chain

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2018 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
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"
)
View Source
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

func As(field, alias string) string

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

func Constraint(constraint string) string

Constraint wraps the passed constraint name with the required SQL to use it.

func Equals

func Equals(field string, value ...interface{}) (string, []interface{})

Equals is a convenience function to enable use of go for where definitions

func GreaterOrEqualThan

func GreaterOrEqualThan(field string, value ...interface{}) (string, []interface{})

GreaterOrEqualThan is a convenience function to enable use of go for where definitions

func GreaterThan

func GreaterThan(field string, value ...interface{}) (string, []interface{})

GreaterThan is a convenience function to enable use of go for where definitions

func In

func In(field string, value ...interface{}) (string, []interface{})

In is a convenience function to enable use of go for where definitions

func LesserOrEqualThan

func LesserOrEqualThan(field string, value ...interface{}) (string, []interface{})

LesserOrEqualThan is a convenience function to enable use of go for where definitions

func LesserThan

func LesserThan(field string, value ...interface{}) (string, []interface{})

LesserThan is a convenience function to enable use of go for where definitions

func NotEquals

func NotEquals(field string, value ...interface{}) (string, []interface{})

NotEquals is a convenience function to enable use of go for where definitions

func NotNull added in v0.1.2

func NotNull(field string) string

NotNull is a convenience function to enable use of go for where definitions

func Null added in v0.1.2

func Null(field string) string

Null is a convenience function to enable use of go for where definitions

func SetToCurrentTimestamp added in v0.1.7

func SetToCurrentTimestamp(field string) string

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

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

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.

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group allows to group a set of expressions and run them together in a transaction.

func (*Group) Add

func (cg *Group) Add(ec *ExpresionChain)

Add appends a chain to the group.

func (*Group) Run

func (cg *Group) Run() (execError error)

Run runs all the chains in a group in a transaction, for this the db of the first query will be used.

func (*Group) Set

func (cg *Group) Set(set string)

Set will cause `SET LOCAL` to be run with this value before executing items of the group in Run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL