Documentation ¶
Index ¶
- Constants
- Variables
- func ConcatQuery(c *Context, values ...interface{}) string
- func GetFuncFrame() string
- func JoinQuery(c *Context, sep string, values []interface{}) string
- type Alias
- type CTE
- type Condition
- type Context
- type DataType
- type DeleteBuilder
- type Driver
- type Field
- type FieldOrder
- type InsertBuilder
- type Join
- type OverrideMap
- type Query
- type ReturningBuilder
- type SQL
- type SQLBuilder
- func (b *SQLBuilder) Conditions(c []Condition, newline bool)
- func (b *SQLBuilder) Delete(t *Table)
- func (b *SQLBuilder) FieldToSQL(f Field) string
- func (b *SQLBuilder) From(src Source)
- func (b *SQLBuilder) GroupBy(f ...Field)
- func (b *SQLBuilder) Having(c ...Condition)
- func (b *SQLBuilder) Insert(t *Table, f []Field)
- func (b *SQLBuilder) Join(j ...join)
- func (b *SQLBuilder) LimitOffset(l, o int)
- func (b *SQLBuilder) List(f []Field, withAlias bool) string
- func (b *SQLBuilder) OrderBy(o ...FieldOrder)
- func (b *SQLBuilder) Select(withAlias bool, f ...Field)
- func (b *SQLBuilder) Set(sets []set)
- func (b *SQLBuilder) SourceToSQL(s Source) string
- func (b *SQLBuilder) Update(t *Table)
- func (b *SQLBuilder) Values(f [][]Field)
- func (b *SQLBuilder) Where(c ...Condition)
- type SelectBuilder
- func (q *SelectBuilder) CTE(fields ...*Field) *CTE
- func (q *SelectBuilder) CrossJoin(s Source) *SelectBuilder
- func (q *SelectBuilder) Fields() []Field
- func (q *SelectBuilder) GroupBy(f ...Field) *SelectBuilder
- func (q *SelectBuilder) Having(c ...Condition) *SelectBuilder
- func (q *SelectBuilder) InnerJoin(f1, f2 Field, c ...Condition) *SelectBuilder
- func (q *SelectBuilder) LeftJoin(f1, f2 Field, c ...Condition) *SelectBuilder
- func (q *SelectBuilder) Limit(i int) *SelectBuilder
- func (q *SelectBuilder) ManualJoin(t Join, s Source, c ...Condition) *SelectBuilder
- func (q *SelectBuilder) Offset(i int) *SelectBuilder
- func (q *SelectBuilder) OrderBy(o ...FieldOrder) *SelectBuilder
- func (q *SelectBuilder) RightJoin(f1, f2 Field, c ...Condition) *SelectBuilder
- func (q *SelectBuilder) SQL(b SQLBuilder) (string, []interface{})
- func (q *SelectBuilder) SubQuery(fields ...*Field) *SubQuery
- func (q *SelectBuilder) Where(c ...Condition) *SelectBuilder
- type SelectQuery
- func Except(q1, q2 SelectQuery) SelectQuery
- func ExceptAll(q1, q2 SelectQuery) SelectQuery
- func Intersect(q1, q2 SelectQuery) SelectQuery
- func IntersectAll(q1, q2 SelectQuery) SelectQuery
- func Returning(q Query, f ...Field) SelectQuery
- func Union(q ...SelectQuery) SelectQuery
- func UnionAll(q ...SelectQuery) SelectQuery
- type Source
- type SubQuery
- type Table
- type TableField
- type UpdateBuilder
Constants ¶
const ( Int = iota + 1 String Bool Float Date Time )
All defined DataTypes
Variables ¶
var ( COMMA = `, ` NEWLINE = "\n" INDENT = "\t" VALUE = `?` )
Values used when building queries
Functions ¶
func ConcatQuery ¶
ConcatQuery combines strings and Fields into string. This function is not intended to be called directly
Types ¶
type Alias ¶
Alias generates table aliasses. This type is not intended to be used directly
func AliasGenerator ¶
func AliasGenerator() Alias
AliasGenerator returns an incrementing alias for each new Source. This function is not intended to be called directly
type CTE ¶
type CTE struct { F []Field // contains filtered or unexported fields }
CTE is a type of subqueries
func (*CTE) TableString ¶
TableString implements Source
func (*CTE) With ¶
func (cte *CTE) With(b SQLBuilder) string
With generates the SQL for a WITH statement. This function is not intended to be called directly
type Context ¶
type Context struct { Driver Driver Values *[]interface{} CTEs *[]*CTE // contains filtered or unexported fields }
Context contains all the data needed to build parts of a query. This type is not intended to be used directly
type DeleteBuilder ¶
type DeleteBuilder struct {
// contains filtered or unexported fields
}
DeleteBuilder builds a DELETE query
func (DeleteBuilder) SQL ¶
func (q DeleteBuilder) SQL(b SQLBuilder) (string, []interface{})
SQL returns a query string and a list of values
type Driver ¶
type Driver interface { ValueString(int) string BoolString(bool) string UpsertSQL(*Table, []Field, Query) (string, []interface{}) LimitOffset(SQL, int, int) Returning(SQLBuilder, Query, []Field) (string, []interface{}) TypeName(DataType) string Override() OverrideMap }
Driver implements databse-specific features
type Field ¶
Field represents a field in a query
type FieldOrder ¶
FieldOrder specifies the order in which fields should be sorted
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
InsertBuilder builds an INSERT query
func (*InsertBuilder) SQL ¶
func (q *InsertBuilder) SQL(b SQLBuilder) (string, []interface{})
SQL returns a query string and a list of values
func (*InsertBuilder) Upsert ¶
func (q *InsertBuilder) Upsert(query Query, conflict ...Field) *InsertBuilder
Upsert turns the INSERT query into an upsert query, only usable if your driver supports it
func (*InsertBuilder) Values ¶
func (q *InsertBuilder) Values(values ...interface{}) *InsertBuilder
Values adds values to the query
type OverrideMap ¶
type OverrideMap map[string]interface{}
OverrideMap allows a driver to override functions from qf and qc. This type is not intended to be used directly
func (OverrideMap) Add ¶
func (m OverrideMap) Add(target, new interface{})
Add adds an override to the map
func (OverrideMap) Condition ¶
func (m OverrideMap) Condition(source string, fallback interface{}, in []interface{}) Condition
Condition gets an override for qc, if there is no entry in the map fallback will be used
func (OverrideMap) Field ¶
func (m OverrideMap) Field(source string, fallback interface{}, in []interface{}) Field
Field gets an override for qf, if there is no entry in the map fallback will be used
type ReturningBuilder ¶
type ReturningBuilder struct { Query Query // contains filtered or unexported fields }
ReturningBuilder builds a query with a RETURNING statement
func (ReturningBuilder) CTE ¶
func (q ReturningBuilder) CTE(fields ...*Field) *CTE
CTE creates a new CTE (WITH) Query
func (ReturningBuilder) Fields ¶
func (q ReturningBuilder) Fields() []Field
Fields returns a list of the fields used in the query
func (ReturningBuilder) SQL ¶
func (q ReturningBuilder) SQL(b SQLBuilder) (string, []interface{})
SQL returns a query string and a list of values
func (ReturningBuilder) SubQuery ¶
func (q ReturningBuilder) SubQuery(fields ...*Field) *SubQuery
SubQuery converts the SelectQuery to a SubQuery for use in further queries
type SQLBuilder ¶
type SQLBuilder struct { Context *Context // contains filtered or unexported fields }
SQLBuilder contains data and methods to generate SQL. This type is not intended to be used directly
func (*SQLBuilder) Conditions ¶
func (b *SQLBuilder) Conditions(c []Condition, newline bool)
Conditions generates valid SQL for the given list of conditions
func (*SQLBuilder) Delete ¶
func (b *SQLBuilder) Delete(t *Table)
Delete generates a SQL DELETE FROM line
func (*SQLBuilder) FieldToSQL ¶
func (b *SQLBuilder) FieldToSQL(f Field) string
FieldToSQL converts a Field to a string
func (*SQLBuilder) GroupBy ¶
func (b *SQLBuilder) GroupBy(f ...Field)
GroupBy generates a SQL GROUP BY line
func (*SQLBuilder) Having ¶
func (b *SQLBuilder) Having(c ...Condition)
Having generates a SQL HAVING line
func (*SQLBuilder) Insert ¶
func (b *SQLBuilder) Insert(t *Table, f []Field)
Insert generates a SQL INSERT line
func (*SQLBuilder) LimitOffset ¶
func (b *SQLBuilder) LimitOffset(l, o int)
LimitOffset generates a SQL LIMIT and OFFSET line
func (*SQLBuilder) List ¶
func (b *SQLBuilder) List(f []Field, withAlias bool) string
List lists the given fields
func (*SQLBuilder) OrderBy ¶
func (b *SQLBuilder) OrderBy(o ...FieldOrder)
OrderBy generates a SQL ORDER BY line
func (*SQLBuilder) Select ¶
func (b *SQLBuilder) Select(withAlias bool, f ...Field)
Select generates a SQL SELECT line
func (*SQLBuilder) SourceToSQL ¶
func (b *SQLBuilder) SourceToSQL(s Source) string
SourceToSQL converts a Source to a string
func (*SQLBuilder) Update ¶
func (b *SQLBuilder) Update(t *Table)
Update generates a SQL UPDATE line
func (*SQLBuilder) Values ¶
func (b *SQLBuilder) Values(f [][]Field)
Values generates a SQL VALUES line
func (*SQLBuilder) Where ¶
func (b *SQLBuilder) Where(c ...Condition)
Where generates SQL WHERE/AND lines
type SelectBuilder ¶
type SelectBuilder struct {
// contains filtered or unexported fields
}
SelectBuilder builds a SELECT query
func NewSelectBuilder ¶
func NewSelectBuilder(f []Field, src Source) *SelectBuilder
NewSelectBuilder retruns a new SelectBuilder
func (*SelectBuilder) CTE ¶
func (q *SelectBuilder) CTE(fields ...*Field) *CTE
CTE creates a new CTE (WITH) Query
func (*SelectBuilder) CrossJoin ¶
func (q *SelectBuilder) CrossJoin(s Source) *SelectBuilder
CrossJoin adds a CROSS JOIN clause to the query
func (*SelectBuilder) Fields ¶
func (q *SelectBuilder) Fields() []Field
Fields returns a list of the fields used in the query
func (*SelectBuilder) GroupBy ¶
func (q *SelectBuilder) GroupBy(f ...Field) *SelectBuilder
GroupBy adds a GROUP BY clause to the query
func (*SelectBuilder) Having ¶
func (q *SelectBuilder) Having(c ...Condition) *SelectBuilder
Having adds a HAVING clause to the query
func (*SelectBuilder) InnerJoin ¶
func (q *SelectBuilder) InnerJoin(f1, f2 Field, c ...Condition) *SelectBuilder
InnerJoin adds an INNER JOIN clause to the query
func (*SelectBuilder) LeftJoin ¶
func (q *SelectBuilder) LeftJoin(f1, f2 Field, c ...Condition) *SelectBuilder
LeftJoin adds a LEFT JOIN clause to the query
func (*SelectBuilder) Limit ¶
func (q *SelectBuilder) Limit(i int) *SelectBuilder
Limit adds a LIMIT clause to the query
func (*SelectBuilder) ManualJoin ¶
func (q *SelectBuilder) ManualJoin(t Join, s Source, c ...Condition) *SelectBuilder
ManualJoin manually joins a table Only use this if you know what you are doing
func (*SelectBuilder) Offset ¶
func (q *SelectBuilder) Offset(i int) *SelectBuilder
Offset adds a OFFSET clause to the query
func (*SelectBuilder) OrderBy ¶
func (q *SelectBuilder) OrderBy(o ...FieldOrder) *SelectBuilder
OrderBy adds a ORDER BY clause to the query
func (*SelectBuilder) RightJoin ¶
func (q *SelectBuilder) RightJoin(f1, f2 Field, c ...Condition) *SelectBuilder
RightJoin adds a RIGHT JOIN clause to the query
func (*SelectBuilder) SQL ¶
func (q *SelectBuilder) SQL(b SQLBuilder) (string, []interface{})
SQL returns a query string and a list of values
func (*SelectBuilder) SubQuery ¶
func (q *SelectBuilder) SubQuery(fields ...*Field) *SubQuery
SubQuery converts the SelectQuery to a SubQuery for use in further queries
func (*SelectBuilder) Where ¶
func (q *SelectBuilder) Where(c ...Condition) *SelectBuilder
Where adds conditions to the WHERE clause
type SelectQuery ¶
type SelectQuery interface { Query SubQuery(...*Field) *SubQuery CTE(...*Field) *CTE Fields() []Field // contains filtered or unexported methods }
SelectQuery represents a query that returns data
func ExceptAll ¶
func ExceptAll(q1, q2 SelectQuery) SelectQuery
ExceptAll combines queries with an EXCEPT ALL
func Intersect ¶
func Intersect(q1, q2 SelectQuery) SelectQuery
Intersect combines queries with an INTERSECT
func IntersectAll ¶
func IntersectAll(q1, q2 SelectQuery) SelectQuery
IntersectAll combines queries with an INTERSECT ALL
func Returning ¶
func Returning(q Query, f ...Field) SelectQuery
Returning creates a RETURNING or OUTPUT query
func UnionAll ¶
func UnionAll(q ...SelectQuery) SelectQuery
UnionAll combines queries with an UNION ALL
type SubQuery ¶
type SubQuery struct { F []Field // contains filtered or unexported fields }
SubQuery represents a subquery
func (*SubQuery) Select ¶
func (t *SubQuery) Select(f ...Field) *SelectBuilder
Select starts a SELECT query
func (*SubQuery) TableString ¶
TableString implements Source
type Table ¶
Table represents a table in the database. This type is used by qb-generator's generated code and is not intended to be used manually
func (*Table) Insert ¶
func (t *Table) Insert(f []Field) *InsertBuilder
Insert starts an INSERT query
func (*Table) Select ¶
func (t *Table) Select(f []Field) *SelectBuilder
Select starts a SELECT query
func (*Table) TableString ¶
TableString implements Source
type TableField ¶
type TableField struct { Parent Source Name string ReadOnly bool Nullable bool Type DataType Size int }
TableField represents a field in a table. This type is used by qb-generator's generated code and is not intended to be used manually
func (TableField) Copy ¶
func (f TableField) Copy(src Source) *TableField
Copy creates a new instance of the field with a different Parent
func (TableField) QueryString ¶
func (f TableField) QueryString(c *Context) string
QueryString implements Field
type UpdateBuilder ¶
type UpdateBuilder struct {
// contains filtered or unexported fields
}
UpdateBuilder builds an UPDATE query
func (*UpdateBuilder) SQL ¶
func (q *UpdateBuilder) SQL(b SQLBuilder) (string, []interface{})
SQL returns a query string and a list of values
func (*UpdateBuilder) Set ¶
func (q *UpdateBuilder) Set(f Field, v interface{}) *UpdateBuilder
Set adds an update to the SET clause
func (*UpdateBuilder) Where ¶
func (q *UpdateBuilder) Where(c ...Condition) *UpdateBuilder
Where adds conditions to the WHERE clause