sqlstore

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package sqlstore is the shared database/sql implementation of the storage.Store contract. Both dialects persist the identical schema (storage/migrations, R7) — timestamps as RFC3339 UTC TEXT, amounts as integer-string TEXT, JSON for list-valued columns — so a single implementation serves both; the per-backend differences (placeholder style, unique-violation mapping, row locking, per-account serialization) are isolated behind the Dialect interface implemented by storage/sqlite and storage/postgres.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dialect

type Dialect interface {
	// Rebind converts '?' placeholders to the backend's style.
	Rebind(query string) string
	// MapError translates driver constraint violations into the storage
	// package's typed errors (ErrDuplicate / ErrActiveSweepExists); any
	// other error is returned unchanged.
	MapError(err error) error
	// RowLock returns the row-locking suffix for read-modify-write SELECTs
	// (" FOR UPDATE" on Postgres, "" on SQLite where the single-writer
	// connection + BEGIN IMMEDIATE serializes globally).
	RowLock() string
	// AcquireAccountLock serializes sequence reservation for one
	// (chain_id, source_address) inside the current transaction (R7:
	// Postgres locks the chain_account_locks row; SQLite is a no-op).
	AcquireAccountLock(ctx context.Context, q Querier, chainID, sourceAddress string) error
}

Dialect isolates the backend-specific behaviour.

type Querier

type Querier interface {
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

Querier is the subset of *sql.DB / *sql.Tx the store runs on.

type Store

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

Store implements storage.Store over one Querier.

func New

func New(db *sql.DB, d Dialect) *Store

New wraps an open, migrated *sql.DB.

func (*Store) AcquireAccountLock

func (s *Store) AcquireAccountLock(ctx context.Context, chainID, sourceAddress string) error

AcquireAccountLock serializes the caller against every other worker of one (chain_id, source_address) account for the remainder of the current transaction. Callers computing the next sequence with a read-modify-write (read reservations → Reserve) MUST take this lock before the read; it is only valid inside WithTx. On SQLite it is a no-op (the single-writer connection + BEGIN IMMEDIATE already serializes globally); on Postgres it locks the chain_account_locks row (R7).

func (*Store) AcquireCreditGateLock

func (s *Store) AcquireCreditGateLock(ctx context.Context, chainID string) error

AcquireCreditGateLock uses the existing per-chain account-lock table with a reserved source key. CreditDeposit, Controls.Apply, and ChainReview.Open all take this lock before reading or mutating the gate, giving PostgreSQL a linear transaction order; SQLite is already serialized by BEGIN IMMEDIATE.

func (*Store) ChainReview

func (s *Store) ChainReview() storage.ChainReviewRepo

func (*Store) Checkpoints

func (s *Store) Checkpoints() storage.CheckpointRepo

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database. Inside a transaction it is a no-op (the transaction owner closes the root store).

func (*Store) Controls

func (s *Store) Controls() storage.ControlsRepo

func (*Store) Deposits

func (s *Store) Deposits() storage.DepositRepo

func (*Store) Ledger

func (s *Store) Ledger() storage.LedgerRepo

func (*Store) Outbox

func (s *Store) Outbox() storage.OutboxRepo

func (*Store) Recon

func (s *Store) Recon() storage.ReconRepo

func (*Store) Review

func (s *Store) Review() storage.ReviewRepo

func (*Store) Sequences

func (s *Store) Sequences() storage.SequenceRepo

func (*Store) Sweeps

func (s *Store) Sweeps() storage.SweepRepo

func (*Store) Watch

func (s *Store) Watch() storage.WatchRepo

func (*Store) WithTx

func (s *Store) WithTx(ctx context.Context, fn func(ctx context.Context, st storage.Store) error) error

WithTx implements storage.Tx. Nested calls run inside the already-open transaction.

func (*Store) Withdrawals

func (s *Store) Withdrawals() storage.WithdrawalRepo

Jump to

Keyboard shortcuts

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