Documentation ¶
Index ¶
- Constants
- func As(field, alias string) string
- func Constraint(constraint string) string
- func Equals(field string, value ...interface{}) (string, []interface{})
- func GreaterOrEqualThan(field string, value ...interface{}) (string, []interface{})
- func GreaterThan(field string, value ...interface{}) (string, []interface{})
- func In(field string, value ...interface{}) (string, []interface{})
- func LesserOrEqualThan(field string, value ...interface{}) (string, []interface{})
- func LesserThan(field string, value ...interface{}) (string, []interface{})
- func NotEquals(field string, value ...interface{}) (string, []interface{})
- func NotNull(field string) string
- func Null(field string) string
- func SetToCurrentTimestamp(field string) string
- type ConflictAction
- type ExpresionChain
- func (ec *ExpresionChain) AndWhere(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) AndWhereGroup(c *ExpresionChain) *ExpresionChain
- func (ec *ExpresionChain) Clone() *ExpresionChain
- func (ec *ExpresionChain) Conflict(constraint string, action ConflictAction) *ExpresionChain
- func (ec *ExpresionChain) Delete() *ExpresionChain
- func (ec *ExpresionChain) Exec() (execError error)
- func (ec *ExpresionChain) GroupBy(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) Insert(insertPairs map[string]interface{}) *ExpresionChain
- func (ec *ExpresionChain) InsertMulti(insertPairs map[string][]interface{}) (*ExpresionChain, error)
- func (ec *ExpresionChain) Join(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) Limit(limit int64) *ExpresionChain
- func (ec *ExpresionChain) NewDB(db connection.DB) *ExpresionChain
- func (ec *ExpresionChain) Offset(offset int64) *ExpresionChain
- func (ec *ExpresionChain) OrWhere(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) OrWhereGroup(c *ExpresionChain) *ExpresionChain
- func (ec *ExpresionChain) OrderBy(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) Query() (connection.ResultFetch, error)
- func (ec *ExpresionChain) QueryIter() (connection.ResultFetchIter, error)
- func (ec *ExpresionChain) Raw(fields ...interface{}) error
- func (ec *ExpresionChain) Render() (string, []interface{}, error)
- func (ec *ExpresionChain) RenderRaw() (string, []interface{}, error)
- func (ec *ExpresionChain) Select(fields ...string) *ExpresionChain
- func (ec *ExpresionChain) Set(set string) *ExpresionChain
- func (ec *ExpresionChain) Table(table string) *ExpresionChain
- func (ec *ExpresionChain) Update(expr string, args ...interface{}) *ExpresionChain
- func (ec *ExpresionChain) UpdateMap(exprMap map[string]interface{}) *ExpresionChain
- type Group
Constants ¶
const ( // NullValue represents the NULL value in SQL NullValue = "NULL" // CurrentTimestampPGFn is the name of the function of postgres that returns current // timestamp with tz. CurrentTimestampPGFn = "CURRENT_TIMESTAMP" )
const ( // SQLNothing is the default value for an SQLBool SQLNothing sqlBool = "" // SQLAnd represents AND in SQL SQLAnd sqlBool = "AND" // SQLOr represents OR in SQL SQLOr sqlBool = "OR" // SQLNot represents NOT in SQL SQLNot sqlBool = "NOT" // SQLAndNot Negates the expresion after AND SQLAndNot sqlBool = "AND NOT" // SQLOrNot Neates the expresion after OR SQLOrNot sqlBool = "OR NOT" )
Variables ¶
This section is empty.
Functions ¶
func As ¶
As is a convenience function to define column alias in go in order to be a bit less error prone and more go semantic.
func Constraint ¶
Constraint wraps the passed constraint name with the required SQL to use it.
func GreaterOrEqualThan ¶
GreaterOrEqualThan is a convenience function to enable use of go for where definitions
func GreaterThan ¶
GreaterThan is a convenience function to enable use of go for where definitions
func LesserOrEqualThan ¶
LesserOrEqualThan is a convenience function to enable use of go for where definitions
func LesserThan ¶
LesserThan is a convenience function to enable use of go for where definitions
func NotNull ¶ added in v0.1.2
NotNull is a convenience function to enable use of go for where definitions
func Null ¶ added in v0.1.2
Null is a convenience function to enable use of go for where definitions
func SetToCurrentTimestamp ¶ added in v0.1.7
SetToCurrentTimestamp crafts a postgres SQL assignement of the field to the current timestamp with timezone.
Types ¶
type ConflictAction ¶
type ConflictAction string
ConflictAction represents a possible conflict resolution action.
const ( // ConflictActionNothing represents a nil action on conflict ConflictActionNothing ConflictAction = "NOTHING" )
type ExpresionChain ¶
type ExpresionChain struct {
// contains filtered or unexported fields
}
ExpresionChain holds all the atoms for the SQL expresions that make a query and allows to chain more assuming the chaining is valid.
func NewExpresionChain ¶
func NewExpresionChain(db connection.DB) *ExpresionChain
NewExpresionChain returns a new instance of ExpresionChain hooked to the passed DB
func Not ¶
func Not(ec *ExpresionChain) *ExpresionChain
Not replaces the chaining operation in the last segment atom by 'AND NOT' or 'OR NOT' depending on what the previous one was (either 'AND' or 'OR') as long as the last operation is a 'WHERE' segment atom.
func Or ¶
func Or(ec *ExpresionChain) *ExpresionChain
Or replaces the chaining operation in the last segment atom by 'OR' or 'OR NOT' depending on what the previous one was (either 'AND' or 'AND NOT') as long as the last operation is a 'WHERE' segment atom.
func (*ExpresionChain) AndWhere ¶
func (ec *ExpresionChain) AndWhere(expr string, args ...interface{}) *ExpresionChain
AndWhere adds a 'AND WHERE' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) AndWhereGroup ¶
func (ec *ExpresionChain) AndWhereGroup(c *ExpresionChain) *ExpresionChain
AndWhereGroup adds an AND ( a = b AND/OR c = d...) basically a group of conditions preceded by AND unless it's the first condition then just the group. It takes an expression chain as a parameter which does not need an DB or any other expresion other than WHEREs `(&ExpressionChain{}).AndWhere(...).OrWhere(...)` THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) Clone ¶
func (ec *ExpresionChain) Clone() *ExpresionChain
Clone returns a copy of the ExpresionChain
func (*ExpresionChain) Conflict ¶
func (ec *ExpresionChain) Conflict(constraint string, action ConflictAction) *ExpresionChain
Conflict will add a "ON CONFLICT" clause at the end of the query if the main operation is an INSERT. This requires a constraint or field name because I really want to be explicit when things are to be ignored.
func (*ExpresionChain) Delete ¶
func (ec *ExpresionChain) Delete() *ExpresionChain
Delete determines a deletion will be made with the results of the query.
func (*ExpresionChain) Exec ¶
func (ec *ExpresionChain) Exec() (execError error)
Exec executes the chain, works for Insert and Update
func (*ExpresionChain) GroupBy ¶
func (ec *ExpresionChain) GroupBy(expr string, args ...interface{}) *ExpresionChain
GroupBy adds a 'GROUP BY' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) Insert ¶
func (ec *ExpresionChain) Insert(insertPairs map[string]interface{}) *ExpresionChain
Insert set fields/values for insertion.
func (*ExpresionChain) InsertMulti ¶
func (ec *ExpresionChain) InsertMulti(insertPairs map[string][]interface{}) (*ExpresionChain, error)
InsertMulti set fields/values for insertion.
func (*ExpresionChain) Join ¶
func (ec *ExpresionChain) Join(expr string, args ...interface{}) *ExpresionChain
Join adds a 'JOIN' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) Limit ¶
func (ec *ExpresionChain) Limit(limit int64) *ExpresionChain
Limit adds a 'LIMIT' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) NewDB ¶
func (ec *ExpresionChain) NewDB(db connection.DB) *ExpresionChain
NewDB sets the passed db as this chain's db.
func (*ExpresionChain) Offset ¶
func (ec *ExpresionChain) Offset(offset int64) *ExpresionChain
Offset adds a 'OFFSET' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) OrWhere ¶
func (ec *ExpresionChain) OrWhere(expr string, args ...interface{}) *ExpresionChain
OrWhere adds a 'OR WHERE' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) OrWhereGroup ¶
func (ec *ExpresionChain) OrWhereGroup(c *ExpresionChain) *ExpresionChain
OrWhereGroup adds an OR ( a = b AND/OR c = d...) basically a group of conditions preceded by OR unless it's the first condition and there are no ANDs present. It takes an expression chain as a parameter which does not need an DB or any other expresion other than WHEREs `(&ExpressionChain{}).AndWhere(...).OrWhere(...)` THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) OrderBy ¶
func (ec *ExpresionChain) OrderBy(expr string, args ...interface{}) *ExpresionChain
OrderBy adds a 'ORDER BY' to the 'ExpresionChain' and returns the same chan to facilitate further chaining. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) Query ¶
func (ec *ExpresionChain) Query() (connection.ResultFetch, error)
Query is a convenience function to run the current chain through the db query with iterator.
func (*ExpresionChain) QueryIter ¶
func (ec *ExpresionChain) QueryIter() (connection.ResultFetchIter, error)
QueryIter is a convenience function to run the current chain through the db query with iterator.
func (*ExpresionChain) Raw ¶
func (ec *ExpresionChain) Raw(fields ...interface{}) error
Raw executes the query and tries to scan the result into fields without much safeguard nor intelligence so you will have to put some of your own
func (*ExpresionChain) Render ¶
func (ec *ExpresionChain) Render() (string, []interface{}, error)
Render returns the SQL expresion string and the arguments of said expresion, there is no checkig of validity or consistency for the time being.
func (*ExpresionChain) RenderRaw ¶
func (ec *ExpresionChain) RenderRaw() (string, []interface{}, error)
RenderRaw returns the SQL expresion string and the arguments of said expresion, No positional argument replacement is done.
func (*ExpresionChain) Select ¶
func (ec *ExpresionChain) Select(fields ...string) *ExpresionChain
Select set fields to be returned by the final query.
func (*ExpresionChain) Set ¶
func (ec *ExpresionChain) Set(set string) *ExpresionChain
Set will produce your chain to be run inside a Transaction and used for `SET LOCAL` For the moment this is only used with Exec.
func (*ExpresionChain) Table ¶
func (ec *ExpresionChain) Table(table string) *ExpresionChain
Table sets the table to be used in the 'FROM' expresion. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) Update ¶
func (ec *ExpresionChain) Update(expr string, args ...interface{}) *ExpresionChain
Update set fields/values for updates. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.
func (*ExpresionChain) UpdateMap ¶ added in v0.1.7
func (ec *ExpresionChain) UpdateMap(exprMap map[string]interface{}) *ExpresionChain
UpdateMap set fields/values for updates but does so from a map of key/value. THIS DOES NOT CREATE A COPY OF THE CHAIN, IT MUTATES IN PLACE.