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 FromStringArray(pta []pgtype.Text) []string
- func GetLimit(opts resource.PageOptions) pgtype.Int4
- func GetOffset(opts resource.PageOptions) pgtype.Int4
- func ID(s resource.ID) pgtype.Text
- func IDPtr(s *resource.ID) pgtype.Text
- 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 NewTestDB(t *testing.T) string
- func NullString() pgtype.Text
- func String(s string) pgtype.Text
- func StringArray(ss []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) Lock(ctx context.Context, table string, ...) error
- func (db *DB) Querier(ctx context.Context) *sqlc.Queries
- func (db *DB) Tx(ctx context.Context, callback func(context.Context, *sqlc.Queries) error) error
- func (db *DB) WaitAndLock(ctx context.Context, id int64, fn func(context.Context) error) (err error)
- type ForwardFunc
- type Listener
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 FromStringArray ¶ added in v0.3.0
FromStringArray converts a postgres text array into a go string slice.
func GetLimit ¶ added in v0.3.6
func GetLimit(opts resource.PageOptions) pgtype.Int4
GetLimit calculates the limit for use in SQL queries.
func GetOffset ¶ added in v0.3.6
func GetOffset(opts resource.PageOptions) pgtype.Int4
GetOffset calculates the offset for use in SQL queries.
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 StringArray ¶ added in v0.3.0
StringArray converts a go-string slice into a postgres text array
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 New ¶
New migrates the database to the latest migration version, and then constructs and returns a connection pool.
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.