sqlstore

package
v1.7.13 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDB

func CreateDB(t *testing.T, keyLen int) sql.Database

CreateDB creates a test database. It is only used for testing.

func EnsureDBItems added in v1.7.10

func EnsureDBItems(t *testing.T, db sql.Database, content []rangesync.KeyBytes)

EnsureDBItems inserts items into a test database, skipping rows with keys that already exist. It is only used for testing.

func InsertDBItems

func InsertDBItems(t *testing.T, db sql.Database, content []rangesync.KeyBytes)

InsertDBItems inserts items into a test database. It is only used for testing.

func PopulateDB

func PopulateDB(t *testing.T, keyLen int, content []rangesync.KeyBytes) sql.Database

PopulateDB creates a test database and inserts items into it. It is only used for testing.

Types

type Binder

type Binder func(s *sql.Statement)

Binder is a function that binds filter expression parameters to a SQL statement.

type IDStore

type IDStore interface {
	// Clone makes a copy of the store.
	// It is expected to be an O(1) operation.
	Clone() IDStore
	// Release releases the resources associated with the store.
	Release()
	// RegisterKey registers the key with the store.
	RegisterKey(k rangesync.KeyBytes) error
	// All returns all keys in the store.
	// The sequence in SeqResult returned by All is either empty or infinite.
	All() rangesync.SeqResult
	// From returns all keys in the store starting from the given key.
	// sizeHint is a hint for the expected number of keys to be returned.
	// The sequence in SeqResult returned by From is either empty or infinite.
	From(from rangesync.KeyBytes, sizeHint int) rangesync.SeqResult
}

IDStore represents a store of IDs (keys).

type SQLIDStore

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

SQLIDStore is an implementation of IDStore that is based on a database table snapshot.

func NewSQLIDStore

func NewSQLIDStore(db sql.Executor, sts *SyncedTableSnapshot, keyLen int) *SQLIDStore

NewSQLIDStore creates a new SQLIDStore.

func (*SQLIDStore) All

func (s *SQLIDStore) All() rangesync.SeqResult

All returns all IDs in the store. The sequence in SeqResult returned by All is either empty or infinite. Implements IDStore.

func (*SQLIDStore) Clone

func (s *SQLIDStore) Clone() IDStore

Clone creates a new SQLIDStore that shares the same database connection and table snapshot. Implements IDStore.

func (*SQLIDStore) From

func (s *SQLIDStore) From(from rangesync.KeyBytes, sizeHint int) rangesync.SeqResult

From returns IDs in the store starting from the given key. The sequence in SeqResult returned by From is either empty or infinite. Implements IDStore.

func (*SQLIDStore) RegisterKey

func (s *SQLIDStore) RegisterKey(k rangesync.KeyBytes) error

RegisterKey is a no-op for SQLIDStore, as the underlying table is never immediately updated upon receiving new items. Implements IDStore.

func (*SQLIDStore) Release

func (s *SQLIDStore) Release()

Release is a no-op for SQLIDStore. Implements IDStore.

func (*SQLIDStore) SetSnapshot

func (s *SQLIDStore) SetSnapshot(sts *SyncedTableSnapshot)

Sets the table snapshot to use for the store.

func (*SQLIDStore) Since

func (s *SQLIDStore) Since(from rangesync.KeyBytes, since int64) (rangesync.SeqResult, int)

Since returns IDs in the store starting from the given key and timestamp. The sequence in SeqResult returned by Since is either empty or infinite.

type SyncedTable

type SyncedTable struct {
	// The name of the table.
	TableName string
	// The name of the ID column.
	IDColumn string
	// The name of the timestamp column.
	TimestampColumn string
	// The filter expression.
	Filter expr.Expr
	// The binder function for the bind parameters appearing in the filter expression.
	Binder Binder
	// contains filtered or unexported fields
}

SyncedTable represents a table that can be used with SQLIDStore.

func (*SyncedTable) Snapshot

func (st *SyncedTable) Snapshot(db sql.Executor) (*SyncedTableSnapshot, error)

Snaptshot creates a snapshot of the table based on its current max rowid value.

type SyncedTableSnapshot

type SyncedTableSnapshot struct {
	*SyncedTable
	// contains filtered or unexported fields
}

SyncedTableSnapshot represents a snapshot of an append-only table. The snapshotting is relies on rowids of the table rows never decreasing as new rows are added. Each snapshot inherits filter expression from the table, so all the rows relevant to the snapshot are always filtered using that expression, if it's specified.

func (*SyncedTableSnapshot) Load

func (sts *SyncedTableSnapshot) Load(
	db sql.Executor,
	dec func(stmt *sql.Statement) bool,
) error

Load loads all the table rows belonging to a snapshot.

func (*SyncedTableSnapshot) LoadCount

func (sts *SyncedTableSnapshot) LoadCount(
	db sql.Executor,
) (int, error)

LoadCount returns the number of rows in the snapshot.

func (*SyncedTableSnapshot) LoadRange

func (sts *SyncedTableSnapshot) LoadRange(
	db sql.Executor,
	fromID rangesync.KeyBytes,
	limit int,
	dec func(stmt *sql.Statement) bool,
) error

LoadRange loads ids starting from the specified one. limit specifies the maximum number of ids to load.

func (*SyncedTableSnapshot) LoadRecent

func (sts *SyncedTableSnapshot) LoadRecent(
	db sql.Executor,
	fromID rangesync.KeyBytes,
	limit int,
	since int64,
	dec func(stmt *sql.Statement) bool,
) error

LoadRecent loads rows added since the specified timestamp.

func (*SyncedTableSnapshot) LoadRecentCount

func (sts *SyncedTableSnapshot) LoadRecentCount(
	db sql.Executor,
	since int64,
) (int, error)

LoadRecentCount returns the number of rows added since the specified timestamp.

func (*SyncedTableSnapshot) LoadSinceSnapshot

func (sts *SyncedTableSnapshot) LoadSinceSnapshot(
	db sql.Executor,
	prev *SyncedTableSnapshot,
	dec func(stmt *sql.Statement) bool,
) error

LoadSinceSnapshot loads rows added since the specified previous snapshot.

Jump to

Keyboard shortcuts

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