sqlite

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package sqlite keeps Aboard's data in SQLite: each board's append-only event log, the read models built from it (boards, members, join codes, messages), humans, browser logins, saved responses for idempotent writes and the server's own settings. It implements board's Store port and api's Responses port. Writes hold the write lock from the start, so event sequence numbers never race.

Index

Constants

This section is empty.

Variables

View Source
var ErrNewerSchema = errors.New("written by a newer aboard")

ErrNewerSchema means the data was written by a newer aboard, whose schema this one doesn't know; reading it could misread it, so Open refuses.

Functions

This section is empty.

Types

type Store

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

Store is an open Aboard database.

func Open

func Open(ctx context.Context, path string, clk clock.Clock) (*Store, error)

Open opens (creating if needed) the database at path and applies migrations.

func OpenReadOnly added in v0.1.3

func OpenReadOnly(ctx context.Context, path string) (*Store, error)

OpenReadOnly opens an existing operator-selected database without creating or migrating it.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) PurgeResponses added in v0.1.1

func (s *Store) PurgeResponses(ctx context.Context) error

PurgeResponses removes expired answers. This is logical deletion; SQLite pages, WAL files and migration backups may still hold copies.

func (*Store) Read

func (s *Store) Read(ctx context.Context, fn func(board.ReadTx) error) error

Read runs fn in a transaction that is always rolled back, so it sees one consistent state of the database.

func (*Store) SaveResponse

func (s *Store) SaveResponse(ctx context.Context, scope, key string, r api.SavedResponse) error

SaveResponse stores the response to an idempotent write. If one is already saved for the key and has not expired, the first one is kept. An expired answer is replaced in the same transaction, so the new request has its own retry window.

func (*Store) SavedResponse

func (s *Store) SavedResponse(ctx context.Context, scope, key string) (api.SavedResponse, bool, error)

SavedResponse finds the response saved for an idempotency key in a caller's scope, and reports whether it is still within its 24-hour lifetime.

func (*Store) Setting

func (s *Store) Setting(ctx context.Context, key string) (value string, ok bool, err error)

Setting returns a server setting, and false if it isn't set.

func (*Store) SettingOnce

func (s *Store) SettingOnce(ctx context.Context, key, value string) (string, error)

SettingOnce stores a server setting unless it has a value already, and returns the value it has afterwards: value, or the one stored first. Stored values never change, so two servers starting at once on one database agree on the one that was kept.

func (*Store) Write

func (s *Store) Write(ctx context.Context, fn func(board.Tx) error) error

Write runs fn in a transaction, committing if it returns nil and rolling back otherwise.

Jump to

Keyboard shortcuts

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