db

package
v0.0.0-...-095633c Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2024 License: Apache-2.0, Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package db is the base package for database access at hcnet. It primarily exposes Session which is a lightweight wrapper around a *sqlx.DB that provides utility methods (See the repo tests for examples).

In addition to the query methods, this package provides query logging and stateful transaction management.

In addition to the lower-level access facilities, this package exposes a system to build queries more dynamically using the help of https://github.com/Masterminds/squirrel. These builder method are access through the `Table` type.

Index

Constants

View Source
const (
	// PostgresQueryMaxParams defines the maximum number of parameters in a query.
	PostgresQueryMaxParams = 65535
)

Variables

View Source
var (
	// ErrTimeout is an error returned by Session methods when request has
	// taken longer than context's deadline max duration
	ErrTimeout = errors.New("canceling statement due to lack of response within timeout period")
	// ErrCancelled is an error returned by Session methods when request has
	// been canceled (ex. context canceled).
	ErrCancelled = errors.New("canceling statement due to user request")
	// ErrAlreadyRolledback is an error returned by Session methods when the transaction
	// containing the request has already been rolled back.
	ErrAlreadyRolledback = errors.New("transaction has already been committed or rolled back")
	// ErrConflictWithRecovery is an error returned by Session methods when
	// read replica cancels the query due to conflict with about-to-be-applied
	// WAL entries (https://www.postgresql.org/docs/current/hot-standby.html).
	ErrConflictWithRecovery = errors.New("canceling statement due to conflict with recovery")
	// ErrBadConnection is an error returned when driver returns `bad connection`
	// error.
	ErrBadConnection = errors.New("bad connection")
	// ErrStatementTimeout is an error returned by Session methods when request has
	// been canceled due to a statement timeout.
	ErrStatementTimeout = errors.New("canceling statement due to statement timeout")
)
View Source
var AdvisoryLockQueryType = QueryType("advisory_lock")
View Source
var CoreSubservice = Subservice("core")
View Source
var DeadlineCtxKey = CtxKey("deadline")
View Source
var DeleteQueryType = QueryType("delete")
View Source
var ErrNoTx = errors.New("cannot call Exec() outside of a transaction")

ErrNoTx is returned when Exec() is called outside of a transaction.

View Source
var ErrSealed = errors.New("cannot add more rows after Exec() without calling Reset() first")

ErrSealed is returned when trying to add rows to the FastBatchInsertBuilder after Exec() is called. Once Exec() is called no more rows can be added to the FastBatchInsertBuilder unless you call Reset() which clears out the old rows from the FastBatchInsertBuilder.

View Source
var HistoryPrimarySubservice = Subservice("history_primary")
View Source
var HistorySubservice = Subservice("history")
View Source
var IngestSubservice = Subservice("ingest")
View Source
var InsertQueryType = QueryType("insert")
View Source
var QueryTypeContextKey = CtxKey("query_type")
View Source
var RouteContextKey = CtxKey("route")
View Source
var SelectQueryType = QueryType("select")
View Source
var UndefinedQueryType = QueryType("undefined")
View Source
var UpdateQueryType = QueryType("update")
View Source
var UpsertQueryType = QueryType("upsert")

Functions

func ColumnsForStruct

func ColumnsForStruct(dest interface{}) []string

ColumnsForStruct returns a slice of column names for the provided value (which should be a struct, a slice of structs).

Types

type BatchInsertBuilder

type BatchInsertBuilder struct {
	Table *Table
	// MaxBatchSize defines the maximum size of a batch. If this number is
	// reached after calling Row() it will call Exec() immediately inserting
	// all rows to a DB.
	// Zero (default) will not add rows until explicitly calling Exec.
	MaxBatchSize int

	// Suffix adds a sql expression to the end of the query (e.g. an ON CONFLICT clause)
	Suffix string
	// contains filtered or unexported fields
}

BatchInsertBuilder works like sq.InsertBuilder but has a better support for batching large number of rows. It is NOT safe for concurrent use.

func (*BatchInsertBuilder) Exec

func (b *BatchInsertBuilder) Exec(ctx context.Context) error

Exec inserts rows in batches. In case of errors it's possible that some batches were added so this should be run in a DB transaction for easy rollbacks.

func (*BatchInsertBuilder) Row

func (b *BatchInsertBuilder) Row(ctx context.Context, row map[string]interface{}) error

Row adds a new row to the batch. All rows must have exactly the same columns (map keys). Otherwise, error will be returned. Please note that rows are not added one by one but in batches when `Exec` is called (or `MaxBatchSize` is reached).

func (*BatchInsertBuilder) RowStruct

func (b *BatchInsertBuilder) RowStruct(ctx context.Context, row interface{}) error

type ClientConfig

type ClientConfig struct {
	Key   string
	Value string
}

func IdleTransactionTimeout

func IdleTransactionTimeout(timeout time.Duration) ClientConfig

func StatementTimeout

func StatementTimeout(timeout time.Duration) ClientConfig

type Conn

type Conn interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	Rebind(sql string) string
	QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

Conn represents a connection to a single database.

type CtxKey

type CtxKey string

type DeleteBuilder

type DeleteBuilder struct {
	Table *Table
	// contains filtered or unexported fields
}

DeleteBuilder is a helper struct used to construct sql queries of the DELETE variety.

func (*DeleteBuilder) Exec

func (delb *DeleteBuilder) Exec(ctx context.Context) (sql.Result, error)

Exec executes the query represented by the builder, deleting any rows that match the queries where clauses.

func (*DeleteBuilder) Where

func (delb *DeleteBuilder) Where(
	pred interface{},
	args ...interface{},
) *DeleteBuilder

Where is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#DeleteBuilder.Where

type ErrorHandlerFunc

type ErrorHandlerFunc func(dbErr error, ctx context.Context)

dbErr - the Postgres error ctx - the caller's context

type FastBatchInsertBuilder

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

FastBatchInsertBuilder works like sq.InsertBuilder but has a better support for batching large number of rows. It is NOT safe for concurrent use. It does NOT support updating existing rows.

func (*FastBatchInsertBuilder) Exec

func (b *FastBatchInsertBuilder) Exec(ctx context.Context, session SessionInterface, tableName string) error

Exec inserts rows in a single COPY statement. Once Exec is called no more rows can be added to the FastBatchInsertBuilder unless Reset is called. Exec must be called within a transaction.

func (*FastBatchInsertBuilder) Len

func (b *FastBatchInsertBuilder) Len() int

Len returns the number of rows held in memory by the FastBatchInsertBuilder.

func (*FastBatchInsertBuilder) Reset

func (b *FastBatchInsertBuilder) Reset()

Reset clears out all the rows contained in the FastBatchInsertBuilder. After Reset is called new rows can be added to the FastBatchInsertBuilder.

func (*FastBatchInsertBuilder) Row

func (b *FastBatchInsertBuilder) Row(row map[string]interface{}) error

Row adds a new row to the batch. All rows must have exactly the same columns (map keys). Otherwise, error will be returned. Please note that rows are not added one by one but in batches when `Exec` is called.

func (*FastBatchInsertBuilder) RowStruct

func (b *FastBatchInsertBuilder) RowStruct(row interface{}) error

RowStruct adds a new row to the batch. All rows must have exactly the same columns (map keys). Otherwise, error will be returned. Please note that rows are not added one by one but in batches when `Exec` is called.

type GetBuilder

type GetBuilder struct {
	Table *Table
	// contains filtered or unexported fields
}

GetBuilder is a helper struct used to construct sql queries of the SELECT variety.

func (*GetBuilder) Exec

func (gb *GetBuilder) Exec(ctx context.Context) error

Exec executes the query represented by the builder, populating the destination with the results returned by running the query against the current database session.

func (*GetBuilder) Offset

func (gb *GetBuilder) Offset(offset uint64) *GetBuilder

Offset is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Offset

func (*GetBuilder) OrderBy

func (gb *GetBuilder) OrderBy(
	orderBys ...string,
) *GetBuilder

OrderBy is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.OrderBy

func (*GetBuilder) Prefix

func (gb *GetBuilder) Prefix(
	sql string,
	args ...interface{},
) *GetBuilder

Prefix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Prefix

func (*GetBuilder) Suffix

func (gb *GetBuilder) Suffix(
	sql string,
	args ...interface{},
) *GetBuilder

Suffix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Suffix

func (*GetBuilder) Where

func (gb *GetBuilder) Where(
	pred interface{},
	args ...interface{},
) *GetBuilder

Where is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#GetBuilder.Where

type InsertBuilder

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

InsertBuilder is a helper struct used to construct sql queries of the INSERT variety. NOTE: InsertBuilder will use "zero" value of a type in case of nil pointer values. If you need to insert `NULL` use sql.Null* or build your own type that implements database/sql/driver.Valuer.

func (*InsertBuilder) Exec

func (ib *InsertBuilder) Exec(ctx context.Context) (sql.Result, error)

Exec executes the query represented by the builder, inserting each val provided to the builder into the database.

func (*InsertBuilder) IgnoreCols

func (ib *InsertBuilder) IgnoreCols(cols ...string) *InsertBuilder

IgnoreCols adds colums to ignore list (will not be inserted)

func (*InsertBuilder) Rows

func (ib *InsertBuilder) Rows(rows ...interface{}) *InsertBuilder

Rows appends more rows onto the insert statement

type MockSession

type MockSession struct {
	mock.Mock
}

func (*MockSession) Begin

func (m *MockSession) Begin(ctx context.Context) error

func (*MockSession) BeginTx

func (m *MockSession) BeginTx(ctx context.Context, opts *sql.TxOptions) error

func (*MockSession) Clone

func (m *MockSession) Clone() SessionInterface

func (*MockSession) Close

func (m *MockSession) Close() error

func (*MockSession) Commit

func (m *MockSession) Commit() error

func (*MockSession) DeleteRange

func (m *MockSession) DeleteRange(
	ctx context.Context,
	start, end int64,
	table string,
	idCol string,
) (err error)

func (*MockSession) Exec

func (m *MockSession) Exec(ctx context.Context, query squirrel.Sqlizer) (sql.Result, error)

func (*MockSession) ExecRaw

func (m *MockSession) ExecRaw(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

func (*MockSession) Get

func (m *MockSession) Get(ctx context.Context, dest interface{}, query sq.Sqlizer) error

func (*MockSession) GetRaw

func (m *MockSession) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error

func (*MockSession) GetTable

func (m *MockSession) GetTable(name string) *Table

func (*MockSession) GetTx

func (m *MockSession) GetTx() *sqlx.Tx

func (*MockSession) GetTxOptions

func (m *MockSession) GetTxOptions() *sql.TxOptions

func (*MockSession) NoRows

func (m *MockSession) NoRows(err error) bool

func (*MockSession) Ping

func (m *MockSession) Ping(ctx context.Context, timeout time.Duration) error

func (*MockSession) Query

func (m *MockSession) Query(ctx context.Context, query squirrel.Sqlizer) (*Rows, error)

func (*MockSession) QueryRaw

func (m *MockSession) QueryRaw(ctx context.Context, query string, args ...interface{}) (*Rows, error)

func (*MockSession) Rollback

func (m *MockSession) Rollback() error

func (*MockSession) Select

func (m *MockSession) Select(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error

func (*MockSession) SelectRaw

func (m *MockSession) SelectRaw(ctx context.Context,
	dest interface{},
	query string,
	args ...interface{},
) error

func (*MockSession) TruncateTables

func (m *MockSession) TruncateTables(ctx context.Context, tables []string) error

type NoRowsError

type NoRowsError struct {
}

NoRowsError is returned when an insert is attempted without providing any values to insert.

func (*NoRowsError) Error

func (err *NoRowsError) Error() string

type QueryType

type QueryType string

type Rows

type Rows struct {
	sqlx.Rows
	// contains filtered or unexported fields
}

func (*Rows) Close

func (r *Rows) Close() error

type SelectBuilder

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

SelectBuilder is a helper struct used to construct sql queries of the SELECT variety.

func (*SelectBuilder) Exec

func (sb *SelectBuilder) Exec(ctx context.Context) error

Exec executes the query represented by the builder, populating the destination with the results returned by running the query against the current database session.

func (*SelectBuilder) Limit

func (sb *SelectBuilder) Limit(limit uint64) *SelectBuilder

Limit is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Limit

func (*SelectBuilder) Offset

func (sb *SelectBuilder) Offset(offset uint64) *SelectBuilder

Offset is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Offset

func (*SelectBuilder) OrderBy

func (sb *SelectBuilder) OrderBy(
	orderBys ...string,
) *SelectBuilder

OrderBy is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.OrderBy

func (*SelectBuilder) Prefix

func (sb *SelectBuilder) Prefix(
	sql string,
	args ...interface{},
) *SelectBuilder

Prefix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Prefix

func (*SelectBuilder) Suffix

func (sb *SelectBuilder) Suffix(
	sql string,
	args ...interface{},
) *SelectBuilder

Suffix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Suffix

func (*SelectBuilder) Where

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

Where is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#SelectBuilder.Where

type Session

type Session struct {
	// DB is the database connection that queries should be executed against.
	DB *sqlx.DB
	// contains filtered or unexported fields
}

Session provides helper methods for making queries against `DB` and provides utilities such as automatic query logging and transaction management. NOTE: Because transaction-handling is stateful, it is not presently intended to cross goroutine boundaries and is not concurrency safe.

func Open

func Open(dialect, dsn string, clientConfigs ...ClientConfig) (*Session, error)

Open the database at `dsn` and returns a new *Session using it.

func Wrap

func Wrap(base *sql.DB, dialect string) *Session

Wrap wraps a bare *sql.DB (from the database/sql stdlib package) in a *db.Session instance. It is meant to be used in cases where you do not control the instantiation of the database connection, but would still like to leverage the facilities provided in Session.

func (*Session) AddErrorHandler

func (s *Session) AddErrorHandler(handler ErrorHandlerFunc)

func (*Session) Begin

func (s *Session) Begin(ctx context.Context) error

Begin binds this session to a new transaction.

func (*Session) BeginTx

func (s *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) error

BeginTx binds this session to a new transaction which is configured with the given transaction options

func (*Session) Clone

func (s *Session) Clone() SessionInterface

Clone clones the receiver, returning a new instance backed by the same context and db. The result will not be bound to any transaction that the source is currently within.

func (*Session) Close

func (s *Session) Close() error

Close delegates to the underlying database Close method, closing the database and releasing any resources. It is rare to Close a DB, as the DB handle is meant to be long-lived and shared between many goroutines.

func (*Session) Commit

func (s *Session) Commit() error

Commit commits the current transaction

func (*Session) DeleteRange

func (s *Session) DeleteRange(
	ctx context.Context,
	start, end int64,
	table string,
	idCol string,
) error

DeleteRange deletes a range of rows from a sql table between `start` and `end` (exclusive).

func (*Session) Dialect

func (s *Session) Dialect() string

Dialect returns the SQL dialect that this session is configured to use

func (*Session) Exec

func (s *Session) Exec(ctx context.Context, query sq.Sqlizer) (sql.Result, error)

Exec runs `query`

func (*Session) ExecAll

func (s *Session) ExecAll(ctx context.Context, script string) error

ExecAll runs all sql commands in `script` against `r` within a single transaction.

func (*Session) ExecRaw

func (s *Session) ExecRaw(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecRaw runs `query` with `args`

func (*Session) Get

func (s *Session) Get(ctx context.Context, dest interface{}, query sq.Sqlizer) error

Get runs `query`, setting the first result found on `dest`, if any.

func (*Session) GetRaw

func (s *Session) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error

GetRaw runs `query` with `args`, setting the first result found on `dest`, if any.

func (*Session) GetTable

func (s *Session) GetTable(name string) *Table

GetTable translates the provided struct into a Table,

func (*Session) GetTx

func (s *Session) GetTx() *sqlx.Tx

func (*Session) GetTxOptions

func (s *Session) GetTxOptions() *sql.TxOptions

func (*Session) NoRows

func (s *Session) NoRows(err error) bool

NoRows returns true if the provided error resulted from a query that found no results.

func (*Session) Ping

func (s *Session) Ping(ctx context.Context, timeout time.Duration) error

Ping verifies a connection to the database is still alive, establishing a connection if necessary.

func (*Session) Query

func (s *Session) Query(ctx context.Context, query sq.Sqlizer) (*Rows, error)

Query runs `query`, returns a *sqlx.Rows instance

func (*Session) QueryRaw

func (s *Session) QueryRaw(ctx context.Context, query string, args ...interface{}) (*Rows, error)

QueryRaw runs `query` with `args`

func (*Session) ReplacePlaceholders

func (s *Session) ReplacePlaceholders(query string) (string, error)

ReplacePlaceholders replaces the '?' parameter placeholders in the provided sql query with a sql dialect appropriate version. Use '??' to escape a placeholder.

func (*Session) Rollback

func (s *Session) Rollback() error

Rollback rolls back the current transaction

func (*Session) Select

func (s *Session) Select(ctx context.Context, dest interface{}, query sq.Sqlizer) error

Select runs `query`, setting the results found on `dest`.

func (*Session) SelectRaw

func (s *Session) SelectRaw(
	ctx context.Context,
	dest interface{},
	query string,
	args ...interface{},
) error

SelectRaw runs `query` with `args`, setting the results found on `dest`.

func (*Session) TruncateTables

func (s *Session) TruncateTables(ctx context.Context, tables []string) error

type SessionInterface

type SessionInterface interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) error
	Begin(ctx context.Context) error
	Rollback() error
	Commit() error
	GetTx() *sqlx.Tx
	GetTxOptions() *sql.TxOptions
	TruncateTables(ctx context.Context, tables []string) error
	Clone() SessionInterface
	Close() error
	Get(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error
	GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	Select(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error
	SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	Query(ctx context.Context, query squirrel.Sqlizer) (*Rows, error)
	QueryRaw(ctx context.Context, query string, args ...interface{}) (*Rows, error)
	GetTable(name string) *Table
	Exec(ctx context.Context, query squirrel.Sqlizer) (sql.Result, error)
	ExecRaw(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	NoRows(err error) bool
	Ping(ctx context.Context, timeout time.Duration) error
	DeleteRange(
		ctx context.Context,
		start, end int64,
		table string,
		idCol string,
	) error
}

func RegisterMetrics

func RegisterMetrics(base *Session, namespace string, sub Subservice, registry *prometheus.Registry) SessionInterface

type SessionWithMetrics

type SessionWithMetrics struct {
	SessionInterface
	// contains filtered or unexported fields
}

func (*SessionWithMetrics) Clone

func (*SessionWithMetrics) Close

func (s *SessionWithMetrics) Close() error

func (*SessionWithMetrics) DeleteRange

func (s *SessionWithMetrics) DeleteRange(
	ctx context.Context,
	start, end int64,
	table string,
	idCol string,
) (err error)

func (*SessionWithMetrics) Exec

func (s *SessionWithMetrics) Exec(ctx context.Context, query squirrel.Sqlizer) (result sql.Result, err error)

func (*SessionWithMetrics) ExecRaw

func (s *SessionWithMetrics) ExecRaw(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)

func (*SessionWithMetrics) Get

func (s *SessionWithMetrics) Get(ctx context.Context, dest interface{}, query squirrel.Sqlizer) (err error)

func (*SessionWithMetrics) GetRaw

func (s *SessionWithMetrics) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)

func (*SessionWithMetrics) Ping

func (s *SessionWithMetrics) Ping(ctx context.Context, timeout time.Duration) (err error)

func (*SessionWithMetrics) Select

func (s *SessionWithMetrics) Select(ctx context.Context, dest interface{}, query squirrel.Sqlizer) (err error)

func (*SessionWithMetrics) SelectRaw

func (s *SessionWithMetrics) SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)

func (*SessionWithMetrics) TruncateTables

func (s *SessionWithMetrics) TruncateTables(ctx context.Context, tables []string) (err error)

type Subservice

type Subservice string

type Table

type Table struct {
	// Name is the name of the table
	Name string

	Session *Session
}

Table helps to build sql queries against a given table. It logically represents a SQL table on the database that `Session` is connected to.

func (*Table) Delete

func (tbl *Table) Delete(
	pred interface{},
	args ...interface{},
) *DeleteBuilder

Delete returns a new query builder configured to delete rows from the table.

func (*Table) Get

func (tbl *Table) Get(
	dest interface{},
	pred interface{},
	args ...interface{},
) *GetBuilder

Get returns a new query builder configured to select into the provided `dest`.

Get behaves the same was as Select, but automatically limits the query generated to a single value and only populates a single struct.

func (*Table) Insert

func (tbl *Table) Insert(rows ...interface{}) *InsertBuilder

Insert returns a new query builder configured to insert structs into the table.

Insert takes one or more struct (or pointer to struct) values, each of which represents a single row to be created in the table. The first value provided in a call to this function will operate as the template for the insert and will determine what columns are populated in the query. For this reason, it is highly recommmended that you always use the same struct type for any single call this function.

An InsertBuilder uses the "db" struct tag to determine the column names that a given struct should be mapped to, and by default the unmofdified name of the field will be used. Similar to other struct tags, the value "-" will cause the field to be skipped.

NOTE: using the omitempty option, such as used with json struct tags, is not supported.

func (*Table) Select

func (tbl *Table) Select(
	dest interface{},
	pred interface{},
	args ...interface{},
) *SelectBuilder

Select returns a new query builder configured to select into the provided `dest`.

func (*Table) Update

func (tbl *Table) Update() *UpdateBuilder

Update returns a new query builder configured to update the table. See docs for `UpdateBuilderExec` for more documentation.

type UpdateBuilder

type UpdateBuilder struct {
	Table *Table
	// contains filtered or unexported fields
}

UpdateBuilder is a helper struct used to construct sql queries of the UPDATE variety.

func (*UpdateBuilder) Exec

func (ub *UpdateBuilder) Exec(ctx context.Context) (sql.Result, error)

Exec executes the query that has been previously configured on the UpdateBuilder.

func (*UpdateBuilder) Limit

func (ub *UpdateBuilder) Limit(limit uint64) *UpdateBuilder

Limit is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Limit

func (*UpdateBuilder) Offset

func (ub *UpdateBuilder) Offset(offset uint64) *UpdateBuilder

Offset is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Offset

func (*UpdateBuilder) OrderBy

func (ub *UpdateBuilder) OrderBy(
	orderBys ...string,
) *UpdateBuilder

OrderBy is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.OrderBy

func (*UpdateBuilder) Prefix

func (ub *UpdateBuilder) Prefix(
	sql string,
	args ...interface{},
) *UpdateBuilder

Prefix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Prefix

func (*UpdateBuilder) Set

func (ub *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder

Set is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Set

func (*UpdateBuilder) SetMap

func (ub *UpdateBuilder) SetMap(clauses map[string]interface{}) *UpdateBuilder

SetMap is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.SetMap

func (*UpdateBuilder) SetStruct

func (ub *UpdateBuilder) SetStruct(s interface{}, ignored []string) *UpdateBuilder

SetStruct is using `db` tag on the struct and updates the query with struct values for each field (except `ignored` fields).

func (*UpdateBuilder) Suffix

func (ub *UpdateBuilder) Suffix(
	sql string,
	args ...interface{},
) *UpdateBuilder

Suffix is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Suffix

func (*UpdateBuilder) Where

func (ub *UpdateBuilder) Where(
	pred interface{},
	args ...interface{},
) *UpdateBuilder

Where is a passthrough call to the squirrel. See https://godoc.org/github.com/Masterminds/squirrel#UpdateBuilder.Where

Directories

Path Synopsis
Package sqlutils contains utility functions for manipulating strings of SQL
Package sqlutils contains utility functions for manipulating strings of SQL

Jump to

Keyboard shortcuts

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