Documentation
¶
Index ¶
- Constants
- func AddToWhereClause(whereClause, newClause string) string
- func BatchInsertQuery(sqlQueryTemplate string, objectsToInsertSlice any, dbColumns ...string) (string, []any)
- func GetDBColumns(object any, opts ...GetDBColumnsOption) []string
- func GetParams(object any, dbColumns ...string) []any
- func InsertQuery(sqlQueryTemplate string, objectToInsert any, dbColumns ...string) (string, []any)
- func IsUniqueViolation(err error) bool
- func NewNullString(s string) sql.NullString
- func QualifyColumns(columns []string, alias string) string
- func SelectQuery(sqlQueryTemplate string, dbColumns []string) string
- type Client
- type Dictionary
- type GetDBColumnsOption
- type GetDBColumnsOpts
- type Opts
- type Tx
Constants ¶
const ( Serializable = pgx.Serializable RepeatableRead = pgx.RepeatableRead ReadCommitted = pgx.ReadCommitted ReadUncommitted = pgx.ReadUncommitted )
Variables ¶
This section is empty.
Functions ¶
func AddToWhereClause ¶
func BatchInsertQuery ¶
func BatchInsertQuery(sqlQueryTemplate string, objectsToInsertSlice any, dbColumns ...string) (string, []any)
BatchInsertQuery takes an sqlQueryTemplate of the form 'INSERT INTO table_name %s VALUES %s', a slice of objects to insert as well as the dbColumns which should map 1-to-1 with the object's db tags. It will return a query and an array of params that can be used directly with db.Exec(query, params) or tx.Exec(query, params). This method will panic if one of the dbColumns is not a valid tag of an object to insert.
func GetDBColumns ¶
func GetDBColumns(object any, opts ...GetDBColumnsOption) []string
GetDBColumns returns all db tags of a struct passed by value.
func InsertQuery ¶
InsertQuery takes an sqlQueryTemplate of the form 'INSERT INTO table_name %s VALUES %s', an object to insert as well as the dbColumns which should map 1-to-1 with the object's db tags. It will return a query and an array of params that can be used directly with db.Exec(query, params) or tx.Exec(query, params). This method will panic if one of the dbColumns is not a valid tag of an object to insert.
func IsUniqueViolation ¶
IsUniqueViolation returns true if the error is a PostgreSQL unique constraint violation (SQLSTATE 23505).
func NewNullString ¶
func NewNullString(s string) sql.NullString
NewNullString returns a sql.NullString value from an input string
func QualifyColumns ¶
QualifyColumns returns a comma-separated string of columns prefixed with the given table alias.
func SelectQuery ¶
SelectQuery injects dbColumns into a sqlQuery template
Types ¶
type Client ¶
Client is a wrapper around sqlx db to avoid importing it in core packages.
func (*Client) ExecuteTransaction ¶
func (c *Client) ExecuteTransaction(ctx context.Context, isolationLevel pgx.TxIsoLevel, fn func(pgx.Tx) error) error
ExecuteTransaction executes a transaction and retries serialization failures.
type Dictionary ¶
Dictionary is a postgres safe alias of map[string]string. This object can be inserted and retrieved from the database without the user having to marshal or unmarshal a dictionary.
func (*Dictionary) Scan ¶
func (d *Dictionary) Scan(src any) error
Scan implements the sql.scanner interface, unmarshalling a json byte representation of a dictionary into this dictionary. (Used implicitely during SELECT)
type GetDBColumnsOption ¶
type GetDBColumnsOption func(*GetDBColumnsOpts)
func ExceptColumns ¶
func ExceptColumns(columns ...string) GetDBColumnsOption
func ExceptTagMatch ¶
func ExceptTagMatch(key, value string) GetDBColumnsOption
type GetDBColumnsOpts ¶
type GetDBColumnsOpts struct {
// contains filtered or unexported fields
}
type Opts ¶
type Opts struct {
Host string `long:"host" env:"HOST" default:"localhost" description:"Postgres host"`
Port int `long:"port" env:"PORT" default:"5432" description:"Postgres port"`
User string `long:"user" env:"USER" default:"postgres" description:"Postgres username"`
Password string `long:"password" env:"PASSWORD" default:"postgres" description:"Postgres password"`
Database string `long:"database" env:"DATABASE" default:"postgres" description:"Postgres database"`
MaxConns int `long:"maxconns" env:"MAXCONNS" default:"10" description:"Max number of connections"`
SSLMode string `long:"sslmode" env:"SSLMODE" default:"disable" description:"Postgres SSL mode"`
}
Opts is the Client config containing the host, port, user and password.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package testserver runs a lightweight Postgres server for testing.
|
Package testserver runs a lightweight Postgres server for testing. |