db

package
v0.0.0-...-09efcc3 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCursor = InvalidCursor.New("invalid pagination cursor")
View Source
var ErrWriteConflict = apierrors.NewDataRace("concurrent write conflict occurred")
View Source
var InvalidCursor = apierrors.Invalid.WithReason("InvalidCursor")
View Source
var InvalidQuery = apierrors.BadRequest.WithReason("InvalidQuery")

Functions

This section is empty.

Types

type ConnectionOptions

type ConnectionOptions struct {
	DatabaseURL           string
	MaxOpenConnection     int
	MaxIdleConnection     int
	MaxConnectionLifetime time.Duration
	IdleConnectionTimeout time.Duration
}

type Handle

type Handle interface {
	// WithTx runs do within a transaction.
	// If there is no error, the transaction is committed.
	WithTx(ctx context.Context, do func(ctx context.Context) error) (err error)

	// ReadOnly runs do within a transaction.
	// The transaction is always rolled back.
	ReadOnly(ctx context.Context, do func(ctx context.Context) error) (err error)
}

Handle allows a function to be run within a transaction.

type HookHandle

type HookHandle struct {
	Pool              *Pool
	ConnectionOptions ConnectionOptions
	Logger            *log.Logger
}

func NewHookHandle

func NewHookHandle(pool *Pool, opts ConnectionOptions, lf *log.Factory) *HookHandle

func (*HookHandle) ReadOnly

func (h *HookHandle) ReadOnly(ctx context.Context, do func(ctx context.Context) error) (err error)

ReadOnly is like WithTx, except that it always rolls back.

func (*HookHandle) UseHook

func (h *HookHandle) UseHook(ctx context.Context, hook TransactionHook)

func (*HookHandle) WithPrepareStatementsHandle

func (h *HookHandle) WithPrepareStatementsHandle(ctx context.Context, do func(ctx context.Context, handle PreparedStatementsHandle) error) (err error)

func (*HookHandle) WithTx

func (h *HookHandle) WithTx(ctx context.Context, do func(ctx context.Context) error) (err error)

WithTx commits if do finishes without error and rolls back otherwise. WithTx is reentrant, meaning that you can call WithTx even when a previous WithTx does not finish yet. Normally you should not call WithTx within a WithTx, but there is a legit use case.

// Assume ctx is a http.Request context.
h.WithTx(ctx, func(ctx context.Context) error {
	// ctx here is associated with a *sql.Tx (Tx1)
	go func() {
		// ctx is detached from the http.Request context.
		ctx = ctx.WithCancel(ctx)
		h.WithTx(ctx, func(ctx context.Context) error {
			// ctx is associated with a *sqlTx (Tx2)
		})
	}()
})

type InsertBuilder

type InsertBuilder struct {
	// contains filtered or unexported fields
}

func (InsertBuilder) Columns

func (b InsertBuilder) Columns(columns ...string) InsertBuilder

func (InsertBuilder) Suffix

func (b InsertBuilder) Suffix(sql string, args ...interface{}) InsertBuilder

func (InsertBuilder) ToSql

func (b InsertBuilder) ToSql() (string, []interface{}, error)

nolint: golint

func (InsertBuilder) Values

func (b InsertBuilder) Values(values ...interface{}) InsertBuilder

type MockHandle

type MockHandle struct{}

func (*MockHandle) ReadOnly

func (h *MockHandle) ReadOnly(ctx context.Context, do func(ctx context.Context) error) (err error)

func (*MockHandle) WithTx

func (h *MockHandle) WithTx(ctx context.Context, do func(ctx context.Context) error) (err error)

type PQListener

type PQListener struct {
	DatabaseURL string
	Listener    *pq.Listener
}

func (*PQListener) Listen

func (p *PQListener) Listen(channels []string, done <-chan struct{}, onChange func(channel string, extra string), onError func(error))

type PageKey

type PageKey struct {
	Offset uint64
}

func NewFromPageCursor

func NewFromPageCursor(k model.PageCursor) (*PageKey, error)

func (*PageKey) ToPageCursor

func (k *PageKey) ToPageCursor() (model.PageCursor, error)

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool() *Pool

func (*Pool) Close

func (p *Pool) Close() (err error)

func (*Pool) Open

func (p *Pool) Open(opts ConnectionOptions) (db *sql.DB, err error)

type PreparedStatementsHandle

type PreparedStatementsHandle interface {
	// WithTx runs do within a transaction.
	// If there is no error, the transaction is committed.
	WithTx(ctx context.Context, do func(ctx context.Context) error) (err error)
}

PreparedStatementsHandle prepares and caches query.

type SQLBuilder

type SQLBuilder struct {
	sq.StatementBuilderType
	// contains filtered or unexported fields
}

func NewSQLBuilder

func NewSQLBuilder(schema string) SQLBuilder

func (SQLBuilder) TableName

func (b SQLBuilder) TableName(table string) string

type SQLBuilderApp

type SQLBuilderApp struct {
	// contains filtered or unexported fields
}

func NewSQLBuilderApp

func NewSQLBuilderApp(schema string, appID string) SQLBuilderApp

func (SQLBuilderApp) Delete

func (b SQLBuilderApp) Delete(from string) sq.DeleteBuilder

func (SQLBuilderApp) Insert

func (b SQLBuilderApp) Insert(into string) InsertBuilder

func (SQLBuilderApp) Select

func (b SQLBuilderApp) Select(columns ...string) SelectBuilder

func (SQLBuilderApp) TableName

func (b SQLBuilderApp) TableName(table string) string

func (SQLBuilderApp) Update

func (b SQLBuilderApp) Update(table string) sq.UpdateBuilder

type SQLExecutor

type SQLExecutor struct{}

func (*SQLExecutor) ExecWith

func (e *SQLExecutor) ExecWith(ctx context.Context, sqlizeri sq.Sqlizer) (sql.Result, error)

func (*SQLExecutor) QueryRowWith

func (e *SQLExecutor) QueryRowWith(ctx context.Context, sqlizeri sq.Sqlizer) (*sql.Row, error)

func (*SQLExecutor) QueryWith

func (e *SQLExecutor) QueryWith(ctx context.Context, sqlizeri sq.Sqlizer) (*sql.Rows, error)

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

Scanner is *sql.Row or *sql.Rows.

type SelectBuilder

type SelectBuilder struct {
	// contains filtered or unexported fields
}

func ApplyPageArgs

func ApplyPageArgs(builder SelectBuilder, pageArgs graphqlutil.PageArgs) (out SelectBuilder, offset uint64, err error)

func (SelectBuilder) From

func (b SelectBuilder) From(from string, alias ...string) SelectBuilder

func (SelectBuilder) Join

func (b SelectBuilder) Join(from string, alias string, pred string, args ...interface{}) SelectBuilder

func (SelectBuilder) LeftJoin

func (b SelectBuilder) LeftJoin(from string, alias string, pred string, args ...interface{}) SelectBuilder

func (SelectBuilder) Limit

func (b SelectBuilder) Limit(limit uint64) SelectBuilder

func (SelectBuilder) Offset

func (b SelectBuilder) Offset(offset uint64) SelectBuilder

func (SelectBuilder) OrderBy

func (b SelectBuilder) OrderBy(orderBy ...string) SelectBuilder

func (SelectBuilder) PrefixExpr

func (b SelectBuilder) PrefixExpr(expr sq.Sqlizer) SelectBuilder

func (SelectBuilder) ToSql

func (b SelectBuilder) ToSql() (string, []interface{}, error)

nolint: golint

func (SelectBuilder) Where

func (b SelectBuilder) Where(pred interface{}, args ...interface{}) SelectBuilder

type TransactionHook

type TransactionHook interface {
	WillCommitTx(ctx context.Context) error
	DidCommitTx(ctx context.Context)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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