dbase

package
v4.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultDBFile = "slackdump.sqlite"

DefaultDBFile is the default database filename used when a directory is passed instead of a file path.

Variables

View Source
var (
	// ErrInvalidSessionID is returned when the session ID is invalid.
	ErrInvalidSessionID = errors.New("invalid session ID")
	// ErrIncomplete is returned when the session is incomplete.
	ErrIncomplete = errors.New("incomplete session")
)
View Source
var ErrIsDirectory = fmt.Errorf("path is a directory")

ErrIsDirectory is returned when a directory path is passed instead of a database file.

Functions

func NewThreadSkipper added in v4.4.0

func NewThreadSkipper(conn *sqlx.DB) func(ctx context.Context, channelID, threadTS string, replyCount int) bool

NewThreadSkipper returns a predicate suitable for stream.OptSkipThreadFunc. It returns true (skip) when the DB already holds replyCount+1 messages for the thread (parent message included), meaning the thread appears complete. Returns false on any error so that the thread is re-fetched safely.

CountThread is used (not CountThreadOnlyParts) intentionally: for resume we want to count messages across all sessions, so a thread fully stored in any prior session will be skipped correctly.

Note: replyCount comes from the Slack API reply_count field on the parent message, which may lag behind true thread state (edits/deletes not reflected). This is the accepted tradeoff documented in the -skip-complete-threads flag.

Types

type DBP

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

DBP is the database processor.

func New

func New(ctx context.Context, conn *sqlx.DB, p SessionInfo, opts ...Option) (*DBP, error)

New return the new database processor.

func (*DBP) Abort added in v4.3.0

func (d *DBP) Abort() error

Abort closes the writer without finalising the session. No additional cleanup is required here because DBP does not own the database connection.

func (*DBP) Close

func (d *DBP) Close() error

Close aborts the writer without finalising the session.

func (*DBP) Encode

func (d *DBP) Encode(ctx context.Context, ch *chunk.Chunk) error

Encode inserts the chunk into the database.

func (*DBP) Finish added in v4.3.0

func (d *DBP) Finish() error

Finish finalises the session, marking it as finished.

func (*DBP) InsertChunk

func (d *DBP) InsertChunk(ctx context.Context, ch *chunk.Chunk) (int64, error)

InsertChunk inserts a chunk into the database.

func (*DBP) IsComplete

func (d *DBP) IsComplete(ctx context.Context, channelID string) (bool, error)

IsComplete returns true if the channel messages have been processed (there are no unfinished threads, and all messages were received).

func (*DBP) IsCompleteThread

func (d *DBP) IsCompleteThread(ctx context.Context, channelID, threadID string) (bool, error)

IsCompleteThread checks that thread with channelID and threadID is complete for thread-only archives. It returns true if there are no unfinished parts of the thread. It returns false if the thread is not found. It will return false on non-thread-only archives.

func (*DBP) Source

func (d *DBP) Source() *Source

Source returns the connection that can be used safely as a source.

func (*DBP) String

func (d *DBP) String() string

func (*DBP) UnsafeInsertChunk

func (d *DBP) UnsafeInsertChunk(ctx context.Context, txx repository.PrepareExtContext, ch *chunk.Chunk) (int64, error)

UnsafeInsertChunk does not lock the DBP and does not commit the transaction. It should be used for bulk inserts. Unsafe for concurrent use.

type ErrInvalidPayload

type ErrInvalidPayload struct {
	Type      chunk.ChunkType
	ChannelID string
	Reason    string
}

func (*ErrInvalidPayload) Error

func (e *ErrInvalidPayload) Error() string

type Option

type Option func(*options)

func WithOnlyNewOrChangedUsers

func WithOnlyNewOrChangedUsers(v bool) Option

func WithVerbose

func WithVerbose(v bool) Option

type RWSource added in v4.1.1

type RWSource struct {
	*Source
}

RWSource wraps Source with alias write operations. It satisfies the viewer Aliaser interface together with the read methods promoted from the embedded Source.

func OpenRW added in v4.1.1

func OpenRW(ctx context.Context, path string) (*RWSource, error)

OpenRW attempts to open the database at given path for reading and writing. Use Open when only read access is needed.

func (*RWSource) DeleteAlias added in v4.1.1

func (s *RWSource) DeleteAlias(id string) error

func (*RWSource) SetAlias added in v4.1.1

func (s *RWSource) SetAlias(id, alias string) error

type SessionInfo

type SessionInfo struct {
	FromTS         *time.Time
	ToTS           *time.Time
	FilesEnabled   bool
	AvatarsEnabled bool
	Mode           string
	Args           string
}

SessionInfo is the information about the session to be logged in the database.

type Source

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

func Open

func Open(ctx context.Context, path string) (*Source, error)

Open attempts to open the database at given path for reading.

func (*Source) Alias added in v4.1.1

func (s *Source) Alias(id string) (string, bool, error)

func (*Source) Aliases added in v4.1.1

func (s *Source) Aliases() (map[string]string, error)

func (*Source) AllMessages

func (s *Source) AllMessages(ctx context.Context, channelID string) (iter.Seq2[slack.Message, error], error)

func (*Source) AllThreadMessages

func (s *Source) AllThreadMessages(ctx context.Context, channelID, threadID string) (iter.Seq2[slack.Message, error], error)

func (*Source) ChannelInfo

func (s *Source) ChannelInfo(ctx context.Context, channelID string) (*slack.Channel, error)

func (*Source) Channels

func (s *Source) Channels(ctx context.Context) ([]slack.Channel, error)

Channels returns all channels. If the channel info is not available, it will attempt to get all channels.

func (*Source) Close

func (s *Source) Close() error

Close closes the database connection. It is a noop if the Source was created with [Connect].

func (*Source) Latest

func (s *Source) Latest(ctx context.Context) (map[structures.SlackLink]time.Time, error)

func (*Source) Sessions

func (src *Source) Sessions(ctx context.Context) ([]repository.Session, error)

func (*Source) Sorted

func (s *Source) Sorted(ctx context.Context, channelID string, desc bool, cb func(ts time.Time, msg *slack.Message) error) error

func (*Source) ToChunk

func (src *Source) ToChunk(ctx context.Context, e chunk.Encoder, sessID int64) error

func (*Source) Users

func (s *Source) Users(ctx context.Context) ([]slack.User, error)

func (*Source) WorkspaceInfo

func (s *Source) WorkspaceInfo(ctx context.Context) (*slack.AuthTestResponse, error)

Directories

Path Synopsis
mock_repository
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