v0.0.0-...-823dbf3 Latest Latest

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

Go to latest
Published: Apr 9, 2022 License: BSD-2-Clause Imports: 19 Imported by: 0



Package storage implements the database layer of the client.



This section is empty.


This section is empty.


This section is empty.


type AfterIDIter

type AfterIDIter struct {

AfterIDIter is an iterator that can return concrete AfterIDRes values.

func (AfterIDIter) Result

func (iter AfterIDIter) Result() AfterIDResult

Result returns the most recent result read from the iter.

type AfterIDResult

type AfterIDResult struct {
	Addr  jid.JID
	ID    string
	Delay time.Time

AfterIDRes is returned from an AfterID query.

type DB

type DB struct {
	// contains filtered or unexported fields

DB represents a SQL database with common pre-prepared statements.

func OpenDB

func OpenDB(ctx context.Context, appName, account, dbFile, schema string, debug *log.Logger) (*DB, error)

OpenDB attempts to open the database at dbFile. If no database can be found one is created. If dbFile is empty a fallback sequence of names is used starting with $XDG_DATA_HOME, then falling back to $HOME/.local/share, then falling back to the current working directory.

func (*DB) AfterID

func (db *DB) AfterID(ctx context.Context) AfterIDIter

AfterID gets the last known message ID assigned by the 'by' JID for each roster entry.

func (*DB) BeforeID

func (db *DB) BeforeID(ctx context.Context, j jid.JID) (string, time.Time, error)

BeforeID gets the first known message ID and timestamp for the given JID.

func (*DB) ForRoster

func (db *DB) ForRoster(ctx context.Context, f func(event.UpdateRoster)) error

ForRoster executes f for each roster entry.

func (*DB) GetInfo

func (db *DB) GetInfo(ctx context.Context, j jid.JID) (disco.Info, disco.Caps, error)

GetInfo queries for service discovery information and entity caps.

The stored caps value does not necessarily match the caps value as calculated from the returned disco info. The info is populated whenever we fetch it, the caps value is populated whenever we see a new value advertised for a JID. By comparing the two we can see if a newer version has been advertised and then go fetch the latest version, but only when we need it (not when the new version is advertised).

func (*DB) InsertCaps

func (db *DB) InsertCaps(ctx context.Context, j jid.JID, caps disco.Caps) error

InsertCaps adds a newly seen entity capbailities hash to the databsae.

func (*DB) InsertMsg

func (db *DB) InsertMsg(ctx context.Context, respectDelay bool, msg event.ChatMessage, addr jid.JID) error

InsertMsg adds a message to the database.

func (*DB) MarkReceived

func (db *DB) MarkReceived(ctx context.Context, e event.Receipt) error

MarkReceived marks a message as having been received by the other side.

func (*DB) QueryHistory

func (db *DB) QueryHistory(ctx context.Context, j string, typ stanza.MessageType) MessageIter

QueryHistory returns all rows to or from the given JID. Any errors encountered while querying are deferred until the iter is used.

func (*DB) ReplaceRoster

func (db *DB) ReplaceRoster(ctx context.Context, e event.FetchRoster) error

ReplaceRoster truncates the entire roster and replaces it with the provided items.

func (*DB) RosterVer

func (db *DB) RosterVer(ctx context.Context) (string, error)

RosterVer returns the currently saved roster version.

func (*DB) UpdateRoster

func (db *DB) UpdateRoster(ctx context.Context, ver string, item event.UpdateRoster) error

UpdateRoster upserts or removes a JID from the roster.

func (*DB) UpsertDisco

func (db *DB) UpsertDisco(ctx context.Context, j jid.JID, caps disco.Caps, info disco.Info) error

UpsertDisco saves the service discovery information to the database.

type Iter

type Iter struct {
	// contains filtered or unexported fields

Iter is a generic iterator that can be returned to marshal database rows into values.

func (*Iter) Close

func (i *Iter) Close() error

Close stops iteration. If Next is called and returns false, Close is called automatically. Close is idempotent and does not affect the result of Err.

func (*Iter) Current

func (i *Iter) Current() interface{}

Current returns the last parsed row.

func (*Iter) Err

func (i *Iter) Err() error

Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.

func (*Iter) Next

func (i *Iter) Next() bool

Next advances the iterator and returns whether the next row is ready to be read.

type MessageIter

type MessageIter struct {

MessageIter is an iterator that can return concrete messages.

func (MessageIter) Message

func (iter MessageIter) Message() event.ChatMessage

Result returns the most recent result read from the iter.

Jump to

Keyboard shortcuts

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