Documentation ¶
Index ¶
- Constants
- func BulkInsert(ctx context.Context, tx CRUD, itemsToInsert Bulker) (rowsInserted int, insertErr error)
- func Commit(tx *sqlx.Tx, resource string) error
- func Err(resource string, err error) error
- func NewTx(ctx context.Context, db *sqlx.DB) (*sqlx.Tx, error)
- func Rollback(tx *sqlx.Tx, resource string, err error) error
- func SanitizeString(s string) string
- func ToNullFloat64(f float64) sql.NullFloat64
- func ToNullInt64(i int64) sql.NullInt64
- func ToNullString(s string) sql.NullString
- func ToWhereClause(rebinder Rebinder, wherable Whereable) (clause string, args []interface{}, err error)
- type Bulker
- type CRUD
- type Cube
- type DatabaseErr
- type Equals
- type ExecRebinder
- type Execer
- type GetRebinder
- type Getter
- type In
- type NameBinder
- type NamedExecer
- type NamedGetBinder
- type NamedQuerier
- type NamedRowQuerier
- type OrderPair
- type Preparer
- type Querier
- type QueryBinder
- type QueryOption
- type QueryOptions
- type Rebinder
- type RowQueryBinder
- type SelectBinder
- type SelectGetter
- type Selecter
- type Whereable
- func All() Whereable
- func And(first Whereable, second Whereable, rest ...Whereable) Whereable
- func ByFieldEquals(field string, value interface{}) Whereable
- func ByFieldIn(field string, values ...interface{}) Whereable
- func ByFieldNotEquals(field string, value interface{}) Whereable
- func ByID(id interface{}) Whereable
- func ByIDsIn(ids ...string) Whereable
- func ByItemID(id interface{}) Whereable
- func ByItemIDsIn(ids ...string) Whereable
- func ByLocationID(id interface{}) Whereable
- func IDsNotNull() Whereable
- func Like(column string, val string) Whereable
- func Or(first Whereable, second Whereable, rest ...Whereable) Whereable
Constants ¶
const QueryOptionTypeLimit = "limit"
QueryOptionTypeLimit describes a limit option type
const QueryOptionTypeOffset = "offset"
QueryOptionTypeOffset describes an offset option type
const QueryOptionTypeOrderBy = "orderBy"
QueryOptionTypeOrderBy describes an order by option type
Variables ¶
This section is empty.
Functions ¶
func BulkInsert ¶
func BulkInsert(ctx context.Context, tx CRUD, itemsToInsert Bulker) (rowsInserted int, insertErr error)
BulkInsert is a general bulk insert func that can be used to insert any valid Bulker type.
func Commit ¶
Commit will attept to commit the provided resource. Upon a failure to commit, the transaction will be rolled back.
func NewTx ¶
NewTx creates a new database transaction with default isolation levels and passes a context to roll back a transaction in the case of a context cancellation. Should clean up any zombie connections that could be if we did not control for this.
func SanitizeString ¶
SanitizeString removes \u0000 (null byte) characters, as PG cannot handle them.
Relevant Thread: https://www.postgresql.org/message-id/CAE37PpOn%3DMcGeokmny4tm4FTHmXSG4KydgUJemKqT9XxkrrTmg%40mail.gmail.com TLDR: Postgres is written in C and uses null bytes to terminate strings. It would be too much work to change across the whole codebase.
func ToNullFloat64 ¶
func ToNullFloat64(f float64) sql.NullFloat64
ToNullFloat64 is a utility method to convert a float64 into an sql null float64. This func never sets the valid field to false.
func ToNullInt64 ¶
ToNullInt64 is a utility method to convert a int64 into an sql null int64. This func never sets the valid field to false.
func ToNullString ¶
func ToNullString(s string) sql.NullString
ToNullString is a utility method to convert a string into a sql null string. If the input string is len 0 it will set a sql.NullString with Valid false.
Types ¶
type Bulker ¶
type Bulker interface { Len() int PrepareStatement() string KeyedArgsAtIndex(index int) (key string, arguments []interface{}) TableName() string }
Bulker is an interface that defines the behavior a type needs to implement to be bulk insert/updated into PG.
type CRUD ¶
CRUD is a ready to go type that implements most of the basic methods we use for 90%+ of our database calls.
type Cube ¶
type Cube []float64
Cube is a type that is used to work with the postgresql cube extension which enables the use of euclidian operators on a matrix of sorts. As of writing this, the only supported use case is a 1xn matrix, since that is all we support in faces at the moment. For more information on cube see: https://www.postgresql.org/docs/9.6/cube.html.
type DatabaseErr ¶
type DatabaseErr struct {
// contains filtered or unexported fields
}
DatabaseErr provides meaningful behavior to the postgres error.
func (*DatabaseErr) Conflict ¶
func (e *DatabaseErr) Conflict() bool
Conflict returns where this error refers to the behavior of a resource that conflicts. At this time the conflict is determiend from a foreign key violation, but can be expanded in the future.
func (*DatabaseErr) Exists ¶
func (e *DatabaseErr) Exists() bool
Exists returns whether this error refers to the behavior of a resource that already exists in the datastore and a violation is thrown. This will be true for a unique key violation in the PG store, but can be expanded in the future.
func (*DatabaseErr) NotFound ¶
func (e *DatabaseErr) NotFound() bool
NotFound returns whether this error refers to the behavior of a resource that was not found.
type Equals ¶
type Equals struct { Key string Val interface{} }
Equals is a struct used to represent a part of a where clause
type ExecRebinder ¶
ExecRebinder is an interface that is agnostic for database transactions for the sql type, an execer can be a sqlx.DB, transactions for something custom.
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Execer provides the exec behavior.
type GetRebinder ¶
GetRebinder provides the get and rebinding functionality.
type Getter ¶
type Getter interface {
GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}
Getter provides get functionality.
type In ¶
type In struct { Key string Vals []interface{} }
In is a struct used to represent an IN clause
type NameBinder ¶
type NameBinder interface {
BindNamed(query string, v interface{}) (bindedQuery string, args []interface{}, err error)
}
NameBinder preforms an operating that returns a pointer sql.Result.
type NamedExecer ¶
type NamedExecer interface {
NamedExecContext(ctx context.Context, query string, args interface{}) (sql.Result, error)
}
NamedExecer preforms an operating that returns an sql.Result and error.
type NamedGetBinder ¶
type NamedGetBinder interface { Getter Rebinder NameBinder }
NamedGetBinder allows you to use the GetContext query.
type NamedQuerier ¶
type NamedQuerier interface { QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) NameBinder }
NamedQuerier allows you to use the named query arguments with a query.
type NamedRowQuerier ¶
type NamedRowQuerier interface { QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row NameBinder }
NamedRowQuerier allows you to use the named query arguments with a row query.
type OrderPair ¶
OrderPair is a type to declare a column to be ordered by and if it should be ASC or DESC.
type Querier ¶
type Querier interface {
QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error)
}
Querier preforms an operating that returns a pointer sql.Rows and possible error.
type QueryBinder ¶
type QueryBinder interface { QueryxContext(ctx context.Context, query string, args ...interface{}) (*sqlx.Rows, error) Rebinder }
QueryBinder preforms an operating that returns a pointer sql.Result.
type QueryOption ¶
type QueryOption interface { Clause() string Type() string // contains filtered or unexported methods }
QueryOption is an interface around query options that can be of and order By, Limit or Offset.
func Limit ¶
func Limit(lim int64) QueryOption
Limit returns a QueryOption that applies a LIMIT to the query.
func Offset ¶
func Offset(o int64) QueryOption
Offset returns a QueryOption that applies an OFFSET to the query.
func OrderBy ¶
func OrderBy(cols ...OrderPair) QueryOption
OrderBy returns a QueryOption that applies an ORDER BY to the query.
type QueryOptions ¶
type QueryOptions []QueryOption
QueryOptions provides a means to turn a collection of Query Options into a sql safe clause.
func (QueryOptions) Clause ¶
func (q QueryOptions) Clause() string
Clause prints out a sql ready statement for the Rebinder to repackage.
type RowQueryBinder ¶
type RowQueryBinder interface { QueryRowxContext(ctx context.Context, query string, args ...interface{}) *sqlx.Row Rebinder }
RowQueryBinder preforms an operating that returns a pointer sql.Result.
type SelectBinder ¶
SelectBinder preforms a query with a context.
type SelectGetter ¶
SelectGetter combines Selecter and Getter interfaces.
type Selecter ¶
type Selecter interface {
SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}
Selecter performs select behavior with contexts.
type Whereable ¶
type Whereable interface {
Clause(rebinder Rebinder) (query string, args []interface{}, err error)
}
Whereable is a way of creating a functional query statement for different lookups.
func ByFieldEquals ¶
ByFieldEquals creates a `{field} = ?` argument for a Where clause.
func ByFieldNotEquals ¶
ByFieldNotEquals creates a `{field} = ?` argument for a Where clause.
func ByID ¶
func ByID(id interface{}) Whereable
ByID creates a `id = ?` argument for a Where clause.
func ByItemID ¶
func ByItemID(id interface{}) Whereable
ByItemID creates a `id = ?` argument for a Where clause.
func ByItemIDsIn ¶
ByItemIDsIn provides a where clause with the IN syntax, matching many rows potentially.
func ByLocationID ¶
func ByLocationID(id interface{}) Whereable
ByLocationID creates a `location_id = ?` arugment for a Where clause.