postgres

package module
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package postgres is a PostgreSQL ledgo.Store.

Index

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 keeps accounts and transactions in PostgreSQL.

Commits lock only the accounts that have a balance limit, always in ID order, so concurrent commits cannot deadlock on READ COMMITTED and need no retry loop.

func InTx

func InTx(tx *sql.Tx) *Store

InTx returns a Store that writes into tx, so postings commit or roll back together with the caller's own changes. The caller commits tx, and must roll it back if a Commit fails.

func New

func New(db *sql.DB) *Store

New returns a Store on db, opened with sql.Open("pgx", dsn). Each Commit runs in its own database transaction.

func (*Store) Balance

func (s *Store) Balance(ctx context.Context, account string) (decimal.Decimal, error)

Balance is the account's debits minus credits: cached for accounts with a limit, summed from entries otherwise.

func (*Store) Commit

func (s *Store) Commit(ctx context.Context, tx ledgo.Transaction) error

Commit stores tx. See ledgo.Store.Commit.

func (*Store) CreateAccount

func (s *Store) CreateAccount(ctx context.Context, account ledgo.Account) error

CreateAccount registers account. Creating the same account again is a no-op; with different settings it returns ledgo.ErrAccountConflict.

func (*Store) Migrate

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

Migrate creates the ledgo tables if they don't exist.

Jump to

Keyboard shortcuts

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