Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL-backed ledger store.
The store uses a single table for all streams. Streams are created implicitly on first append — no DDL is required per stream.
The caller is responsible for opening and closing the *sql.DB. Import a PostgreSQL driver (e.g., github.com/lib/pq) in your application.
Transaction support: pass a *sql.Tx via ledger.WithTx to have the store participate in an external transaction instead of creating its own.
Index ¶
- type Option
- type Store
- func (s *Store) Append(ctx context.Context, stream string, ...) ([]int64, error)
- func (s *Store) Close(_ context.Context) error
- func (s *Store) Count(ctx context.Context, stream string) (int64, error)
- func (s *Store) Health(ctx context.Context) error
- func (s *Store) ListStreamIDs(ctx context.Context, opts ...ledger.ListOption) ([]string, error)
- func (s *Store) Read(ctx context.Context, stream string, opts ...ledger.ReadOption) ([]ledger.StoredEntry[int64, json.RawMessage], error)
- func (s *Store) SetAnnotations(ctx context.Context, stream string, id int64, annotations map[string]*string) error
- func (s *Store) SetTags(ctx context.Context, stream string, id int64, tags []string) error
- func (s *Store) Trim(ctx context.Context, stream string, beforeID int64) (int64, error)
- func (s *Store) Type() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*options)
Option configures the PostgreSQL store.
func WithLogger ¶
WithLogger sets the structured logger. Defaults to slog.Default().
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a PostgreSQL ledger store.
func New ¶
New creates a new PostgreSQL ledger store. The table and indexes are created automatically. Tag GIN indexes are created asynchronously in the background.
func (*Store) Append ¶
func (s *Store) Append(ctx context.Context, stream string, entries ...ledger.RawEntry[json.RawMessage]) ([]int64, error)
Append adds entries to the named stream. Returns IDs of newly appended entries.
func (*Store) ListStreamIDs ¶ added in v0.0.2
ListStreamIDs returns distinct stream IDs with at least one entry in this store. Results are ascending by stream ID and cursor-paginated via ListAfter/ListLimit.
func (*Store) Read ¶
func (s *Store) Read(ctx context.Context, stream string, opts ...ledger.ReadOption) ([]ledger.StoredEntry[int64, json.RawMessage], error)
Read returns entries from the named stream.
func (*Store) SetAnnotations ¶ added in v0.0.2
func (s *Store) SetAnnotations(ctx context.Context, stream string, id int64, annotations map[string]*string) error
SetAnnotations merges annotations into an entry. Keys with nil values are deleted.