Documentation
¶
Overview ¶
Package sqlite is the embedded, single-node docstore.Store backed by SQLite (modernc.org/sqlite, pure Go, driver name "sqlite").
Documents live in one table:
docs(site, collection, id, data JSON text, created_at, updated_at,
created_by, updated_by, version, PRIMARY KEY (site, collection, id))
with timestamps stored as sortable integers (unix nanoseconds, always whole microseconds) and an index on (site, collection, created_at, id) for the default listing order. Filters, ordering and pagination are pushed into SQL using json_extract/json_type so that the type-strict semantics of SPEC §5.2 hold exactly (see query.go).
The database runs in WAL mode. Writes go through a dedicated single connection (SQLite allows one writer at a time; serialising in-process avoids SQLITE_BUSY churn) using BEGIN IMMEDIATE transactions, while reads use a separate read-only pool and proceed concurrently. busy_timeout covers other processes sharing the file.
Index ¶
- type Store
- func (s *Store) Close() error
- func (s *Store) Collections(ctx context.Context, site string) ([]string, error)
- func (s *Store) Count(ctx context.Context, site string) (int64, error)
- func (s *Store) Create(ctx context.Context, site, collection, id string, data map[string]any, ...) (*docstore.Doc, error)
- func (s *Store) Delete(ctx context.Context, site, collection, id string) (bool, error)
- func (s *Store) DeleteIf(ctx context.Context, site, collection, id string, rev docstore.Rev) (bool, error)
- func (s *Store) DeleteSite(ctx context.Context, site string) error
- func (s *Store) Get(ctx context.Context, site, collection, id string) (*docstore.Doc, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) Put(ctx context.Context, site, collection, id string, data map[string]any, ...) (*docstore.Doc, error)
- func (s *Store) Query(ctx context.Context, site, collection string, q docstore.Query) (*docstore.Page, error)
- func (s *Store) Update(ctx context.Context, site, collection, id string, patch map[string]any, ...) (*docstore.Doc, error)
- func (s *Store) UpdateIf(ctx context.Context, site, collection, id string, rev docstore.Rev, ...) (*docstore.Doc, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed document store.
func Open ¶
Open opens (creating if needed, with mode 0600) the database file at path and applies migrations. The parent directory must exist. path ":memory:" opens a private in-memory database (one connection; for tests).
func (*Store) Collections ¶
Collections lists the non-empty collections of a site, sorted bytewise.
func (*Store) Create ¶
func (s *Store) Create(ctx context.Context, site, collection, id string, data map[string]any, actor string) (*docstore.Doc, error)
Create inserts a new document; see docstore.Store.
func (*Store) DeleteIf ¶ added in v0.2.0
func (s *Store) DeleteIf(ctx context.Context, site, collection, id string, rev docstore.Rev) (bool, error)
DeleteIf removes a document while it is at rev, in one statement; see docstore.Store.
func (*Store) DeleteSite ¶
DeleteSite removes every document of a site.
func (*Store) Put ¶
func (s *Store) Put(ctx context.Context, site, collection, id string, data map[string]any, actor string) (*docstore.Doc, error)
Put creates or replaces a document; see docstore.Store.
func (*Store) Query ¶
func (s *Store) Query(ctx context.Context, site, collection string, q docstore.Query) (*docstore.Page, error)
Query returns matching documents; see docstore.Store.