Documentation ¶
Index ¶
- Variables
- func Delete(ctx context.Context, c QueryClient, v Model) (int64, error)
- func DeleteReturning(ctx context.Context, c QueryClient, v Model) error
- func Insert(ctx context.Context, c QueryClient, v Model, cols ...string) error
- func InsertReturning(ctx context.Context, c QueryClient, v Model, cols ...string) error
- func Quote(str string) string
- func RawSelect(ctx context.Context, c QueryClient, outSlicePtr interface{}, q string, ...) error
- func Save(ctx context.Context, c QueryClient, v Model, cols ...string) error
- func Update(ctx context.Context, c QueryClient, v Model, cols ...string) error
- func UpdateReturning(ctx context.Context, c QueryClient, v Model, cols ...string) error
- type Attrs
- type BulkInserter
- type BulkProvider
- type ChannelModelProvider
- type Client
- func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (c *Client) BulkInsert(p BulkProvider) error
- func (c *Client) BulkInserter() BulkInserter
- func (c *Client) Delete(ctx context.Context, v Model) (int64, error)
- func (c *Client) DeleteAll(table string) *Query
- func (c *Client) DeleteReturning(ctx context.Context, v Model) error
- func (c *Client) Insert(ctx context.Context, v Model, cols ...string) error
- func (c *Client) InsertReturning(ctx context.Context, v Model, cols ...string) error
- func (c *Client) MonitorBulkInsertChannel(ch chan Model, errFunc ModelErrorFunc) error
- func (c *Client) Name() string
- func (c *Client) RawQuery(ctx context.Context, q string, args ...interface{}) (*QueryResult, error)
- func (c *Client) RawSelect(ctx context.Context, outSlicePtr interface{}, q string, args ...interface{}) error
- func (c *Client) RunInTransaction(ctx context.Context, f func(context.Context, *Tx) error, opts *sql.TxOptions) error
- func (c *Client) Save(ctx context.Context, v Model, cols ...string) error
- func (c *Client) Select(tableName string, cols ...string) *Query
- func (c *Client) Start(driverName string) error
- func (c *Client) Started() bool
- func (c *Client) Status(ctx context.Context) error
- func (c *Client) Stop() error
- func (c *Client) Update(ctx context.Context, v Model, cols ...string) error
- func (c *Client) UpdateAll(table string, attrs Attrs) *Query
- func (c *Client) UpdateReturning(ctx context.Context, v Model, cols ...string) error
- type Config
- type EncryptableString
- type Inter
- type JSONObject
- func (o JSONObject) Bool(key string) (bool, error)
- func (o JSONObject) Float64(key string) (float64, error)
- func (o JSONObject) Int(key string) (int, error)
- func (o JSONObject) Int64(key string) (int64, error)
- func (o JSONObject) Object(key string) (JSONObject, error)
- func (o *JSONObject) Scan(src interface{}) error
- func (o JSONObject) Slice(key string) ([]interface{}, error)
- func (o JSONObject) String(key string) (string, error)
- func (o JSONObject) Value() (driver.Value, error)
- type Model
- type ModelErrorFunc
- type ModelHelper
- type NullBool
- type NullFloat64
- type NullInt64
- type NullString
- type NullTime
- type Nullable
- type Query
- func DeleteAll(c QueryClient, table string) *Query
- func DeleteQuery(c QueryClient, tableName string) *Query
- func InsertQuery(c QueryClient, tableName string, attrs map[string]interface{}) *Query
- func Select(c QueryClient, tableName string, cols ...string) *Query
- func SelectQuery(c QueryClient, tableName string, cols ...string) *Query
- func SubQuery() *Query
- func UpdateAll(c QueryClient, table string, attrs Attrs) *Query
- func UpdateQuery(c QueryClient, tableName string, attrs map[string]interface{}) *Query
- func (q *Query) And(and *Query) *Query
- func (q *Query) Exec(ctx context.Context) (*QueryResult, error)
- func (q *Query) Limit(i int) *Query
- func (q *Query) Or(or *Query) *Query
- func (q *Query) OrderBy(bys ...string) *Query
- func (q *Query) Returning(cols ...string) *Query
- func (q *Query) Scan(ctx context.Context, ptr interface{}) error
- func (q *Query) Slice(ctx context.Context, outSlicePtr interface{}) error
- func (q *Query) Where(attrs map[string]interface{}) *Query
- func (q *Query) WhereNot(attrs map[string]interface{}) *Query
- func (q *Query) WhereRaw(raw string, vals ...interface{}) *Query
- type QueryClient
- type QueryResult
- type Range
- type SliceModelProvider
- type StringsBuilder
- type Tx
- func (tx *Tx) Delete(ctx context.Context, v Model) (int64, error)
- func (tx *Tx) DeleteAll(table string) *Query
- func (tx *Tx) DeleteReturning(ctx context.Context, v Model) error
- func (tx *Tx) Insert(ctx context.Context, v Model, cols ...string) error
- func (tx *Tx) InsertReturning(ctx context.Context, v Model, cols ...string) error
- func (tx *Tx) RawQuery(ctx context.Context, q string, args ...interface{}) (*QueryResult, error)
- func (tx *Tx) RawSelect(ctx context.Context, outSlicePtr interface{}, q string, args ...interface{}) error
- func (tx *Tx) Save(ctx context.Context, v Model, cols ...string) error
- func (tx *Tx) Select(tableName string, cols ...string) *Query
- func (tx *Tx) Started() bool
- func (tx *Tx) Update(ctx context.Context, v Model, cols ...string) error
- func (tx *Tx) UpdateAll(table string, attrs Attrs) *Query
- func (tx *Tx) UpdateReturning(ctx context.Context, v Model, cols ...string) error
Constants ¶
This section is empty.
Variables ¶
var ( NonceByteSize = 12 // standard nonce size for GCM cipher EncryptionKey string // must be 128, 192 or 256 bit, blank disables encryption DecryptionErrorFunc func(interface{}, error) error // You can log or take other actions. The error returned will be returned from Scan function )
var (
ErrNil = errors.New("value is nil")
)
var ErrNilValue = errors.New("value is nil")
var (
ErrNoRows = sql.ErrNoRows
)
Functions ¶
func DeleteReturning ¶
func DeleteReturning(ctx context.Context, c QueryClient, v Model) error
func InsertReturning ¶
func RawSelect ¶
func RawSelect(ctx context.Context, c QueryClient, outSlicePtr interface{}, q string, args ...interface{}) error
func UpdateReturning ¶
Types ¶
type BulkInserter ¶
type BulkInserter struct {
// contains filtered or unexported fields
}
func (BulkInserter) BulkInsert ¶
func (bi BulkInserter) BulkInsert(p BulkProvider) error
Unlike the other Client funcs this executes immediately and does not return a Query that you Exec() on
func (BulkInserter) WithModelErrFunc ¶
func (bi BulkInserter) WithModelErrFunc(errFunc ModelErrorFunc) BulkInserter
type BulkProvider ¶
Make sure all Models are the same type
type ChannelModelProvider ¶
type ChannelModelProvider struct { Channel <-chan Model // contains filtered or unexported fields }
Bulk provider for channels, see '*Client MonitorBulkInsertChannel()' for usage example
func NewChannelModelProvider ¶
func NewChannelModelProvider(m Model, ch <-chan Model) *ChannelModelProvider
func (*ChannelModelProvider) Cap ¶
func (p *ChannelModelProvider) Cap() int
func (*ChannelModelProvider) NextModel ¶
func (p *ChannelModelProvider) NextModel() Model
type Client ¶
Client is a helper type to easily connect to PostgreSQL database instances.
It satisfies the `health.Metric` interface.
func (*Client) BulkInsert ¶
func (c *Client) BulkInsert(p BulkProvider) error
func (*Client) BulkInserter ¶
func (c *Client) BulkInserter() BulkInserter
func (*Client) DeleteReturning ¶
func (*Client) InsertReturning ¶
func (*Client) MonitorBulkInsertChannel ¶
func (c *Client) MonitorBulkInsertChannel(ch chan Model, errFunc ModelErrorFunc) error
func (*Client) Name ¶
Name returns `"psql"`.
To better identify the `Client` may be wrapped in a prefixed metric:
health.PrefixedMetric{Prefix: "MyDatabaseName", BaseMetric: c}
func (*Client) RunInTransaction ¶
type EncryptableString ¶
type EncryptableString struct {
NullString
}
EncryptableString is a struct containing a string that can be stored as an encrypted string in the database. It extends NullString so the value can be null. In memory the string will be in plain text. In the DB it is stored as a hex string where the first 8 bytes represent an integer which is the byte size of the nonce, The next nonce size bytes are the nonce and the rest of the bytes are the encrypted data
func NewEncryptableString ¶
func NewEncryptableString(s string) EncryptableString
func (*EncryptableString) Scan ¶
func (s *EncryptableString) Scan(value interface{}) error
Scan implements the Scanner interface. (converts from DB)
type JSONObject ¶
type JSONObject map[string]interface{}
func (JSONObject) Object ¶
func (o JSONObject) Object(key string) (JSONObject, error)
func (*JSONObject) Scan ¶
func (o *JSONObject) Scan(src interface{}) error
func (JSONObject) Slice ¶
func (o JSONObject) Slice(key string) ([]interface{}, error)
type ModelErrorFunc ¶
type ModelHelper ¶
type ModelHelper struct {
Model Model
}
func (ModelHelper) Attributes ¶
func (h ModelHelper) Attributes(only ...string) map[string]interface{}
Returns a map of the attributes of the struct excluding id
func (ModelHelper) ID ¶
func (h ModelHelper) ID() (int64, error)
func (ModelHelper) SetID ¶
func (h ModelHelper) SetID(id int64) error
type NullBool ¶
NullBool is an alias for sql.NullBool data type
func InvalidNullBool ¶
func InvalidNullBool() NullBool
NullBool convenience initializer for invalid (nil)
func (NullBool) MarshalJSON ¶
MarshalJSON for NullBool
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON for NullBool
type NullFloat64 ¶
type NullFloat64 struct {
sql.NullFloat64
}
NullFloat64 is an alias for sql.NullFloat64 data type
func InvalidNullFloat64 ¶
func InvalidNullFloat64() NullFloat64
NullFloat64 convenience initializer for invalid (nil)
func NewNullFloat64 ¶
func NewNullFloat64(f float64) NullFloat64
NullFloat64 convenience initializer
func (NullFloat64) MarshalJSON ¶
func (n NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON for NullFloat64
func (*NullFloat64) UnmarshalJSON ¶
func (n *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON for NullFloat64
type NullInt64 ¶
NullInt64 is an alias for sql.NullInt64 data type
func InvalidNullInt64 ¶
func InvalidNullInt64() NullInt64
NullInt64 convenience initializer for invalid (nil)
func (NullInt64) MarshalJSON ¶
MarshalJSON for NullInt64
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON for NullInt64
type NullString ¶
type NullString struct {
sql.NullString
}
NullString is an alias for sql.NullString data type
func InvalidNullString ¶
func InvalidNullString() NullString
NullString convenience initializer for invalid (nil)
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
MarshalJSON for NullString
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON for NullString
type NullTime ¶
NullTime is an alias for mysql.NullTime data type
func InvalidNullTime ¶
func InvalidNullTime() NullTime
NullTime convenience initializer for invalid (nil)
func (NullTime) MarshalJSON ¶
MarshalJSON for NullTime
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON for NullTime
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func DeleteAll ¶
func DeleteAll(c QueryClient, table string) *Query
func DeleteQuery ¶
func DeleteQuery(c QueryClient, tableName string) *Query
func InsertQuery ¶
func InsertQuery(c QueryClient, tableName string, attrs map[string]interface{}) *Query
func SelectQuery ¶
func SelectQuery(c QueryClient, tableName string, cols ...string) *Query
func UpdateQuery ¶
func UpdateQuery(c QueryClient, tableName string, attrs map[string]interface{}) *Query
func (*Query) Exec ¶
func (q *Query) Exec(ctx context.Context) (*QueryResult, error)
Exec() executes the query either with db.Exec() (RowsAffected) or db.Query() (Rows) depending on the query
Select returns Rows ¶
Insert returns the Rows which represents the id of the inserted record by default ¶
Delete and Update return RowsAffected unless the Returning() function is called on the query, then it returns Rows
type QueryClient ¶
type QueryResult ¶
func RawQuery ¶
func RawQuery(ctx context.Context, c QueryClient, q string, args ...interface{}) (*QueryResult, error)
type SliceModelProvider ¶
type SliceModelProvider struct {
// contains filtered or unexported fields
}
Bulk provider for slices of Models
func NewSliceModelProvider ¶
func NewSliceModelProvider(arr []Model) *SliceModelProvider
func (*SliceModelProvider) Cap ¶
func (p *SliceModelProvider) Cap() int
func (*SliceModelProvider) NextModel ¶
func (p *SliceModelProvider) NextModel() Model
type StringsBuilder ¶
func (*StringsBuilder) WriteStrings ¶
func (b *StringsBuilder) WriteStrings(strs ...string)