Documentation ¶
Overview ¶
Package sql implements persistent storage using the postgres database.
Index ¶
- Constants
- Variables
- func Bool(b bool) pgtype.Bool
- func BoolPtr(s *bool) pgtype.Bool
- func Error(err error) error
- func Inet(ip net.IP) pgtype.Inet
- func Int4(s int) pgtype.Int4
- func Int4Ptr(s *int) pgtype.Int4
- func Int8(s int) pgtype.Int8
- func Int8Ptr(s *int) pgtype.Int8
- func JSON(b []byte) pgtype.JSON
- func NewTestDB(t *testing.T) string
- func NoRowsInResultError(err error) bool
- func NullString() pgtype.Text
- func String(s string) pgtype.Text
- func StringPtr(s *string) pgtype.Text
- func Timestamptz(t time.Time) pgtype.Timestamptz
- func TimestamptzPtr(t *time.Time) pgtype.Timestamptz
- func UUID(s uuid.UUID) pgtype.UUID
- type Action
- type DB
- func (db *DB) Conn(ctx context.Context) *pggen.DBQuerier
- func (db *DB) Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
- func (db *DB) Lock(ctx context.Context, table string, ...) error
- func (db *DB) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
- func (db *DB) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
- func (db *DB) Tx(ctx context.Context, callback func(context.Context, pggen.Querier) error) error
- func (db *DB) WaitAndLock(ctx context.Context, id int64, fn func(context.Context) error) (err error)
- type ForwardFunc
- type Listener
- type Options
Constants ¶
const ( InsertAction = "INSERT" UpdateAction = "UPDATE" DeleteAction = "DELETE" )
const TestDatabaseURL = "OTF_TEST_DATABASE_URL"
Variables ¶
var ErrSubscriptionTerminated = errors.New("broker terminated the subscription")
ErrSubscriptionTerminated is for use by subscribers to indicate that their subscription has been terminated by the broker.
Functions ¶
func BoolPtr ¶ added in v0.2.0
BoolPtr converts a go-boolean pointer into a postgres nullable boolean
func NewTestDB ¶
NewTestDB creates a logical database in postgres for a test and returns a connection string for connecting to the database. The database is dropped upon test completion.
func NoRowsInResultError ¶ added in v0.0.51
func StringPtr ¶ added in v0.0.50
StringPtr converts a go-string pointer into a postgres nullable string
func Timestamptz ¶
func Timestamptz(t time.Time) pgtype.Timestamptz
Timestamptz converts a go-time into a postgres non-null timestamptz
func TimestamptzPtr ¶ added in v0.1.0
func TimestamptzPtr(t *time.Time) pgtype.Timestamptz
TimestamptzPtr converts a go-time pointer into a postgres nullable timestamptz
Types ¶
type Action ¶ added in v0.2.0
type Action string
Action is the action that was carried out on a database table
type DB ¶
DB provides access to the postgres db as well as queries generated from SQL
func (*DB) Exec ¶
Exec acquires a connection from the pool and executes the given SQL. If the context contains a transaction then that is used.
func (*DB) Tx ¶
Tx provides the caller with a callback in which all operations are conducted within a transaction.
func (*DB) WaitAndLock ¶
func (db *DB) WaitAndLock(ctx context.Context, id int64, fn func(context.Context) error) (err error)
WaitAndLock obtains an exclusive session-level advisory lock. If another session holds the lock with the given id then it'll wait until the other session releases the lock. The given fn is called once the lock is obtained and when the fn finishes the lock is released.
type ForwardFunc ¶ added in v0.2.0
ForwardFunc handles forwarding the id and action onto subscribers.
type Listener ¶ added in v0.2.0
Listener listens for postgres events
func NewListener ¶ added in v0.2.0
func (*Listener) RegisterFunc ¶ added in v0.2.0
func (b *Listener) RegisterFunc(table string, getter ForwardFunc)
RegisterFunc registers a function that is capable of converting database events for the given table into an OTF event.