Documentation ¶
Index ¶
- Variables
- func JSONScan(destination interface{}, value interface{}) error
- func JSONValue(value interface{}) (driver.Value, error)
- func WitLogger(ctx context.Context, logger Logger) context.Context
- func WitTx(ctx context.Context, tx *Tx) context.Context
- type Builder
- type DB
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
- func (db *DB) Delete(ctx context.Context) *DeleteQuery
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) Insert(ctx context.Context) *InsertQuery
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) Select(ctx context.Context) *SelectQuery
- func (db *DB) Update(ctx context.Context) *UpdateQuery
- type DeleteQuery
- type InsertQuery
- func (q *InsertQuery) Build(buf *bytes.Buffer) error
- func (q *InsertQuery) Columns(columns ...string) *InsertQuery
- func (q *InsertQuery) Exec() (sql.Result, error)
- func (q *InsertQuery) InTo(table string) *InsertQuery
- func (q *InsertQuery) OnConflict(column string, sets string) *InsertQuery
- func (q *InsertQuery) OrIgnore() *InsertQuery
- func (q *InsertQuery) Params() []interface{}
- func (q *InsertQuery) Record(structValue interface{})
- func (q *InsertQuery) Returning(returning ...string) *InsertQuery
- func (q *InsertQuery) Values(values ...interface{}) *InsertQuery
- type Logger
- type NullInt64
- type NullString
- type NullTime
- type SelectQuery
- func (q *SelectQuery) Build(buf *bytes.Buffer) error
- func (q *SelectQuery) Columns(columns ...string) *SelectQuery
- func (q *SelectQuery) From(table string) *SelectQuery
- func (q *SelectQuery) GroupBy(column string) *SelectQuery
- func (q *SelectQuery) Join(join string, params ...interface{}) *SelectQuery
- func (q *SelectQuery) Limit(limit int) *SelectQuery
- func (q *SelectQuery) Load(value interface{}) (int, error)
- func (q *SelectQuery) LoadValue(value interface{}) error
- func (q *SelectQuery) Offset(offset int) *SelectQuery
- func (q *SelectQuery) OrderBy(column string, direction string) *SelectQuery
- func (q *SelectQuery) Params() []interface{}
- func (q *SelectQuery) Where(condition string, params ...interface{}) *SelectQuery
- type Tx
- func (tx *Tx) Delete(ctx context.Context) *DeleteQuery
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Tx) Insert(ctx context.Context) *InsertQuery
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (tx *Tx) Select(ctx context.Context) *SelectQuery
- func (tx *Tx) Update(ctx context.Context) *UpdateQuery
- type UpdateQuery
- func (q *UpdateQuery) Build(buf *bytes.Buffer) error
- func (q *UpdateQuery) Exec() (sql.Result, error)
- func (q *UpdateQuery) Params() []interface{}
- func (q *UpdateQuery) Returning(returning ...string) *UpdateQuery
- func (q *UpdateQuery) Set(column string, values ...interface{}) *UpdateQuery
- func (q *UpdateQuery) Table(table string) *UpdateQuery
- func (q *UpdateQuery) Where(condition string, params ...interface{}) *UpdateQuery
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPointer indicates that you passed an invalid pointer into a function ErrInvalidPointer = errors.New("qb: attempt to load into an invalid pointer") )
Functions ¶
func JSONScan ¶
func JSONScan(destination interface{}, value interface{}) error
JSONScan is a convenient function to implement the Scanner interface for json columns
func JSONValue ¶
JSONValue is a convenient function to implement the Valuer interface for json columns
Types ¶
type DB ¶
DB represents the database
func (*DB) BeginTx ¶
BeginTx starts a transaction. The default isolation level is dependent on the driver
func (*DB) Delete ¶
func (db *DB) Delete(ctx context.Context) *DeleteQuery
Delete creates and returns a new instance of DeleteQuery for the specified table
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query
func (*DB) Insert ¶
func (db *DB) Insert(ctx context.Context) *InsertQuery
Insert creates and returns a new instance of InsertQuery for the specified table
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
type DeleteQuery ¶
type DeleteQuery struct {
// contains filtered or unexported fields
}
DeleteQuery represents a DELETE sql query
func (*DeleteQuery) Build ¶
func (q *DeleteQuery) Build(buf *bytes.Buffer) error
Build renders the DELETE query as a string
func (*DeleteQuery) From ¶
func (q *DeleteQuery) From(table string) *DeleteQuery
From is used to set the table to delete from
func (*DeleteQuery) Params ¶
func (q *DeleteQuery) Params() []interface{}
Params returns the parameters for this query
func (*DeleteQuery) Where ¶
func (q *DeleteQuery) Where(condition string, params ...interface{}) *DeleteQuery
Where adds a where clause to the select query using *AND* strategy
type InsertQuery ¶
type InsertQuery struct {
// contains filtered or unexported fields
}
InsertQuery represents a INSERT sql query
func (*InsertQuery) Build ¶
func (q *InsertQuery) Build(buf *bytes.Buffer) error
Build renders the INSERT query as a string
func (*InsertQuery) Columns ¶
func (q *InsertQuery) Columns(columns ...string) *InsertQuery
Columns determines the columns to insert
func (*InsertQuery) InTo ¶
func (q *InsertQuery) InTo(table string) *InsertQuery
InTo is used to set the table to insert into
func (*InsertQuery) OnConflict ¶
func (q *InsertQuery) OnConflict(column string, sets string) *InsertQuery
OnConflict specifies what to do if there is conflict
func (*InsertQuery) OrIgnore ¶
func (q *InsertQuery) OrIgnore() *InsertQuery
OrIgnore make the query behave using INSERT OR IGNORE INTO
func (*InsertQuery) Params ¶
func (q *InsertQuery) Params() []interface{}
Params returns all parameters for the query
func (*InsertQuery) Record ¶
func (q *InsertQuery) Record(structValue interface{})
Record scans the result of the query into the given struct
func (*InsertQuery) Returning ¶
func (q *InsertQuery) Returning(returning ...string) *InsertQuery
Returning specifies with columns to return after the INSERT is successful
func (*InsertQuery) Values ¶
func (q *InsertQuery) Values(values ...interface{}) *InsertQuery
Values determines the columns to insert
type NullInt64 ¶
NullInt64 is a wrapper around sql.NullInt64 that plays nice with JSON
func (NullInt64) MarshalJSON ¶
MarshalJSON serializes a NullInt64 to JSON
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON deserializes a NullInt64 from JSON
type NullString ¶
type NullString struct {
sql.NullString
}
NullString is a wrapper around sql.NullString that plays nice with JSON
func (NullString) MarshalJSON ¶
func (n NullString) MarshalJSON() ([]byte, error)
MarshalJSON serializes a NullString to JSON
func (*NullString) UnmarshalJSON ¶
func (n *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON deserializes a NullString from JSON
type NullTime ¶
NullTime is a wrapper around time.Time that plays nice with SQL and JSON
func (NullTime) MarshalJSON ¶
MarshalJSON serializes a NullTime to JSON
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON deserializes a NullTime from JSON
type SelectQuery ¶
type SelectQuery struct {
// contains filtered or unexported fields
}
SelectQuery represents a SELECT sql query
func (*SelectQuery) Build ¶
func (q *SelectQuery) Build(buf *bytes.Buffer) error
Build renders the SELECT query as a string
func (*SelectQuery) Columns ¶
func (q *SelectQuery) Columns(columns ...string) *SelectQuery
Columns determines with columns to select
func (*SelectQuery) From ¶
func (q *SelectQuery) From(table string) *SelectQuery
From is used to set the table to select from
func (*SelectQuery) GroupBy ¶
func (q *SelectQuery) GroupBy(column string) *SelectQuery
GroupBy adds a GROUP BY clause to the SELECT query
func (*SelectQuery) Join ¶
func (q *SelectQuery) Join(join string, params ...interface{}) *SelectQuery
Join adds a join to the select query
func (*SelectQuery) Limit ¶
func (q *SelectQuery) Limit(limit int) *SelectQuery
Limit adds a LIMIT clause to the SELECT query
func (*SelectQuery) Load ¶
func (q *SelectQuery) Load(value interface{}) (int, error)
Load will execute the query and scan the result into the given struct
func (*SelectQuery) LoadValue ¶
func (q *SelectQuery) LoadValue(value interface{}) error
LoadValue will execute the query and scan the scalar result into the given variable
func (*SelectQuery) Offset ¶
func (q *SelectQuery) Offset(offset int) *SelectQuery
Offset adds a OFFSET clause to the SELECT query
func (*SelectQuery) OrderBy ¶
func (q *SelectQuery) OrderBy(column string, direction string) *SelectQuery
OrderBy adds an ORDER BY clause to the SELECT query
func (*SelectQuery) Params ¶
func (q *SelectQuery) Params() []interface{}
Params returns the parameters for this query
func (*SelectQuery) Where ¶
func (q *SelectQuery) Where(condition string, params ...interface{}) *SelectQuery
Where adds a where clause to the select query using *AND* strategy
type Tx ¶
Tx represents a transaction in a database
func (*Tx) Delete ¶
func (tx *Tx) Delete(ctx context.Context) *DeleteQuery
Delete creates and returns a new instance of DeleteQuery for the specified table
func (*Tx) ExecContext ¶
func (tx *Tx) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query
func (*Tx) Insert ¶
func (tx *Tx) Insert(ctx context.Context) *InsertQuery
Insert creates and returns a new instance of InsertQuery for the specified table
func (*Tx) QueryContext ¶
func (tx *Tx) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
type UpdateQuery ¶
type UpdateQuery struct {
// contains filtered or unexported fields
}
UpdateQuery represents a UPDATE sql query
func (*UpdateQuery) Build ¶
func (q *UpdateQuery) Build(buf *bytes.Buffer) error
Build renders the UPDATE query as a string
func (*UpdateQuery) Params ¶
func (q *UpdateQuery) Params() []interface{}
Params returns all parameters for the query
func (*UpdateQuery) Returning ¶
func (q *UpdateQuery) Returning(returning ...string) *UpdateQuery
Returning specifies with columns to return after the UPDATE is successful
func (*UpdateQuery) Set ¶
func (q *UpdateQuery) Set(column string, values ...interface{}) *UpdateQuery
Set adds a column = value statement to the UPDATE querie's SET clause
func (*UpdateQuery) Table ¶
func (q *UpdateQuery) Table(table string) *UpdateQuery
Table is used to set the table to update from
func (*UpdateQuery) Where ¶
func (q *UpdateQuery) Where(condition string, params ...interface{}) *UpdateQuery
Where adds a where clause to the update query using *AND* strategy