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
- Variables
- func ColumnsForStruct(dest interface{}) []string
- type BatchInsertBuilder
- type ClientConfig
- type Conn
- type CtxKey
- type DeleteBuilder
- type ErrorHandlerFunc
- type FastBatchInsertBuilder
- func (b *FastBatchInsertBuilder) Exec(ctx context.Context, session SessionInterface, tableName string) error
- func (b *FastBatchInsertBuilder) Len() int
- func (b *FastBatchInsertBuilder) Reset()
- func (b *FastBatchInsertBuilder) Row(row map[string]interface{}) error
- func (b *FastBatchInsertBuilder) RowStruct(row interface{}) error
- type GetBuilder
- func (gb *GetBuilder) Exec(ctx context.Context) error
- func (gb *GetBuilder) Offset(offset uint64) *GetBuilder
- func (gb *GetBuilder) OrderBy(orderBys ...string) *GetBuilder
- func (gb *GetBuilder) Prefix(sql string, args ...interface{}) *GetBuilder
- func (gb *GetBuilder) Suffix(sql string, args ...interface{}) *GetBuilder
- func (gb *GetBuilder) Where(pred interface{}, args ...interface{}) *GetBuilder
- type InsertBuilder
- type MockSession
- func (m *MockSession) Begin(ctx context.Context) error
- func (m *MockSession) BeginTx(ctx context.Context, opts *sql.TxOptions) error
- func (m *MockSession) Clone() SessionInterface
- func (m *MockSession) Close() error
- func (m *MockSession) Commit() error
- func (m *MockSession) DeleteRange(ctx context.Context, start, end int64, table string, idCol string) (err error)
- func (m *MockSession) Exec(ctx context.Context, query squirrel.Sqlizer) (sql.Result, error)
- func (m *MockSession) ExecRaw(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (m *MockSession) Get(ctx context.Context, dest interface{}, query sq.Sqlizer) error
- func (m *MockSession) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (m *MockSession) GetTable(name string) *Table
- func (m *MockSession) GetTx() *sqlx.Tx
- func (m *MockSession) GetTxOptions() *sql.TxOptions
- func (m *MockSession) NoRows(err error) bool
- func (m *MockSession) Ping(ctx context.Context, timeout time.Duration) error
- func (m *MockSession) Query(ctx context.Context, query squirrel.Sqlizer) (*Rows, error)
- func (m *MockSession) QueryRaw(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (m *MockSession) Rollback() error
- func (m *MockSession) Select(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error
- func (m *MockSession) SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (m *MockSession) TruncateTables(ctx context.Context, tables []string) error
- type NoRowsError
- type QueryType
- type Rows
- type SelectBuilder
- func (sb *SelectBuilder) Exec(ctx context.Context) error
- func (sb *SelectBuilder) Limit(limit uint64) *SelectBuilder
- func (sb *SelectBuilder) Offset(offset uint64) *SelectBuilder
- func (sb *SelectBuilder) OrderBy(orderBys ...string) *SelectBuilder
- func (sb *SelectBuilder) Prefix(sql string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Suffix(sql string, args ...interface{}) *SelectBuilder
- func (sb *SelectBuilder) Where(pred interface{}, args ...interface{}) *SelectBuilder
- type Session
- func (s *Session) AddErrorHandler(handler ErrorHandlerFunc)
- func (s *Session) Begin(ctx context.Context) error
- func (s *Session) BeginTx(ctx context.Context, opts *sql.TxOptions) error
- func (s *Session) Clone() SessionInterface
- func (s *Session) Close() error
- func (s *Session) Commit() error
- func (s *Session) DeleteRange(ctx context.Context, start, end int64, table string, idCol string) error
- func (s *Session) Dialect() string
- func (s *Session) Exec(ctx context.Context, query sq.Sqlizer) (sql.Result, error)
- func (s *Session) ExecAll(ctx context.Context, script string) error
- func (s *Session) ExecRaw(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (s *Session) Get(ctx context.Context, dest interface{}, query sq.Sqlizer) error
- func (s *Session) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (s *Session) GetTable(name string) *Table
- func (s *Session) GetTx() *sqlx.Tx
- func (s *Session) GetTxOptions() *sql.TxOptions
- func (s *Session) NoRows(err error) bool
- func (s *Session) Ping(ctx context.Context, timeout time.Duration) error
- func (s *Session) Query(ctx context.Context, query sq.Sqlizer) (*Rows, error)
- func (s *Session) QueryRaw(ctx context.Context, query string, args ...interface{}) (*Rows, error)
- func (s *Session) ReplacePlaceholders(query string) (string, error)
- func (s *Session) Rollback() error
- func (s *Session) Select(ctx context.Context, dest interface{}, query sq.Sqlizer) error
- func (s *Session) SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (s *Session) TruncateTables(ctx context.Context, tables []string) error
- type SessionInterface
- type SessionWithMetrics
- func (s *SessionWithMetrics) Clone() SessionInterface
- func (s *SessionWithMetrics) Close() error
- func (s *SessionWithMetrics) DeleteRange(ctx context.Context, start, end int64, table string, idCol string) (err error)
- func (s *SessionWithMetrics) Exec(ctx context.Context, query squirrel.Sqlizer) (result sql.Result, err error)
- func (s *SessionWithMetrics) ExecRaw(ctx context.Context, query string, args ...interface{}) (result sql.Result, err error)
- func (s *SessionWithMetrics) Get(ctx context.Context, dest interface{}, query squirrel.Sqlizer) (err error)
- func (s *SessionWithMetrics) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (s *SessionWithMetrics) Ping(ctx context.Context, timeout time.Duration) (err error)
- func (s *SessionWithMetrics) Select(ctx context.Context, dest interface{}, query squirrel.Sqlizer) (err error)
- func (s *SessionWithMetrics) SelectRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) (err error)
- func (s *SessionWithMetrics) TruncateTables(ctx context.Context, tables []string) (err error)
- type Subservice
- type Table
- func (tbl *Table) Delete(pred interface{}, args ...interface{}) *DeleteBuilder
- func (tbl *Table) Get(dest interface{}, pred interface{}, args ...interface{}) *GetBuilder
- func (tbl *Table) Insert(rows ...interface{}) *InsertBuilder
- func (tbl *Table) Select(dest interface{}, pred interface{}, args ...interface{}) *SelectBuilder
- func (tbl *Table) Update() *UpdateBuilder
- type UpdateBuilder
- func (ub *UpdateBuilder) Exec(ctx context.Context) (sql.Result, error)
- func (ub *UpdateBuilder) Limit(limit uint64) *UpdateBuilder
- func (ub *UpdateBuilder) Offset(offset uint64) *UpdateBuilder
- func (ub *UpdateBuilder) OrderBy(orderBys ...string) *UpdateBuilder
- func (ub *UpdateBuilder) Prefix(sql string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) SetMap(clauses map[string]interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) SetStruct(s interface{}, ignored []string) *UpdateBuilder
- func (ub *UpdateBuilder) Suffix(sql string, args ...interface{}) *UpdateBuilder
- func (ub *UpdateBuilder) Where(pred interface{}, args ...interface{}) *UpdateBuilder
Constants ¶
const (
// PostgresQueryMaxParams defines the maximum number of parameters in a query.
PostgresQueryMaxParams = 65535
)
Variables ¶
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") )
var AdvisoryLockQueryType = QueryType("advisory_lock")
var CoreSubservice = Subservice("core")
var DeadlineCtxKey = CtxKey("deadline")
var DeleteQueryType = QueryType("delete")
var ErrNoTx = errors.New("cannot call Exec() outside of a transaction")
ErrNoTx is returned when Exec() is called outside of a transaction.
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.
var HistoryPrimarySubservice = Subservice("history_primary")
var HistorySubservice = Subservice("history")
var IngestSubservice = Subservice("ingest")
var InsertQueryType = QueryType("insert")
var QueryTypeContextKey = CtxKey("query_type")
var RouteContextKey = CtxKey("route")
var SelectQueryType = QueryType("select")
var UndefinedQueryType = QueryType("undefined")
var UpdateQueryType = QueryType("update")
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).
type ClientConfig ¶
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 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 ¶
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 ¶
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 ¶
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 ¶
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 (*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) Rollback ¶
func (m *MockSession) Rollback() 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 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 ¶
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) BeginTx ¶
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 ¶
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) 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) ExecAll ¶
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) 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) GetTxOptions ¶
func (*Session) NoRows ¶
NoRows returns true if the provided error resulted from a query that found no results.
func (*Session) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*Session) ReplacePlaceholders ¶
ReplacePlaceholders replaces the '?' parameter placeholders in the provided sql query with a sql dialect appropriate version. Use '??' to escape a placeholder.
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 (s *SessionWithMetrics) Clone() SessionInterface
func (*SessionWithMetrics) Close ¶
func (s *SessionWithMetrics) Close() error
func (*SessionWithMetrics) DeleteRange ¶
func (*SessionWithMetrics) GetRaw ¶
func (s *SessionWithMetrics) GetRaw(ctx context.Context, dest interface{}, query string, args ...interface{}) (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 ¶
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 ¶
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