Documentation
¶
Overview ¶
Package sqlite stores record streams in a SQLite file: a table per kind, keyed (stream_id, seq), with the kind's columns typed from its schema, and a record_streams table describing every stream.
The same file is the query index a `sql` profile reads through ReadDSN, which is what makes a stream pageable, filterable and exportable by the native profile engine. Used as a durable backend it is the index already; behind another backend an Indexer keeps it caught up.
Index ¶
- type Backend
- func (b *Backend) Append(ctx context.Context, stream, kind string, rows []recordstore.Row) (recordstore.AppendResult, error)
- func (b *Backend) Close() error
- func (b *Backend) Derived() bool
- func (b *Backend) Expire(ctx context.Context, stream string, ttl time.Duration) error
- func (b *Backend) Import(ctx context.Context, request recordstore.ImportRequest) (recordstore.Window, error)
- func (b *Backend) Lease() func()
- func (b *Backend) Meta(ctx context.Context, stream string) (recordstore.Meta, error)
- func (b *Backend) Path() string
- func (b *Backend) Prepare(ctx context.Context, source recordstore.Meta) (recordstore.Meta, bool, error)
- func (b *Backend) ReadDSN() string
- func (b *Backend) Scan(ctx context.Context, stream string, afterSeq int64, ...) error
- func (b *Backend) SetExpiry(ctx context.Context, stream string, expiresAt *time.Time) error
- func (b *Backend) Sweep(ctx context.Context) (int, error)
- func (b *Backend) Table(kind string) (sqlitetable.Table, error)
- func (b *Backend) Trim(ctx context.Context, stream string, before time.Time) (recordstore.Meta, error)
- func (b *Backend) TrimBelow(ctx context.Context, stream string, lowSeq int64) (recordstore.Meta, error)
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is a recordstore.Backend over a SQLite file.
func (*Backend) Append ¶
func (b *Backend) Append(ctx context.Context, stream, kind string, rows []recordstore.Row) (recordstore.AppendResult, error)
Append numbers the rows it keeps after the stream's high seq.
func (*Backend) Close ¶
Close stops the sweeper, waiting out a sweep in progress, and closes the file.
func (*Backend) Derived ¶
Derived reports whether this file can discard indexed rows and rebuild them from a separate source.
func (*Backend) Import ¶
func (b *Backend) Import(ctx context.Context, request recordstore.ImportRequest) (recordstore.Window, error)
Import stores rows under source's generation and seqs. The requested first seq must follow the indexed high seq exactly; a stream the index does not hold yet starts at it, since its source may have trimmed the seqs below.
func (*Backend) Lease ¶
func (b *Backend) Lease() func()
Lease holds off every row and schema mutation until the returned function is called, so an external reader can issue multiple stable paging statements.
func (*Backend) Prepare ¶
func (b *Backend) Prepare(ctx context.Context, source recordstore.Meta) (recordstore.Meta, bool, error)
Prepare reconciles source's table before comparing the indexed stream. A derived index removes an older incarnation so its first import starts at 1.
func (*Backend) Scan ¶
func (b *Backend) Scan(ctx context.Context, stream string, afterSeq int64, fn func(int64, recordstore.Row) error) error
Scan reads stream's rows after afterSeq in seq order.
func (*Backend) SetExpiry ¶
SetExpiry makes an index expire at the source's exact deadline. A nil deadline keeps it for as long as its source exists.
func (*Backend) Sweep ¶
Sweep removes every stream whose expiry has passed, rows included, and reports how many it removed.
func (*Backend) Table ¶
func (b *Backend) Table(kind string) (sqlitetable.Table, error)
Table is kind's table, created on first use. It is exported for the typed result registry, which reads a kind through the table's own columns.
func (*Backend) Trim ¶
func (b *Backend) Trim(ctx context.Context, stream string, before time.Time) (recordstore.Meta, error)
Trim removes the rows appended before before.
func (*Backend) TrimBelow ¶
func (b *Backend) TrimBelow(ctx context.Context, stream string, lowSeq int64) (recordstore.Meta, error)
TrimBelow drops the indexed rows below lowSeq, mirroring a trim of the source. An index that had not reached lowSeq is moved up to it as an empty stream, so the next import starts at lowSeq.
type Options ¶
type Options struct {
// Path is the database file. It must be a file rather than memory: a
// profile reads it through a connection of its own.
Path string
// Schema resolves a kind to its columns, key and retention. A kind it
// refuses cannot be written.
Schema recordstore.SchemaResolver
// TTL is how long a stream lives from its first append unless Expire moves
// it, or how long a row of a kind retaining rows lives from its own append.
// Zero keeps a stream until something expires it, and refuses a kind
// retaining rows.
TTL time.Duration
// Derived marks the file as an index rebuilt from a source. A kind whose
// columns changed since its table was created is then dropped with every
// stream it held, for an Indexer to refill; in a durable file the same
// change is an error, because those rows exist nowhere else.
Derived bool
// Now is the clock streams are stamped and expired by. Nil is time.Now.
Now func() time.Time
// SweepInterval is how often the file removes the streams whose expiry
// has passed, rows included, until it is closed. It is required: a stream
// expires from a ttl or from the source an index mirrors, and a file that
// never swept would keep every row it was ever given.
SweepInterval time.Duration
}
Options configure a sqlite backend.