Documentation ¶
Index ¶
- Variables
- func DefaultCompileType(t TypeElem, supportsUnsigned bool) string
- func EscapeAll(dialect Dialect, strings []string) []string
- func RegisterDialect(name string, dialect Dialect)
- type AggregateClause
- type AliasClause
- type BinaryExpressionClause
- func BinaryExpression(left Clause, op string, right Clause) BinaryExpressionClause
- func Eq(left Clause, right interface{}) BinaryExpressionClause
- func Gt(left Clause, right interface{}) BinaryExpressionClause
- func Gte(left Clause, right interface{}) BinaryExpressionClause
- func Like(left Clause, right interface{}) BinaryExpressionClause
- func Lt(left Clause, right interface{}) BinaryExpressionClause
- func Lte(left Clause, right interface{}) BinaryExpressionClause
- func NotEq(left Clause, right interface{}) BinaryExpressionClause
- type BindClause
- type Builder
- type Clause
- type ColumnElem
- func (c ColumnElem) Accept(context *CompilerContext) string
- func (c ColumnElem) AutoIncrement() ColumnElem
- func (c ColumnElem) Constraint(name string) ColumnElem
- func (c ColumnElem) Default(def interface{}) ColumnElem
- func (c ColumnElem) Eq(value interface{}) Clause
- func (c ColumnElem) Gt(value interface{}) Clause
- func (c ColumnElem) Gte(value interface{}) Clause
- func (c ColumnElem) In(values ...interface{}) Clause
- func (c ColumnElem) Like(pattern string) Clause
- func (c ColumnElem) Lt(value interface{}) Clause
- func (c ColumnElem) Lte(value interface{}) Clause
- func (c ColumnElem) NotEq(value interface{}) Clause
- func (c ColumnElem) NotIn(values ...interface{}) Clause
- func (c ColumnElem) NotNull() ColumnElem
- func (c ColumnElem) Null() ColumnElem
- func (c ColumnElem) PrimaryKey() ColumnElem
- func (c ColumnElem) String(dialect Dialect) string
- func (c ColumnElem) Unique() ColumnElem
- type ColumnOptions
- type CombinerClause
- type Compiler
- type CompilerContext
- type CompositeIndex
- type ConstraintElem
- type DefaultDialect
- func (d *DefaultDialect) AutoIncrement(column *ColumnElem) string
- func (d *DefaultDialect) CompileType(t TypeElem) string
- func (d *DefaultDialect) Driver() string
- func (d *DefaultDialect) Escape(str string) string
- func (d *DefaultDialect) EscapeAll(strings []string) []string
- func (d *DefaultDialect) Escaping() bool
- func (d *DefaultDialect) GetCompiler() Compiler
- func (d *DefaultDialect) SetEscaping(escaping bool)
- func (d *DefaultDialect) SupportsUnsigned() bool
- func (d *DefaultDialect) WrapError(err error) Error
- type DefaultLogger
- type DeleteStmt
- type Dialect
- type Engine
- func (e *Engine) Begin() (*Tx, error)
- func (e *Engine) BeginContext(ctx context.Context) (*Tx, error)
- func (e *Engine) Close() error
- func (e *Engine) DB() *sqlx.DB
- func (e Engine) Dialect() Dialect
- func (e *Engine) Driver() string
- func (e *Engine) Dsn() string
- func (e *Engine) Exec(builder Builder) (sql.Result, error)
- func (e *Engine) ExecContext(ctx context.Context, builder Builder) (sql.Result, error)
- func (e *Engine) Get(builder Builder, model interface{}) error
- func (e *Engine) GetContext(ctx context.Context, builder Builder, model interface{}) error
- func (e *Engine) Logger() Logger
- func (e *Engine) Ping() error
- func (e *Engine) PingContext(ctx context.Context) error
- func (e *Engine) Query(builder Builder) (*sql.Rows, error)
- func (e *Engine) QueryContext(ctx context.Context, builder Builder) (*sql.Rows, error)
- func (e *Engine) QueryRow(builder Builder) Row
- func (e *Engine) QueryRowContext(ctx context.Context, builder Builder) Row
- func (e *Engine) Select(builder Builder, model interface{}) error
- func (e *Engine) SelectContext(ctx context.Context, builder Builder, model interface{}) error
- func (e Engine) SetDialect(dialect Dialect)
- func (e *Engine) SetLogFlags(flags LogFlags)
- func (e *Engine) SetLogger(logger Logger)
- func (e Engine) TranslateError(err error) error
- type Error
- type ErrorCode
- type ExistsClause
- type ForUpdateClause
- type ForeignKeyConstraint
- func (fkey ForeignKeyConstraint) OnDelete(action string) ForeignKeyConstraint
- func (fkey ForeignKeyConstraint) OnUpdate(action string) ForeignKeyConstraint
- func (fkey ForeignKeyConstraint) References(refTable string, refCols ...string) ForeignKeyConstraint
- func (fkey ForeignKeyConstraint) String(dialect Dialect) string
- type ForeignKeyConstraints
- type HavingClause
- type InClause
- type IndexElem
- type InsertStmt
- type JoinClause
- type ListClause
- type LogFlags
- type Logger
- type MetaDataElem
- type OrderByClause
- type PrimaryKeyConstraint
- type Row
- type SQLCompiler
- func (c SQLCompiler) VisitAggregate(context *CompilerContext, aggregate AggregateClause) string
- func (SQLCompiler) VisitAlias(context *CompilerContext, alias AliasClause) string
- func (c SQLCompiler) VisitBinary(context *CompilerContext, binary BinaryExpressionClause) string
- func (SQLCompiler) VisitBind(context *CompilerContext, bind BindClause) string
- func (c SQLCompiler) VisitColumn(context *CompilerContext, column ColumnElem) string
- func (c SQLCompiler) VisitCombiner(context *CompilerContext, combiner CombinerClause) string
- func (c SQLCompiler) VisitDelete(context *CompilerContext, delete DeleteStmt) string
- func (SQLCompiler) VisitExists(context *CompilerContext, exists ExistsClause) string
- func (c SQLCompiler) VisitForUpdate(context *CompilerContext, forUpdate ForUpdateClause) string
- func (c SQLCompiler) VisitHaving(context *CompilerContext, having HavingClause) string
- func (c SQLCompiler) VisitIn(context *CompilerContext, in InClause) string
- func (c SQLCompiler) VisitInsert(context *CompilerContext, insert InsertStmt) string
- func (c SQLCompiler) VisitJoin(context *CompilerContext, join JoinClause) string
- func (c SQLCompiler) VisitLabel(context *CompilerContext, label string) string
- func (c SQLCompiler) VisitList(context *CompilerContext, list ListClause) string
- func (c SQLCompiler) VisitOrderBy(context *CompilerContext, OrderByClause OrderByClause) string
- func (c SQLCompiler) VisitSelect(context *CompilerContext, selectStmt SelectStmt) string
- func (SQLCompiler) VisitTable(context *CompilerContext, table TableElem) string
- func (SQLCompiler) VisitText(context *CompilerContext, text TextClause) string
- func (c SQLCompiler) VisitUpdate(context *CompilerContext, update UpdateStmt) string
- func (c SQLCompiler) VisitUpsert(context *CompilerContext, upsert UpsertStmt) string
- func (c SQLCompiler) VisitWhere(context *CompilerContext, where WhereClause) string
- type SelectStmt
- func (s SelectStmt) Accept(context *CompilerContext) string
- func (s SelectStmt) Asc() SelectStmt
- func (s SelectStmt) Build(dialect Dialect) *Stmt
- func (s SelectStmt) CrossJoin(right Selectable) SelectStmt
- func (s SelectStmt) Desc() SelectStmt
- func (s SelectStmt) ForUpdate(tables ...TableElem) SelectStmt
- func (s SelectStmt) From(selectable Selectable) SelectStmt
- func (s SelectStmt) GroupBy(cols ...ColumnElem) SelectStmt
- func (s SelectStmt) Having(aggregate AggregateClause, op string, value interface{}) SelectStmt
- func (s SelectStmt) InnerJoin(right Selectable, onClause ...Clause) SelectStmt
- func (s SelectStmt) LeftJoin(right Selectable, onClause ...Clause) SelectStmt
- func (s SelectStmt) Limit(limit int) SelectStmt
- func (s SelectStmt) LimitOffset(limit, offset int) SelectStmt
- func (s SelectStmt) Offset(value int) SelectStmt
- func (s SelectStmt) OrderBy(columns ...ColumnElem) SelectStmt
- func (s SelectStmt) RightJoin(right Selectable, onClause ...Clause) SelectStmt
- func (s SelectStmt) Select(clauses ...Clause) SelectStmt
- func (s SelectStmt) Where(clauses ...Clause) SelectStmt
- type Selectable
- type Stmt
- type TableElem
- func (t TableElem) Accept(context *CompilerContext) string
- func (t TableElem) All() []Clause
- func (t TableElem) Build(dialect Dialect) *Stmt
- func (t TableElem) C(name string) ColumnElem
- func (t TableElem) ColumnList() []ColumnElem
- func (t TableElem) Create(dialect Dialect) string
- func (t TableElem) DefaultName() string
- func (t TableElem) Delete() DeleteStmt
- func (t TableElem) Drop(dialect Dialect) string
- func (t TableElem) Index(cols ...string) TableElem
- func (t TableElem) Insert() InsertStmt
- func (t TableElem) PrimaryCols() []ColumnElem
- func (t TableElem) Select(clauses ...Clause) SelectStmt
- func (t TableElem) Update() UpdateStmt
- func (t TableElem) Upsert() UpsertStmt
- type TableSQLClause
- type TextClause
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) Exec(builder Builder) (sql.Result, error)
- func (tx *Tx) ExecContext(ctx context.Context, builder Builder) (sql.Result, error)
- func (tx *Tx) Get(builder Builder, model interface{}) error
- func (tx *Tx) GetContext(ctx context.Context, builder Builder, model interface{}) error
- func (tx *Tx) Query(builder Builder) (*sql.Rows, error)
- func (tx *Tx) QueryContext(ctx context.Context, builder Builder) (*sql.Rows, error)
- func (tx *Tx) QueryRow(builder Builder) Row
- func (tx *Tx) QueryRowContext(ctx context.Context, builder Builder) Row
- func (tx *Tx) Rollback() error
- func (tx *Tx) Select(builder Builder, model interface{}) error
- func (tx *Tx) SelectContext(ctx context.Context, builder Builder, model interface{}) error
- func (tx *Tx) Tx() *sqlx.Tx
- type TypeElem
- func BigInt() TypeElem
- func Blob() TypeElem
- func Boolean() TypeElem
- func Char() TypeElem
- func Decimal() TypeElem
- func Float() TypeElem
- func Int() TypeElem
- func Numeric() TypeElem
- func SmallInt() TypeElem
- func Text() TypeElem
- func Timestamp() TypeElem
- func TinyInt() TypeElem
- func Type(name string) TypeElem
- func UUID() TypeElem
- func Varchar() TypeElem
- type UniqueKeyConstraint
- type UpdateStmt
- type UpsertStmt
- type WhereClause
Constants ¶
This section is empty.
Variables ¶
var DialectRegistry = make(map[string]Dialect)
DialectRegistry is a global registry of dialects
Functions ¶
func DefaultCompileType ¶
DefaultCompileType is a default implementation for Dialect.CompileType
func RegisterDialect ¶
RegisterDialect add a new dialect to the registry
Types ¶
type AggregateClause ¶
type AggregateClause struct {
// contains filtered or unexported fields
}
AggregateClause is the base struct for building aggregate functions
func Aggregate ¶
func Aggregate(fn string, clause Clause) AggregateClause
Aggregate generates a new aggregate clause given function & clause
func Avg ¶
func Avg(clause Clause) AggregateClause
Avg function generates "avg(%s)" statement for clause
func Count ¶
func Count(clause Clause) AggregateClause
Count function generates "count(%s)" statement for clause
func Max ¶
func Max(clause Clause) AggregateClause
Max function generates "max(%s)" statement for clause
func Min ¶
func Min(clause Clause) AggregateClause
Min function generates "min(%s)" statement for clause
func Sum ¶
func Sum(clause Clause) AggregateClause
Sum function generates "sum(%s)" statement for clause
func (AggregateClause) Accept ¶
func (c AggregateClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitAggregate function
type AliasClause ¶
type AliasClause struct { Name string Selectable Selectable }
AliasClause is a ALIAS sql clause
func Alias ¶
func Alias(name string, selectable Selectable) AliasClause
Alias returns a new AliasClause
func (AliasClause) Accept ¶
func (c AliasClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitAlias function
func (AliasClause) All ¶
func (c AliasClause) All() []Clause
All returns the aliased selectable columns with their "Table" field updated with the alias name
func (AliasClause) C ¶
func (c AliasClause) C(name string) ColumnElem
C returns the aliased selectable column with the given name. Before returning it, the 'Table' field is updated with alias name so that they can be used in Select()
func (AliasClause) ColumnList ¶
func (c AliasClause) ColumnList() []ColumnElem
ColumnList returns the aliased selectable columns with their "Table" field updated with the alias name
func (AliasClause) DefaultName ¶
func (c AliasClause) DefaultName() string
DefaultName returns the alias name
type BinaryExpressionClause ¶
BinaryExpressionClause is the base struct for any conditional statements in sql clauses
func BinaryExpression ¶
func BinaryExpression(left Clause, op string, right Clause) BinaryExpressionClause
BinaryExpression generates a condition object to use in update, delete & select statements
func Eq ¶
func Eq(left Clause, right interface{}) BinaryExpressionClause
Eq generates a equals conditional sql clause
func Gt ¶
func Gt(left Clause, right interface{}) BinaryExpressionClause
Gt generates a greater than conditional sql clause
func Gte ¶
func Gte(left Clause, right interface{}) BinaryExpressionClause
Gte generates a greater than or equal to conditional sql clause
func Like ¶
func Like(left Clause, right interface{}) BinaryExpressionClause
Like generates a like conditional sql clause
func Lt ¶
func Lt(left Clause, right interface{}) BinaryExpressionClause
Lt generates a less than conditional sql clause
func Lte ¶
func Lte(left Clause, right interface{}) BinaryExpressionClause
Lte generates a less than or equal to conditional sql clause
func NotEq ¶
func NotEq(left Clause, right interface{}) BinaryExpressionClause
NotEq generates a not equal conditional sql clause
func (BinaryExpressionClause) Accept ¶
func (c BinaryExpressionClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitBinary method
type BindClause ¶
type BindClause struct {
Value interface{}
}
BindClause binds a value to a placeholder
func (BindClause) Accept ¶
func (c BindClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitBind method
type Builder ¶
Builder is the common interface for any statement builder in qb such as Insert(), Update(), Delete(), Select() query starters
type Clause ¶
type Clause interface {
Accept(context *CompilerContext) string
}
Clause is the base interface of all clauses that will get compiled to SQL by Compiler
func GetClauseFrom ¶
func GetClauseFrom(value interface{}) Clause
GetClauseFrom returns the value if already a Clause, or make one if it is a scalar value
func GetListFrom ¶
func GetListFrom(values ...interface{}) Clause
GetListFrom returns a list clause from any list
If only one value is passed and is a ListClause, it is returned as-is. In any other case, a ListClause is built with each value wrapped by a Bind() if not already a Clause
func GuessJoinOnClause ¶
func GuessJoinOnClause(left Selectable, right Selectable) Clause
GuessJoinOnClause finds a join 'ON' clause between two tables
func MakeJoinOnClause ¶
func MakeJoinOnClause(left Selectable, right Selectable, onClause ...Clause) Clause
MakeJoinOnClause assemble a 'ON' clause for a join from either: 0 clause: attempt to guess the join clause (only if left & right are tables),
otherwise panics
1 clause: returns it 2 clauses: returns a Eq() of both otherwise if panics
type ColumnElem ¶
type ColumnElem struct { Name string Type TypeElem Table string // This field should be lazily set by Table() function Constraints []ConstraintElem Options ColumnOptions }
ColumnElem is the definition of any columns defined in a table
func Column ¶
func Column(name string, t TypeElem) ColumnElem
Column generates a ColumnElem given name and type
func (ColumnElem) Accept ¶
func (c ColumnElem) Accept(context *CompilerContext) string
Accept calls the compiler VisitColumn function
func (ColumnElem) AutoIncrement ¶
func (c ColumnElem) AutoIncrement() ColumnElem
AutoIncrement set up “auto increment” semantics for an integer column. Depending on the dialect, the column may be required to be a PrimaryKey too.
func (ColumnElem) Constraint ¶
func (c ColumnElem) Constraint(name string) ColumnElem
Constraint adds a custom constraint to column type
func (ColumnElem) Default ¶
func (c ColumnElem) Default(def interface{}) ColumnElem
Default adds a default constraint to column type
func (ColumnElem) Eq ¶
func (c ColumnElem) Eq(value interface{}) Clause
Eq wraps the Eq(col ColumnElem, value interface{})
func (ColumnElem) Gt ¶
func (c ColumnElem) Gt(value interface{}) Clause
Gt wraps the Gt(col ColumnElem, value interface{})
func (ColumnElem) Gte ¶
func (c ColumnElem) Gte(value interface{}) Clause
Gte wraps the Gte(col ColumnElem, value interface{})
func (ColumnElem) In ¶
func (c ColumnElem) In(values ...interface{}) Clause
In wraps the In(col ColumnElem, values ...interface{})
func (ColumnElem) Like ¶
func (c ColumnElem) Like(pattern string) Clause
Like wraps the Like(col ColumnElem, pattern string)
func (ColumnElem) Lt ¶
func (c ColumnElem) Lt(value interface{}) Clause
Lt wraps the Lt(col ColumnElem, value interface{})
func (ColumnElem) Lte ¶
func (c ColumnElem) Lte(value interface{}) Clause
Lte wraps the Lte(col ColumnElem, value interface{})
func (ColumnElem) NotEq ¶
func (c ColumnElem) NotEq(value interface{}) Clause
NotEq wraps the NotEq(col ColumnElem, value interface{})
func (ColumnElem) NotIn ¶
func (c ColumnElem) NotIn(values ...interface{}) Clause
NotIn wraps the NotIn(col ColumnElem, values ...interface{})
func (ColumnElem) NotNull ¶
func (c ColumnElem) NotNull() ColumnElem
NotNull adds not null constraint to column type
func (ColumnElem) Null ¶
func (c ColumnElem) Null() ColumnElem
Null adds null constraint to column type
func (ColumnElem) PrimaryKey ¶
func (c ColumnElem) PrimaryKey() ColumnElem
PrimaryKey add the column to the primary key
func (ColumnElem) String ¶
func (c ColumnElem) String(dialect Dialect) string
String returns the column element as an sql clause It satisfies the TableSQLClause interface
func (ColumnElem) Unique ¶
func (c ColumnElem) Unique() ColumnElem
Unique adds a unique constraint to column type
type ColumnOptions ¶
ColumnOptions holds options for a column
type CombinerClause ¶
type CombinerClause struct {
// contains filtered or unexported fields
}
CombinerClause is for OR and AND clauses
func And ¶
func And(clauses ...Clause) CombinerClause
And generates an AndClause given conditional clauses
func Or ¶
func Or(clauses ...Clause) CombinerClause
Or generates an AndClause given conditional clauses
func (CombinerClause) Accept ¶
func (c CombinerClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitCombiner entry point
type Compiler ¶
type Compiler interface { VisitAggregate(*CompilerContext, AggregateClause) string VisitAlias(*CompilerContext, AliasClause) string VisitBinary(*CompilerContext, BinaryExpressionClause) string VisitBind(*CompilerContext, BindClause) string VisitColumn(*CompilerContext, ColumnElem) string VisitCombiner(*CompilerContext, CombinerClause) string VisitDelete(*CompilerContext, DeleteStmt) string VisitExists(*CompilerContext, ExistsClause) string VisitForUpdate(*CompilerContext, ForUpdateClause) string VisitHaving(*CompilerContext, HavingClause) string VisitIn(*CompilerContext, InClause) string VisitInsert(*CompilerContext, InsertStmt) string VisitJoin(*CompilerContext, JoinClause) string VisitLabel(*CompilerContext, string) string VisitList(*CompilerContext, ListClause) string VisitOrderBy(*CompilerContext, OrderByClause) string VisitSelect(*CompilerContext, SelectStmt) string VisitTable(*CompilerContext, TableElem) string VisitText(*CompilerContext, TextClause) string VisitUpdate(*CompilerContext, UpdateStmt) string VisitUpsert(*CompilerContext, UpsertStmt) string VisitWhere(*CompilerContext, WhereClause) string }
Compiler is a visitor that produce SQL from various types of Clause
type CompilerContext ¶
type CompilerContext struct { Binds []interface{} DefaultTableName string InSubQuery bool Vars map[string]interface{} Dialect Dialect Compiler Compiler }
CompilerContext is a data structure passed to all the Compiler visit functions. It contains the bindings, links to the Dialect and Compiler being used, and some contextual informations that can be used by the compiler functions to communicate during the compilation.
func NewCompilerContext ¶
func NewCompilerContext(dialect Dialect) *CompilerContext
NewCompilerContext initialize a new compiler context
type CompositeIndex ¶
type CompositeIndex string
CompositeIndex is the struct definition when building composite indices for any struct that will be mapped into a table
type ConstraintElem ¶
type ConstraintElem struct {
Name string
}
ConstraintElem is the definition of column & table constraints
func Constraint ¶
func Constraint(name string) ConstraintElem
Constraint generates a custom constraint due to variation of dialects
func Default ¶
func Default(value interface{}) ConstraintElem
Default generates generic default constraint
func Unique ¶
func Unique() ConstraintElem
Unique generates generic unique constraint if cols are given, then composite unique constraint will be built
func (ConstraintElem) String ¶
func (c ConstraintElem) String() string
String returns the constraint as an sql clause
type DefaultDialect ¶
type DefaultDialect struct {
// contains filtered or unexported fields
}
DefaultDialect is a type of dialect that can be used with unsupported sql drivers
func (*DefaultDialect) AutoIncrement ¶
func (d *DefaultDialect) AutoIncrement(column *ColumnElem) string
AutoIncrement generates auto increment sql of current dialect
func (*DefaultDialect) CompileType ¶
func (d *DefaultDialect) CompileType(t TypeElem) string
CompileType compiles a type into its DDL
func (*DefaultDialect) Driver ¶
func (d *DefaultDialect) Driver() string
Driver returns the current driver of dialect
func (*DefaultDialect) Escape ¶
func (d *DefaultDialect) Escape(str string) string
Escape wraps the string with escape characters of the dialect
func (*DefaultDialect) EscapeAll ¶
func (d *DefaultDialect) EscapeAll(strings []string) []string
EscapeAll wraps all elements of string array
func (*DefaultDialect) Escaping ¶
func (d *DefaultDialect) Escaping() bool
Escaping gets the escaping parameter of dialect
func (*DefaultDialect) GetCompiler ¶
func (d *DefaultDialect) GetCompiler() Compiler
GetCompiler returns the default SQLCompiler
func (*DefaultDialect) SetEscaping ¶
func (d *DefaultDialect) SetEscaping(escaping bool)
SetEscaping sets the escaping parameter of dialect
func (*DefaultDialect) SupportsUnsigned ¶
func (d *DefaultDialect) SupportsUnsigned() bool
SupportsUnsigned returns whether driver supports unsigned type mappings or not
func (*DefaultDialect) WrapError ¶
func (d *DefaultDialect) WrapError(err error) Error
WrapError wraps a native error in a qb Error
type DefaultLogger ¶
DefaultLogger is the default logger of qb engine unless engine.SetLogger() is not called
func (*DefaultLogger) LogFlags ¶
func (l *DefaultLogger) LogFlags() LogFlags
LogFlags gets the logflags as an int
func (*DefaultLogger) SetLogFlags ¶
func (l *DefaultLogger) SetLogFlags(logFlags LogFlags)
SetLogFlags sets the logflags It is for changing engine log flags
type DeleteStmt ¶
type DeleteStmt struct {
// contains filtered or unexported fields
}
DeleteStmt is the base struct for building delete queries
func Delete ¶
func Delete(table TableElem) DeleteStmt
Delete generates a delete statement and returns it for chaining qb.Delete(usersTable).Where(qb.Eq("id", 5))
func (DeleteStmt) Accept ¶
func (s DeleteStmt) Accept(context *CompilerContext) string
Accept implements Clause.Accept
func (DeleteStmt) Build ¶
func (s DeleteStmt) Build(dialect Dialect) *Stmt
Build generates a statement out of DeleteStmt object
func (DeleteStmt) Returning ¶
func (s DeleteStmt) Returning(cols ...ColumnElem) DeleteStmt
Returning accepts the column names as strings and forms the returning array of insert statement NOTE: Please use it in only postgres dialect, otherwise it'll crash
func (DeleteStmt) Where ¶
func (s DeleteStmt) Where(clause Clause) DeleteStmt
Where adds a where clause to the current delete statement
type Dialect ¶
type Dialect interface { GetCompiler() Compiler CompileType(t TypeElem) string Escape(str string) string EscapeAll([]string) []string SetEscaping(escaping bool) Escaping() bool AutoIncrement(column *ColumnElem) string SupportsUnsigned() bool Driver() string WrapError(err error) Error }
Dialect is the common interface for driver changes It is for fixing compatibility issues of different drivers
func NewDefaultDialect ¶
func NewDefaultDialect() Dialect
NewDefaultDialect instanciate a DefaultDialect
func NewDialect ¶
NewDialect returns a dialect pointer given driver
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the generic struct for handling db connections
func (*Engine) BeginContext ¶
BeginContext begins a transaction and return a *qb.Tx
func (*Engine) ExecContext ¶
ExecContext executes insert & update type queries and returns sql.Result and error
func (*Engine) GetContext ¶
GetContext maps the single row to a model
func (*Engine) Ping ¶
Ping pings the db using connection and returns error if connectivity is not present
func (*Engine) PingContext ¶
PingContext pings the db using connection and returns error if connectivity is not present
func (*Engine) QueryContext ¶
QueryContext wraps *sql.DB.QueryContext()
func (*Engine) QueryRowContext ¶
QueryRowContext wraps *sql.DB.QueryRow()
func (*Engine) SelectContext ¶
SelectContext maps multiple rows to a model array
func (Engine) SetDialect ¶
SetDialect sets the current engine dialect
func (*Engine) SetLogFlags ¶
SetLogFlags sets the log flags on the current logger
func (Engine) TranslateError ¶
TranslateError translates the native errors into qb.Error
type Error ¶
type Error struct { Code ErrorCode Orig error // The native error from the driver Table string Column string Constraint string }
Error wraps driver errors. It helps handling constraint error in a generic way, while still giving access to the original error
type ErrorCode ¶
type ErrorCode int
ErrorCode discriminates the types of errors that qb wraps, mainly the constraint errors The different kind of errors are based on the python dbapi errors (https://www.python.org/dev/peps/pep-0249/#exceptions)
const ( // ErrAny is for errors that could not be categorized by the dialect ErrAny ErrorCode = 0 // ErrInterface is a bit mask for errors that are related to the database // interface rather than the database itself. ErrInterface ErrorCode = 1 << 8 // ErrDatabase is a bit mask for errors that are related to the database. ErrDatabase ErrorCode = 1 << 9 )
Bit 8 and 9 are flags to separate interface errors from database errors
const ( // ErrData is for errors that are due to problems with the processed data // like division by zero, numeric value out of range, etc. ErrData ErrorCode = ErrDatabase | (iota + 1<<5) // ErrOperational is for errors that are related to the database's // operation and not necessarily under the control of the programmer, e.g. // an unexpected disconnect occurs, the data source name is not found, a // transaction could not be processed, a memory allocation error occurred // during processing, etc. ErrOperational // ErrIntegrity is when the relational integrity of the database is // affected, e.g. a foreign key check fails ErrIntegrity // ErrInternal is when the database encounters an internal error, e.g. the // cursor is not valid anymore, the transaction is out of sync, etc. ErrInternal // ErrProgramming is for programming errors, e.g. table not found or // already exists, syntax error in the SQL statement, wrong number of // parameters specified, etc. ErrProgramming // ErrNotSupported is in case a method or database API was used which // is not supported by the database, e.g. requesting a .rollback() on a // connection that does not support transaction or has transactions turned // off. ErrNotSupported )
Database error codes are in bits 5 to 7, leaving bits 0 to 4 for detailed codes in a later version
func (ErrorCode) IsDatabaseError ¶
IsDatabaseError returns true if the error is a Database error
func (ErrorCode) IsInterfaceError ¶
IsInterfaceError returns true if the error is a Interface error
type ExistsClause ¶
type ExistsClause struct { Select SelectStmt Not bool }
ExistsClause is a EXISTS clause
func (ExistsClause) Accept ¶
func (c ExistsClause) Accept(context *CompilerContext) string
Accept calls compiler VisitExists methos
type ForUpdateClause ¶
type ForUpdateClause struct {
Tables []TableElem
}
ForUpdateClause is a FOR UPDATE expression
func (ForUpdateClause) Accept ¶
func (s ForUpdateClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitForUpdate method
type ForeignKeyConstraint ¶
type ForeignKeyConstraint struct { Cols []string RefTable string RefCols []string ActionOnUpdate string ActionOnDelete string }
ForeignKeyConstraint is the main struct for defining foreign key references
func ForeignKey ¶
func ForeignKey(cols ...string) ForeignKeyConstraint
ForeignKey generates a foreign key for table constraint definitions
func (ForeignKeyConstraint) OnDelete ¶
func (fkey ForeignKeyConstraint) OnDelete(action string) ForeignKeyConstraint
OnDelete set the ON DELETE action
func (ForeignKeyConstraint) OnUpdate ¶
func (fkey ForeignKeyConstraint) OnUpdate(action string) ForeignKeyConstraint
OnUpdate set the ON UPDATE action
func (ForeignKeyConstraint) References ¶
func (fkey ForeignKeyConstraint) References(refTable string, refCols ...string) ForeignKeyConstraint
References set the reference part of the foreign key
func (ForeignKeyConstraint) String ¶
func (fkey ForeignKeyConstraint) String(dialect Dialect) string
type ForeignKeyConstraints ¶
type ForeignKeyConstraints struct {
FKeys []ForeignKeyConstraint
}
ForeignKeyConstraints is the definition of foreign keys in any table
func (ForeignKeyConstraints) String ¶
func (c ForeignKeyConstraints) String(dialect Dialect) string
type HavingClause ¶
type HavingClause struct {
// contains filtered or unexported fields
}
HavingClause is the base struct for generating having clauses when using select It satisfies SQLClause interface
func (HavingClause) Accept ¶
func (c HavingClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitHaving function
type InClause ¶
type InClause struct {
BinaryExpressionClause
}
InClause is a IN or NOT IN binary expression
func (InClause) Accept ¶
func (c InClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitBinary method
type IndexElem ¶
IndexElem is the definition of any index elements for a table
type InsertStmt ¶
type InsertStmt struct {
// contains filtered or unexported fields
}
InsertStmt is the base struct for any insert statements
func Insert ¶
func Insert(table TableElem) InsertStmt
Insert generates an insert statement and returns it Insert(usersTable).Values(map[string]interface{}{"id": 1})
func (InsertStmt) Accept ¶
func (s InsertStmt) Accept(context *CompilerContext) string
Accept implements Clause.Accept
func (InsertStmt) Build ¶
func (s InsertStmt) Build(dialect Dialect) *Stmt
Build generates a statement out of InsertStmt object
func (InsertStmt) Returning ¶
func (s InsertStmt) Returning(cols ...ColumnElem) InsertStmt
Returning accepts the column names as strings and forms the returning array of insert statement NOTE: Please use it in only postgres dialect, otherwise it'll crash
func (InsertStmt) Values ¶
func (s InsertStmt) Values(values map[string]interface{}) InsertStmt
Values accepts map[string]interface{} and forms the values map of insert statement
type JoinClause ¶
type JoinClause struct { JoinType string Left Selectable Right Selectable OnClause Clause }
JoinClause is the base struct for generating join clauses when using select It satisfies Clause interface
func Join ¶
func Join(joinType string, left Selectable, right Selectable, onClause ...Clause) JoinClause
Join returns a new JoinClause onClause can be one of:
- 0 clause: attempt to guess the join clause (only if left & right are tables), otherwise panics
- 1 clause: use it directly
- 2 clauses: use a Eq() of both
func (JoinClause) Accept ¶
func (c JoinClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitJoin method
func (JoinClause) All ¶
func (c JoinClause) All() []Clause
All returns the columns from both sides of the join
func (JoinClause) C ¶
func (c JoinClause) C(name string) ColumnElem
C returns the first column with the given name If columns from both sides of the join match the name, the one from the left side will be returned.
func (JoinClause) ColumnList ¶
func (c JoinClause) ColumnList() []ColumnElem
ColumnList returns the columns from both sides of the join
func (JoinClause) DefaultName ¶
func (c JoinClause) DefaultName() string
DefaultName returns an empty string because Joins have no name by default
type ListClause ¶
type ListClause struct {
Clauses []Clause
}
ListClause is a list of clause elements (for IN operator for example)
func (ListClause) Accept ¶
func (c ListClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitList method
type LogFlags ¶
type LogFlags uint
LogFlags is the type we use for flags that can be passed to the logger
type Logger ¶
type Logger interface { Print(...interface{}) Printf(string, ...interface{}) Println(...interface{}) Fatal(...interface{}) Fatalf(string, ...interface{}) Fatalln(...interface{}) Panic(...interface{}) Panicf(string, ...interface{}) Panicln(...interface{}) LogFlags() LogFlags SetLogFlags(LogFlags) }
Logger is the std logger interface of the qb engine
type MetaDataElem ¶
type MetaDataElem struct {
// contains filtered or unexported fields
}
MetaDataElem is the container for database structs and tables
func MetaData ¶
func MetaData() *MetaDataElem
MetaData creates a new MetaData object and returns it as a pointer
func (*MetaDataElem) AddTable ¶
func (m *MetaDataElem) AddTable(table TableElem)
AddTable appends table to tables slice
func (*MetaDataElem) CreateAll ¶
func (m *MetaDataElem) CreateAll(engine *Engine) error
CreateAll creates all the tables added to metadata
func (*MetaDataElem) DropAll ¶
func (m *MetaDataElem) DropAll(engine *Engine) error
DropAll drops all the tables which is added to metadata
func (*MetaDataElem) Table ¶
func (m *MetaDataElem) Table(name string) TableElem
Table returns the metadata registered table object. It returns nil if table is not found
func (*MetaDataElem) Tables ¶
func (m *MetaDataElem) Tables() []TableElem
Tables returns the current tables slice
type OrderByClause ¶
type OrderByClause struct {
// contains filtered or unexported fields
}
OrderByClause is the base struct for generating order by clauses when using select It satisfies SQLClause interface
func (OrderByClause) Accept ¶
func (c OrderByClause) Accept(context *CompilerContext) string
Accept generates an order by clause
type PrimaryKeyConstraint ¶
type PrimaryKeyConstraint struct {
Columns []string
}
PrimaryKeyConstraint is the definition of primary key constraints of any table
func PrimaryKey ¶
func PrimaryKey(cols ...string) PrimaryKeyConstraint
PrimaryKey generates a primary key constraint of any table
func (PrimaryKeyConstraint) String ¶
func (c PrimaryKeyConstraint) String(dialect Dialect) string
String returns the primary key constraints as an sql clause
type SQLCompiler ¶
type SQLCompiler struct {
Dialect Dialect
}
SQLCompiler aims to provide a SQL ANSI-92 implementation of Compiler
func NewSQLCompiler ¶
func NewSQLCompiler(dialect Dialect) SQLCompiler
NewSQLCompiler returns a new SQLCompiler
func (SQLCompiler) VisitAggregate ¶
func (c SQLCompiler) VisitAggregate(context *CompilerContext, aggregate AggregateClause) string
VisitAggregate compiles aggregate functions (COUNT, SUM...)
func (SQLCompiler) VisitAlias ¶
func (SQLCompiler) VisitAlias(context *CompilerContext, alias AliasClause) string
VisitAlias compiles a '<selectable> AS <aliasname>' SQL clause
func (SQLCompiler) VisitBinary ¶
func (c SQLCompiler) VisitBinary(context *CompilerContext, binary BinaryExpressionClause) string
VisitBinary compiles LEFT <op> RIGHT expressions
func (SQLCompiler) VisitBind ¶
func (SQLCompiler) VisitBind(context *CompilerContext, bind BindClause) string
VisitBind renders a bounded value
func (SQLCompiler) VisitColumn ¶
func (c SQLCompiler) VisitColumn(context *CompilerContext, column ColumnElem) string
VisitColumn returns a column name, optionnaly escaped depending on the dialect configuration
func (SQLCompiler) VisitCombiner ¶
func (c SQLCompiler) VisitCombiner(context *CompilerContext, combiner CombinerClause) string
VisitCombiner compiles AND and OR sql clauses
func (SQLCompiler) VisitDelete ¶
func (c SQLCompiler) VisitDelete(context *CompilerContext, delete DeleteStmt) string
VisitDelete compiles a DELETE statement
func (SQLCompiler) VisitExists ¶
func (SQLCompiler) VisitExists(context *CompilerContext, exists ExistsClause) string
VisitExists compile a EXISTS clause
func (SQLCompiler) VisitForUpdate ¶
func (c SQLCompiler) VisitForUpdate(context *CompilerContext, forUpdate ForUpdateClause) string
VisitForUpdate compiles a 'FOR UPDATE' clause
func (SQLCompiler) VisitHaving ¶
func (c SQLCompiler) VisitHaving(context *CompilerContext, having HavingClause) string
VisitHaving compiles a HAVING clause
func (SQLCompiler) VisitIn ¶
func (c SQLCompiler) VisitIn(context *CompilerContext, in InClause) string
VisitIn compiles a <left> (NOT) IN (<right>)
func (SQLCompiler) VisitInsert ¶
func (c SQLCompiler) VisitInsert(context *CompilerContext, insert InsertStmt) string
VisitInsert compiles a INSERT statement
func (SQLCompiler) VisitJoin ¶
func (c SQLCompiler) VisitJoin(context *CompilerContext, join JoinClause) string
VisitJoin compiles a JOIN (ON) clause
func (SQLCompiler) VisitLabel ¶
func (c SQLCompiler) VisitLabel(context *CompilerContext, label string) string
VisitLabel returns a single label, optionally escaped
func (SQLCompiler) VisitList ¶
func (c SQLCompiler) VisitList(context *CompilerContext, list ListClause) string
VisitList compiles a list of values
func (SQLCompiler) VisitOrderBy ¶
func (c SQLCompiler) VisitOrderBy(context *CompilerContext, OrderByClause OrderByClause) string
VisitOrderBy compiles a ORDER BY sql clause
func (SQLCompiler) VisitSelect ¶
func (c SQLCompiler) VisitSelect(context *CompilerContext, selectStmt SelectStmt) string
VisitSelect compiles a SELECT statement
func (SQLCompiler) VisitTable ¶
func (SQLCompiler) VisitTable(context *CompilerContext, table TableElem) string
VisitTable returns a table name, optionally escaped
func (SQLCompiler) VisitText ¶
func (SQLCompiler) VisitText(context *CompilerContext, text TextClause) string
VisitText return a raw SQL clause as is
func (SQLCompiler) VisitUpdate ¶
func (c SQLCompiler) VisitUpdate(context *CompilerContext, update UpdateStmt) string
VisitUpdate compiles a UPDATE statement
func (SQLCompiler) VisitUpsert ¶
func (c SQLCompiler) VisitUpsert(context *CompilerContext, upsert UpsertStmt) string
VisitUpsert is not implemented and will panic. It should be implemented in each dialect
func (SQLCompiler) VisitWhere ¶
func (c SQLCompiler) VisitWhere(context *CompilerContext, where WhereClause) string
VisitWhere compiles a WHERE clause
type SelectStmt ¶
type SelectStmt struct { SelectList []Clause FromClause Selectable GroupByClause []ColumnElem OrderByClause *OrderByClause HavingClause []HavingClause WhereClause *WhereClause ForUpdateClause *ForUpdateClause OffsetValue *int LimitValue *int }
SelectStmt is the base struct for building select statements
func Select ¶
func Select(clauses ...Clause) SelectStmt
Select generates a select statement and returns it
func (SelectStmt) Accept ¶
func (s SelectStmt) Accept(context *CompilerContext) string
Accept calls the compiler VisitSelect method
func (SelectStmt) Asc ¶
func (s SelectStmt) Asc() SelectStmt
Asc sets the t type of current order by clause NOTE: Please use it after calling OrderBy()
func (SelectStmt) Build ¶
func (s SelectStmt) Build(dialect Dialect) *Stmt
Build compiles the select statement and returns the Stmt
func (SelectStmt) CrossJoin ¶
func (s SelectStmt) CrossJoin(right Selectable) SelectStmt
CrossJoin appends an cross join clause to the select statement
func (SelectStmt) Desc ¶
func (s SelectStmt) Desc() SelectStmt
Desc sets the t type of current order by clause NOTE: Please use it after calling OrderBy()
func (SelectStmt) ForUpdate ¶
func (s SelectStmt) ForUpdate(tables ...TableElem) SelectStmt
ForUpdate adds a "FOR UPDATE" clause
func (SelectStmt) From ¶
func (s SelectStmt) From(selectable Selectable) SelectStmt
From sets the from selectable of select statement
func (SelectStmt) GroupBy ¶
func (s SelectStmt) GroupBy(cols ...ColumnElem) SelectStmt
GroupBy appends columns to group by clause of the select statement
func (SelectStmt) Having ¶
func (s SelectStmt) Having(aggregate AggregateClause, op string, value interface{}) SelectStmt
Having appends a having clause to select statement
func (SelectStmt) InnerJoin ¶
func (s SelectStmt) InnerJoin(right Selectable, onClause ...Clause) SelectStmt
InnerJoin appends an inner join clause to the select statement
func (SelectStmt) LeftJoin ¶
func (s SelectStmt) LeftJoin(right Selectable, onClause ...Clause) SelectStmt
LeftJoin appends an left outer join clause to the select statement
func (SelectStmt) Limit ¶
func (s SelectStmt) Limit(limit int) SelectStmt
Limit sets the limit number of rows
func (SelectStmt) LimitOffset ¶
func (s SelectStmt) LimitOffset(limit, offset int) SelectStmt
LimitOffset sets the limit & offset values of the select statement
func (SelectStmt) OrderBy ¶
func (s SelectStmt) OrderBy(columns ...ColumnElem) SelectStmt
OrderBy generates an OrderByClause and sets select statement's orderbyclause OrderBy(usersTable.C("id")).Asc() OrderBy(usersTable.C("email")).Desc()
func (SelectStmt) RightJoin ¶
func (s SelectStmt) RightJoin(right Selectable, onClause ...Clause) SelectStmt
RightJoin appends a right outer join clause to select statement
func (SelectStmt) Select ¶
func (s SelectStmt) Select(clauses ...Clause) SelectStmt
Select sets the selected columns
func (SelectStmt) Where ¶
func (s SelectStmt) Where(clauses ...Clause) SelectStmt
Where sets the where clause of select statement
type Selectable ¶
type Selectable interface { Clause All() []Clause ColumnList() []ColumnElem C(column string) ColumnElem DefaultName() string }
Selectable is any clause from which we can select columns and is suitable as a FROM clause element
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt is the base abstraction for all sql queries
func (*Stmt) AddBinding ¶
func (s *Stmt) AddBinding(bindings ...interface{})
AddBinding appends a new binding to current query
func (*Stmt) AddSQLClause ¶
AddSQLClause appends a new clause to current query
func (*Stmt) Bindings ¶
func (s *Stmt) Bindings() []interface{}
Bindings returns all bindings of current query
func (*Stmt) SQLClauses ¶
SQLClauses returns all clauses of current query
func (*Stmt) SetDelimiter ¶
SetDelimiter sets the delimiter of query
type TableElem ¶
type TableElem struct { Name string Columns map[string]ColumnElem PrimaryKeyConstraint PrimaryKeyConstraint ForeignKeyConstraints ForeignKeyConstraints UniqueKeyConstraint UniqueKeyConstraint Indices []IndexElem }
TableElem is the definition of any sql table
func Table ¶
func Table(name string, clauses ...TableSQLClause) TableElem
Table generates table struct given name and clauses
func (TableElem) Accept ¶
func (t TableElem) Accept(context *CompilerContext) string
Accept implements Clause.Accept
func (TableElem) C ¶
func (t TableElem) C(name string) ColumnElem
C returns the column name given col
func (TableElem) ColumnList ¶
func (t TableElem) ColumnList() []ColumnElem
ColumnList columns of the table
func (TableElem) DefaultName ¶
DefaultName returns the name of the table
func (TableElem) Delete ¶
func (t TableElem) Delete() DeleteStmt
Delete starts a delete statement by setting the table parameter
func (TableElem) Insert ¶
func (t TableElem) Insert() InsertStmt
Insert starts an insert statement by setting the table parameter
func (TableElem) PrimaryCols ¶
func (t TableElem) PrimaryCols() []ColumnElem
PrimaryCols returns the columns that are primary key to the table
func (TableElem) Select ¶
func (t TableElem) Select(clauses ...Clause) SelectStmt
Select starts a select statement by setting from table
func (TableElem) Update ¶
func (t TableElem) Update() UpdateStmt
Update starts an update statement by setting the table parameter
func (TableElem) Upsert ¶
func (t TableElem) Upsert() UpsertStmt
Upsert starts an upsert statement by setting the table parameter
type TableSQLClause ¶
type TableSQLClause interface { // String takes the dialect and returns the ddl as an sql string String(dialect Dialect) string }
TableSQLClause is the common interface for ddl generators such as Column(), PrimaryKey(), ForeignKey().Ref(), etc.
type TextClause ¶
type TextClause struct {
Text string
}
TextClause is a raw SQL clause
func (TextClause) Accept ¶
func (c TextClause) Accept(context *CompilerContext) string
Accept calls the compiler VisitText method
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is an in-progress database transaction
func (*Tx) ExecContext ¶
ExecContext executes insert & update type queries and returns sql.Result and error
func (*Tx) GetContext ¶
GetContext maps the single row to a model
func (*Tx) QueryContext ¶
QueryContext wraps *sql.DB.QueryContext()
func (*Tx) QueryRowContext ¶
QueryRowContext wraps *sql.DB.QueryRow()
func (*Tx) SelectContext ¶
SelectContext maps multiple rows to a model array
type TypeElem ¶
type TypeElem struct { Name string // contains filtered or unexported fields }
TypeElem is the struct for defining column types
func (TypeElem) Precision ¶
Precision sets the precision of column type Note: Use it in Float, Decimal and Numeric types
func (TypeElem) Signed ¶
Signed change the column type to 'signed' Note: Use it in Float, Decimal and Numeric types
type UniqueKeyConstraint ¶
type UniqueKeyConstraint struct {
// contains filtered or unexported fields
}
UniqueKeyConstraint is the base struct to define composite unique indexes of tables
func UniqueKey ¶
func UniqueKey(cols ...string) UniqueKeyConstraint
UniqueKey generates UniqueKeyConstraint given columns as strings
func (UniqueKeyConstraint) Name ¶
func (c UniqueKeyConstraint) Name(name string) UniqueKeyConstraint
Name set the constraint name
func (UniqueKeyConstraint) String ¶
func (c UniqueKeyConstraint) String(dialect Dialect) string
String generates composite unique indices as sql clause
func (UniqueKeyConstraint) Table ¶
func (c UniqueKeyConstraint) Table(name string) UniqueKeyConstraint
Table optionally set the constraint name based on the table name if a name is already defined, it remains untouched
type UpdateStmt ¶
type UpdateStmt struct {
// contains filtered or unexported fields
}
UpdateStmt is the base struct for any update statements
func Update ¶
func Update(table TableElem) UpdateStmt
Update generates an update statement and returns it qb.Update(usersTable). Values(map[string]interface{}{"id": 1}). Where(qb.Eq("id", 5))
func (UpdateStmt) Accept ¶
func (s UpdateStmt) Accept(context *CompilerContext) string
Accept implements Clause.Accept
func (UpdateStmt) Build ¶
func (s UpdateStmt) Build(dialect Dialect) *Stmt
Build generates a statement out of UpdateStmt object
func (UpdateStmt) Returning ¶
func (s UpdateStmt) Returning(cols ...ColumnElem) UpdateStmt
Returning accepts the column names as strings and forms the returning array of insert statement NOTE: Please use it in only postgres dialect, otherwise it'll crash
func (UpdateStmt) Values ¶
func (s UpdateStmt) Values(values map[string]interface{}) UpdateStmt
Values accepts map[string]interface{} and forms the values map of insert statement
func (UpdateStmt) Where ¶
func (s UpdateStmt) Where(clause Clause) UpdateStmt
Where adds a where clause to update statement and returns the update statement
type UpsertStmt ¶
type UpsertStmt struct { Table TableElem ValuesMap map[string]interface{} ReturningCols []ColumnElem }
UpsertStmt is the base struct for any insert ... on conflict/duplicate key ... update ... statements
func Upsert ¶
func Upsert(table TableElem) UpsertStmt
Upsert generates an insert ... on (duplicate key/conflict) update statement
func (UpsertStmt) Accept ¶
func (s UpsertStmt) Accept(context *CompilerContext) string
Accept calls the compiler VisitUpsert function
func (UpsertStmt) Build ¶
func (s UpsertStmt) Build(dialect Dialect) *Stmt
Build generates a statement out of UpdateStmt object
func (UpsertStmt) Returning ¶
func (s UpsertStmt) Returning(cols ...ColumnElem) UpsertStmt
Returning accepts the column names as strings and forms the returning array of insert statement NOTE: Please use it in only postgres dialect, otherwise it'll crash
func (UpsertStmt) Values ¶
func (s UpsertStmt) Values(values map[string]interface{}) UpsertStmt
Values accepts map[string]interface{} and forms the values map of insert statement
type WhereClause ¶
type WhereClause struct {
// contains filtered or unexported fields
}
WhereClause is the base of any where clause when using expression api
func (WhereClause) Accept ¶
func (c WhereClause) Accept(context *CompilerContext) string
Accept compiles the where clause, returns sql
func (WhereClause) And ¶
func (c WhereClause) And(clauses ...Clause) WhereClause
And combine the current clause and the new ones with a And()
func (WhereClause) Or ¶
func (c WhereClause) Or(clauses ...Clause) WhereClause
Or combine the current clause and the new ones with a Or()