repository

package
v3.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Driver = "sqlite"
)

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, db *sql.DB, verbose bool) error

Types

type BulkRepository

type BulkRepository[T dbObject] interface {
	Inserter[T]
	Counter[T]
	Dictionary[T]
	Getter[T]
	Chunker[T]
}

BulkRepository is a generic repository interface without the means to select individual rows.

type ChannelRepository

type ChannelRepository interface {
	BulkRepository[DBChannel]
}

func NewChannelRepository

func NewChannelRepository() ChannelRepository

type ChannelUserRepository

type ChannelUserRepository interface {
	BulkRepository[DBChannelUser]
	GetByChannelID(ctx context.Context, db sqlx.QueryerContext, channelID string) (iter.Seq2[DBChannelUser, error], error)
}

func NewChannelUserRepository

func NewChannelUserRepository() ChannelUserRepository

type ChunkCount

type ChunkCount map[chunk.ChunkType]int64

func (ChunkCount) Sum

func (c ChunkCount) Sum() int64

type ChunkRepository

type ChunkRepository interface {
	// Insert should insert dbchunk into the repository and return its ID.
	Insert(ctx context.Context, conn sqlx.ExtContext, dbchunk *DBChunk) (int64, error)
	Count(ctx context.Context, conn sqlx.ExtContext, sessionID int64, chunkTypeID ...chunk.ChunkType) (ChunkCount, error)
	All(ctx context.Context, conn sqlx.ExtContext, sessionID int64, chunkTypeID ...chunk.ChunkType) (iter.Seq2[DBChunk, error], error)
}

func NewChunkRepository

func NewChunkRepository() ChunkRepository

type Chunker

type Chunker[T dbObject] interface {
	OneForChunk(ctx context.Context, conn sqlx.QueryerContext, chunkID int64) (T, error)
	AllForChunk(ctx context.Context, conn sqlx.QueryerContext, chunkID int64) (iter.Seq2[T, error], error)
}

type Counter

type Counter[T dbObject] interface {
	// CountType should return the number of entities in the database of a
	// given chunk types.
	CountType(ctx context.Context, conn sqlx.QueryerContext, chunkTypeID ...chunk.ChunkType) (int64, error)
	// Count should return the number of entities in the database.
	Count(ctx context.Context, conn sqlx.QueryerContext) (int64, error)
}

type DBChannel

type DBChannel struct {
	ID      string  `db:"ID"`
	ChunkID int64   `db:"CHUNK_ID"`
	Name    *string `db:"NAME"`
	Index   int     `db:"IDX"`
	Data    []byte  `db:"DATA"`
}

func NewDBChannel

func NewDBChannel(chunkID int64, n int, channel *slack.Channel) (*DBChannel, error)

func (DBChannel) Val

func (c DBChannel) Val() (slack.Channel, error)

type DBChannelUser

type DBChannelUser struct {
	ChannelID string `db:"CHANNEL_ID"`
	UserID    string `db:"USER_ID"`
	ChunkID   int64  `db:"CHUNK_ID"`
	Index     int    `db:"IDX"`
}

func NewDBChannelUser

func NewDBChannelUser(chunkID int64, n int, channelID, userID string) (*DBChannelUser, error)

type DBChunk

type DBChunk struct {
	// ID is the unique identifier of the chunk within the session.
	ID          int64           `db:"ID,omitempty"`
	SessionID   int64           `db:"SESSION_ID,omitempty"`
	UnixTS      int64           `db:"UNIX_TS,omitempty"`
	CreatedAt   time.Time       `db:"CREATED_AT,omitempty"`
	TypeID      chunk.ChunkType `db:"TYPE_ID,omitempty"`
	NumRecords  int32           `db:"NUM_REC"`
	ChannelID   *string         `db:"CHANNEL_ID,omitempty"`
	SearchQuery *string         `db:"SEARCH_QUERY,omitempty"`
	Final       bool            `db:"FINAL"`
	ThreadOnly  *bool           `db:"THREAD_ONLY,omitempty"`
}

DBChunk is the database representation of the Chunk.

func (DBChunk) Chunk

func (c DBChunk) Chunk() *chunk.Chunk

type DBFile

type DBFile struct {
	ID        string  `db:"ID"`
	ChunkID   int64   `db:"CHUNK_ID"`
	ChannelID string  `db:"CHANNEL_ID"`
	MessageID *int64  `db:"MESSAGE_ID"`
	ThreadID  *int64  `db:"THREAD_ID,omitempty"`
	Index     int     `db:"IDX"`
	Mode      string  `db:"MODE"`
	Filename  *string `db:"FILENAME"`
	URL       *string `db:"URL"`
	Data      []byte  `db:"DATA"`
}

func NewDBFile

func NewDBFile(chunkID int64, idx int, channelID, threadTS string, parentMsgTS string, file *slack.File) (*DBFile, error)

func (DBFile) Val

func (f DBFile) Val() (slack.File, error)

type DBMessage

type DBMessage struct {
	ID          int64   `db:"ID,omitempty"`
	ChunkID     int64   `db:"CHUNK_ID,omitempty"`
	ChannelID   string  `db:"CHANNEL_ID"`
	TS          string  `db:"TS"`
	ParentID    *int64  `db:"PARENT_ID,omitempty"`
	ThreadTS    *string `db:"THREAD_TS,omitempty"`
	LatestReply *string `db:"LATEST_REPLY,omitempty"`
	IsParent    bool    `db:"IS_PARENT"`
	Index       int     `db:"IDX"`
	NumFiles    int     `db:"NUM_FILES"`
	Text        string  `db:"TXT"`
	Data        []byte  `db:"DATA"`
}

func NewDBMessage

func NewDBMessage(dbchunkID int64, idx int, channelID string, msg *slack.Message) (*DBMessage, error)

func (DBMessage) Val

func (dbm DBMessage) Val() (slack.Message, error)

type DBSearchFile

type DBSearchFile struct {
	ID      int64  `db:"ID,omitempty"`
	ChunkID int64  `db:"CHUNK_ID"`
	FileID  string `db:"FILE_ID"`
	Index   int    `db:"IDX"`
	Data    []byte `db:"DATA"`
}

func NewDBSearchFile

func NewDBSearchFile(chunkID int64, n int, sf *slack.File) (*DBSearchFile, error)

func (DBSearchFile) Val

func (c DBSearchFile) Val() (slack.File, error)

type DBSearchMessage

type DBSearchMessage struct {
	ID          int64   `db:"ID"`
	ChunkID     int64   `db:"CHUNK_ID"`
	ChannelID   string  `db:"CHANNEL_ID"`
	ChannelName *string `db:"CHANNEL_NAME,omitempty"`
	TS          string  `db:"TS"`
	Text        *string `db:"TXT,omitempty"`
	IDX         int     `db:"IDX"`
	Data        []byte  `db:"DATA"`
}

func NewDBSearchMessage

func NewDBSearchMessage(chunkID int64, idx int, sm *slack.SearchMessage) (*DBSearchMessage, error)

func (DBSearchMessage) Val

type DBUser

type DBUser struct {
	ID       string `db:"ID"`
	ChunkID  int64  `db:"CHUNK_ID,omitempty"`
	Username string `db:"USERNAME,omitempty"`
	Index    int    `db:"IDX"`
	Data     []byte `db:"DATA"`
}

func NewDBUser

func NewDBUser(chunkID int64, n int, u *slack.User) (*DBUser, error)

func (DBUser) Val

func (u DBUser) Val() (slack.User, error)

type DBWorkspace

type DBWorkspace struct {
	ID           int64   `db:"ID,omitempty"`
	ChunkID      int64   `db:"CHUNK_ID"`
	Team         string  `db:"TEAM"`
	User         *string `db:"USERNAME"`
	TeamID       string  `db:"TEAM_ID"`
	UserID       string  `db:"USER_ID"`
	EnterpriseID *string `db:"ENTERPRISE_ID"`
	URL          string  `db:"URL"`
	Data         []byte  `db:"DATA"`
}

func NewDBWorkspace

func NewDBWorkspace(chunkID int64, wi *slack.AuthTestResponse) (*DBWorkspace, error)

func (DBWorkspace) Val

type Dictionary

type Dictionary[T dbObject] interface {
	// AllOfType should return all entities of a given chunk types.
	AllOfType(ctx context.Context, conn sqlx.QueryerContext, chunkTypeID ...chunk.ChunkType) (iter.Seq2[T, error], error)
	// All should return all entities.
	All(ctx context.Context, conn sqlx.QueryerContext) (iter.Seq2[T, error], error)
}

type FileRepository

type FileRepository interface {
	BulkRepository[DBFile]
}

func NewFileRepository

func NewFileRepository() FileRepository

type Getter

type Getter[T dbObject] interface {
	// Get should return the entity with the given id.
	Get(ctx context.Context, conn sqlx.ExtContext, id any) (T, error)
	// GetType should return the entity with the given id.
	GetType(ctx context.Context, conn sqlx.ExtContext, id any, ct ...chunk.ChunkType) (T, error)
}

type Inserter

type Inserter[T dbObject] interface {
	// Insert should insert the entity into the database.
	Insert(ctx context.Context, conn sqlx.ExtContext, t ...*T) error
	// InsertAll should insert all entities from the iterator into the
	// database.
	InsertAll(ctx context.Context, pconn PrepareExtContext, tt iter.Seq2[*T, error]) (int, error)
}

type LatestMessage

type LatestMessage struct {
	ChannelID string `db:"CHANNEL_ID"`
	TS        string `db:"TS"`
	ID        int64  `db:"ID"`
}

type LatestThread

type LatestThread struct {
	LatestMessage
	ThreadTS string `db:"THREAD_TS"`
	ParentID int64  `db:"PARENT_ID"`
}

type MessageRepository

type MessageRepository interface {
	Inserter[DBMessage]
	Chunker[DBMessage]
	Getter[DBMessage]
	// Count returns the number of messages in a channel.
	Count(ctx context.Context, conn sqlx.QueryerContext, channelID string) (int64, error)
	// AllForID returns all messages in a channel.
	AllForID(ctx context.Context, conn sqlx.QueryerContext, channelID string) (iter.Seq2[DBMessage, error], error)
	// CountThread returns the number of messages in a thread.
	CountThread(ctx context.Context, conn sqlx.QueryerContext, channelID, threadID string) (int64, error)
	// AllForThread returns all messages in a thread, including parent message.
	AllForThread(ctx context.Context, conn sqlx.QueryerContext, channelID, threadID string) (iter.Seq2[DBMessage, error], error)
	// Sorted returns all thread and channel messages in ascending or descending
	// time order.
	Sorted(ctx context.Context, conn sqlx.QueryerContext, channelID string, order Order) (iter.Seq2[DBMessage, error], error)
	// CountUnfinished returns the number of unfinished threads in a channel.
	CountUnfinished(ctx context.Context, conn sqlx.QueryerContext, sessionID int64, channelID string) (int64, error)
	// CountThreadOnlyParts should return the number of parts in a complete
	// thread-only thread. If an unfinished or non-existent thread is
	// requested, it should return the sql.ErrNoRows error.
	CountThreadOnlyParts(ctx context.Context, conn sqlx.QueryerContext, sessionID int64, channelID, threadID string) (int64, error)
	// LatestMessages returns the latest message in each channel.
	LatestMessages(ctx context.Context, conn sqlx.QueryerContext) (iter.Seq2[LatestMessage, error], error)
	// LatestThreads returns the latest thread message in each channel.
	LatestThreads(ctx context.Context, conn sqlx.QueryerContext) (iter.Seq2[LatestThread, error], error)
}

MessageRepository provides an interface for working with messages in the database.

func NewMessageRepository

func NewMessageRepository() MessageRepository

type Order

type Order bool

Order is the sort order type.

const (
	// Asc is an ascending order.
	Asc Order = false
	// Desc is a descending order.
	Desc Order = true
)

Sort order.

func (Order) String

func (o Order) String() string

type PrepareExtContext

type PrepareExtContext interface {
	sqlx.PreparerContext
	sqlx.ExtContext
}

PrepareExtContext is a combination of sqlx.PreparerContext and sqlx.ExtContext.

type SearchFileRepository

type SearchFileRepository interface {
	BulkRepository[DBSearchFile]
}

func NewSearchFileRepository

func NewSearchFileRepository() SearchFileRepository

type SearchMessageRepository

type SearchMessageRepository interface {
	BulkRepository[DBSearchMessage]
}

func NewSearchMessageRepository

func NewSearchMessageRepository() SearchMessageRepository

type Session

type Session struct {
	ID             int64      `db:"ID,omitempty"`
	CreatedAt      time.Time  `db:"CREATED_AT,omitempty"`
	UpdatedAt      time.Time  `db:"UPDATED_AT,omitempty"`
	ParentID       *int64     `db:"PAR_SESSION_ID,omitempty"`
	FromTS         *time.Time `db:"FROM_TS,omitempty"`
	ToTS           *time.Time `db:"TO_TS,omitempty"`
	Finished       bool       `db:"FINISHED"`
	FilesEnabled   bool       `db:"FILES_ENABLED"`
	AvatarsEnabled bool       `db:"AVATARS_ENABLED"`
	Mode           string     `db:"MODE"`
	Args           string     `db:"ARGS,omitempty"`
}

Session is a Slackdump archive session entry.

type SessionRepository

type SessionRepository interface {
	// Insert should insert a new session into the database. If the session has
	// a parent session, it should verify that the parent session exists. It
	// should return the ID of the newly inserted session.
	Insert(ctx context.Context, conn sqlx.ExtContext, s *Session) (int64, error)
	// Finalise should mark a [Session] as finished. It should return the number
	// of rows affected.
	Finalise(ctx context.Context, conn sqlx.ExtContext, id int64) (int64, error)
	// Get should retrieve a session from the database by its ID.
	Get(ctx context.Context, conn sqlx.ExtContext, id int64) (*Session, error)
	// Update should update a session in the database. It should return the
	// number of rows affected.
	Update(ctx context.Context, conn sqlx.ExtContext, s *Session) (int64, error)
	// Last should return the last session in the database. If finished is not nil,
	// it should return the last session that is finished or not finished,
	// depending on the value of finished.
	Last(ctx context.Context, conn sqlx.ExtContext, finished *bool) (*Session, error)
	// All should return all sessions in the database.
	All(ctx context.Context, conn sqlx.ExtContext) ([]Session, error)
}

func NewSessionRepository

func NewSessionRepository() SessionRepository

type UserRepository

type UserRepository interface {
	BulkRepository[DBUser]
}

func NewUserRepository

func NewUserRepository() UserRepository

type WorkspaceRepository

type WorkspaceRepository interface {
	Inserter[DBWorkspace]
	Chunker[DBWorkspace]
	GetWorkspace(ctx context.Context, conn sqlx.QueryerContext) (DBWorkspace, error)
}

func NewWorkspaceRepository

func NewWorkspaceRepository() WorkspaceRepository

Directories

Path Synopsis
Package mock_repository is a generated GoMock package.
Package mock_repository is a generated GoMock package.

Jump to

Keyboard shortcuts

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