sqlite

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

SPDX-License-Identifier: AGPL-3.0-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements domain.Store backed by SQLite.

func Open

func Open(path string) (*Store, error)

Open opens an SQLite database and runs migrations.

func (*Store) AddChannelMember

func (s *Store) AddChannelMember(channelID, userID int64) error

AddChannelMember adds a user to a channel.

func (*Store) ChannelMemberUsernames

func (s *Store) ChannelMemberUsernames(channelID int64) ([]string, error)

ChannelMemberUsernames returns the usernames of all members of a channel.

func (*Store) Close

func (s *Store) Close() error

Close closes the database connection.

func (*Store) CreateChannel

func (s *Store) CreateChannel(name string, public bool, memberIDs []int64, channelType string) (int64, error)

CreateChannel creates a channel with the given members in a transaction. channelType should be "channel" or "dm".

func (*Store) CreateRole

func (s *Store) CreateRole(name string) error

CreateRole inserts a new custom role.

func (*Store) CreateUser

func (s *Store) CreateUser(username, password string) (int64, error)

CreateUser inserts a new user and returns its ID.

func (*Store) DeleteRole

func (s *Store) DeleteRole(name string) error

DeleteRole removes a custom role. Built-in roles cannot be deleted.

func (*Store) GetChannelByID

func (s *Store) GetChannelByID(id int64) (*domain.Channel, error)

GetChannelByID returns a channel by its ID.

func (*Store) GetChannelByName

func (s *Store) GetChannelByName(name string) (*domain.Channel, error)

GetChannelByName returns a channel by its name.

func (*Store) GetMessages

func (s *Store) GetMessages(channelID int64, before *int64, after *int64, limit int, threadID *int64) ([]domain.Message, error)

GetMessages returns messages for a channel with cursor-based pagination. If before is set, returns messages with id < before (most recent first up to limit, returned in ASC order). If after is set, returns messages with id > after in ASC order. If neither is set, returns the most recent `limit` messages in ASC order. If threadID is set, only returns replies to that parent message.

func (*Store) GetRolePermissions

func (s *Store) GetRolePermissions(role string) ([]string, error)

GetRolePermissions returns all permissions granted to a role.

func (*Store) GetSetting

func (s *Store) GetSetting(key string) (string, error)

GetSetting returns the value for a setting key.

func (*Store) GetUnreadCounts

func (s *Store) GetUnreadCounts(userID int64) ([]domain.UnreadCount, error)

GetUnreadCounts returns per-channel unread message and mention counts for a user. Only returns channels with >0 unreads. Excludes the user's own messages.

func (*Store) GetUnreadMessages

func (s *Store) GetUnreadMessages(userID int64, channelID *int64, mentionsOnly bool, threadID *int64) ([]domain.Message, error)

GetUnreadMessages returns unread messages for a user, optionally filtered by channel, mentions, or thread. Advances the read cursor only when no filters are active (a filtered read is partial and shouldn't mark everything as read).

func (*Store) GetUserByUsername

func (s *Store) GetUserByUsername(username string) (*domain.User, error)

GetUserByUsername returns a user by username.

func (*Store) GetUserPermissions

func (s *Store) GetUserPermissions(username string) ([]string, error)

GetUserPermissions returns all permissions for a user based on their role.

func (*Store) GrantPermission

func (s *Store) GrantPermission(role, permission string) error

GrantPermission grants a permission to a role. If already granted, this is a no-op.

func (*Store) HasPermission

func (s *Store) HasPermission(username, permission string) (bool, error)

HasPermission reports whether a user has the given permission via their role.

func (*Store) ImportMessage added in v0.3.0

func (s *Store) ImportMessage(channelID, userID int64, body string, threadID *int64, mentionUserIDs []int64, createdAt time.Time) (int64, error)

ImportMessage inserts a message with an explicit created_at timestamp. Used by the backup import to preserve original message timestamps.

func (*Store) IsChannelMember

func (s *Store) IsChannelMember(channelID, userID int64) (bool, error)

IsChannelMember returns true if the user is a member of the channel.

func (*Store) IsEmpty added in v0.3.0

func (s *Store) IsEmpty() (bool, error)

IsEmpty reports whether the users table has no rows. Used by backup import to prevent importing into a non-empty database.

func (*Store) ListAllChannelsWithMembership

func (s *Store) ListAllChannelsWithMembership(userID int64) ([]domain.ChannelWithMembership, error)

ListAllChannelsWithMembership returns all non-DM channels with membership status for the given user.

func (*Store) ListAllDMs

func (s *Store) ListAllDMs() ([]domain.AllDMInfo, error)

ListAllDMs returns all DM channels with both participants (admin view).

func (*Store) ListChannelsForUser

func (s *Store) ListChannelsForUser(userID int64) ([]domain.ChannelWithMembership, error)

ListChannelsForUser returns non-DM channels visible to a user: all public channels plus private channels where the user is a member. Each result includes whether the user is a member.

func (*Store) ListDMsForUser

func (s *Store) ListDMsForUser(userID int64) ([]domain.DMInfo, error)

ListDMsForUser returns all DM channels the user is a member of, with the other participant's info.

func (*Store) ListRoles

func (s *Store) ListRoles() ([]domain.Role, error)

ListRoles returns all roles ordered by name.

func (*Store) ListSettings

func (s *Store) ListSettings() (map[string]string, error)

ListSettings returns all settings as a map.

func (*Store) ListUsers

func (s *Store) ListUsers() ([]domain.User, error)

ListUsers returns all registered users.

func (*Store) MarkRead

func (s *Store) MarkRead(userID, channelID int64, messageID *int64) error

MarkRead advances the read cursor for a user in a channel. If messageID is nil, advances to the latest message. Forward-only: never moves the cursor backwards.

func (*Store) OpenDM

func (s *Store) OpenDM(userID, otherUserID int64, otherUsername string) (string, bool, error)

OpenDM finds or creates a DM channel between two users. Returns the channel name and whether it was newly created.

func (*Store) RevokePermission

func (s *Store) RevokePermission(role, permission string) error

RevokePermission removes a permission from a role.

func (*Store) SendMessage

func (s *Store) SendMessage(channelID, userID int64, body string, threadID *int64, mentionUserIDs []int64) (int64, error)

SendMessage inserts a message into a channel with optional thread and mentions.

func (*Store) SetSetting

func (s *Store) SetSetting(key, value string) error

SetSetting sets a setting key to a value (upsert).

func (*Store) SetUserRole

func (s *Store) SetUserRole(username, role string) error

SetUserRole updates a user's role. Returns an error if the user does not exist.

func (*Store) SetUserType

func (s *Store) SetUserType(username, userType string) error

SetUserType updates a user's type. Returns an error if the user does not exist.

func (*Store) WipeAll added in v0.3.0

func (s *Store) WipeAll() error

WipeAll deletes all user data, preserving schema and built-in RBAC seeds.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL