Documentation ¶
Overview ¶
Package sql implements persistent storage using the postgres database.
Index ¶
- Constants
- func Error(err error) error
- func JSON(b []byte) pgtype.JSON
- func NewTestDB(t *testing.T) string
- func NullString() pgtype.Text
- func String(s string) pgtype.Text
- func Timestamptz(t time.Time) pgtype.Timestamptz
- func UUID(s uuid.UUID) pgtype.UUID
- type DB
- func (db *DB) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
- func (db *DB) GetLogs(ctx context.Context, runID string, phase internal.PhaseType) ([]byte, error)
- func (db *DB) Tx(ctx context.Context, callback func(internal.DB) error) error
- func (db *DB) WaitAndLock(ctx context.Context, id int64, fn func() 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 Timestamptz ¶
func Timestamptz(t time.Time) pgtype.Timestamptz
Timestamptz converts a go-time into a postgres non-null timestamptz
Types ¶
type DB ¶
type DB struct { *pgxpool.Pool // db connection pool pggen.Querier // generated queries logr.Logger // contains filtered or unexported fields }
DB provides access to the postgres db as well as queries generated from SQL
func (*DB) Tx ¶
Tx provides the caller with a callback in which all operations are conducted within a transaction.
func (*DB) WaitAndLock ¶
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.