sql

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package sql implements persistent storage using the postgres database.

Index

Constants

View Source
const TestDatabaseURL = "OTF_TEST_DATABASE_URL"

Variables

This section is empty.

Functions

func Error

func Error(err error) error

func JSON

func JSON(b []byte) pgtype.JSON

JSON converts a []byte into a postgres JSON type

func NewTestDB

func NewTestDB(t *testing.T) string

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 NullString

func NullString() pgtype.Text

NullString returns a postgres null string

func String

func String(s string) pgtype.Text

String converts a go-string into a postgres non-null string

func Timestamptz

func Timestamptz(t time.Time) pgtype.Timestamptz

Timestamptz converts a go-time into a postgres non-null timestamptz

func UUID

func UUID(s uuid.UUID) pgtype.UUID

UUID converts a google-go-uuid into a postgres non-null UUID

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 New

func New(ctx context.Context, opts Options) (*DB, error)

New constructs a new DB connection pool, and migrates the schema to the latest version.

func (*DB) Exec

func (db *DB) Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)

func (*DB) GetLogs

func (db *DB) GetLogs(ctx context.Context, runID string, phase internal.PhaseType) ([]byte, error)

GetLogs retrieves the logs for a given run phase.

func (*DB) Tx

func (db *DB) Tx(ctx context.Context, callback func(internal.DB) error) error

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() 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 Options

type Options struct {
	Logger     logr.Logger
	ConnString string
}

Options for constructing a DB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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