Documentation ¶
Overview ¶
Package sql implements persistent storage using the postgres database.
Index ¶
- Constants
- func Error(err error) error
- 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 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 Options
Constants ¶
const TestDatabaseURL = "OTF_TEST_DATABASE_URL"
Variables ¶
This section is empty.
Functions ¶
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 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.