Documentation
¶
Index ¶
- Constants
- func DefaultLogger(sql string, duration time.Duration, isTx bool, retry bool)
- type Alias
- type ArrayDimension
- type ArrayExpression
- type ArrayField
- type Assignment
- type BooleanExpression
- type BooleanField
- type CaseExpression
- type CaseExpressionWithElse
- type Cursor
- type Database
- type DateExpression
- type DateField
- type Expression
- type Field
- type InterceptorFunc
- type InvokerFunc
- type LoggerFunc
- type Model
- type NumberExpression
- type NumberField
- type OrderBy
- type Scanner
- type StringExpression
- type StringField
- type Table
- type Transaction
- type UnknownExpression
- type WellKnownBinary
- type WellKnownBinaryExpression
- type WellKnownBinaryField
Constants ¶
const (
// SqlingoRuntimeVersion is the the runtime version of sqlingo
SqlingoRuntimeVersion = 2
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArrayDimension ¶
type ArrayExpression ¶
type ArrayExpression interface {
Expression
}
type ArrayField ¶
type ArrayField interface {
ArrayExpression
IndexOf(index int) Field
GetTable() Table
}
ArrayField is the interface of a generated field of array type.
type Assignment ¶
Assignment is an assignment statement
type BooleanExpression ¶
type BooleanExpression interface {
Expression
And(other interface{}) BooleanExpression
Or(other interface{}) BooleanExpression
Xor(other interface{}) BooleanExpression
Not() BooleanExpression
}
BooleanExpression is the interface of an SQL expression with boolean value.
func And ¶
func And(expressions ...BooleanExpression) (result BooleanExpression)
And creates an expression with AND operator.
func False ¶
func False() BooleanExpression
func Or ¶
func Or(expressions ...BooleanExpression) (result BooleanExpression)
Or creates an expression with OR operator.
func True ¶
func True() BooleanExpression
type BooleanField ¶
type BooleanField interface {
BooleanExpression
GetTable() Table
}
BooleanField is the interface of a generated field of boolean type.
func NewBooleanField ¶
func NewBooleanField(table Table, fieldName string) BooleanField
NewBooleanField creates a reference to a boolean field. It should only be called from generated code.
type CaseExpression ¶
type CaseExpression interface {
WhenThen(when BooleanExpression, then interface{}) CaseExpression
Else(value interface{}) CaseExpressionWithElse
End() Expression
}
CaseExpression indicates the status in a CASE statement
type CaseExpressionWithElse ¶
type CaseExpressionWithElse interface {
End() Expression
}
CaseExpressionWithElse indicates the status in CASE ... ELSE ... statement
type Cursor ¶
type Cursor interface {
Next() bool
Scan(dest ...interface{}) error
GetMap() (map[string]value, error)
Close() error
}
Cursor is the interface of a row cursor.
type Database ¶
type Database interface {
// Get the underlying sql.DB object of the database
GetDB() *sql.DB
BeginTx(ctx context.Context, opts *sql.TxOptions, f func(tx Transaction) error) error
// Executes a query and return the cursor
Query(sql string) (Cursor, error)
// Executes a query with context and return the cursor
QueryContext(ctx context.Context, sqlString string) (Cursor, error)
// Executes a statement
Execute(sql string) (sql.Result, error)
// Executes a statement with context
ExecuteContext(ctx context.Context, sql string) (sql.Result, error)
// Set the logger function
SetLogger(logger LoggerFunc)
// Set the retry policy function.
// The retry policy function returns true if needs retry.
SetRetryPolicy(retryPolicy func(err error) bool)
// EnableCallerInfo enable or disable the caller info in the log.
// Deprecated: use SetLogger instead
EnableCallerInfo(enableCallerInfo bool)
// Set a interceptor function
SetInterceptor(interceptor InterceptorFunc)
// Initiate a SELECT statement
Select(fields ...interface{}) selectWithFields
// Initiate a SELECT DISTINCT statement
SelectDistinct(fields ...interface{}) selectWithFields
// Initiate a SELECT * FROM statement
SelectFrom(tables ...Table) selectWithTables
// Initiate a INSERT INTO statement
InsertInto(table Table) insertWithTable
// Initiate a REPLACE INTO statement
ReplaceInto(table Table) insertWithTable
// Initiate a UPDATE statement
Update(table Table) updateWithSet
// Initiate a DELETE FROM statement
DeleteFrom(table Table) deleteWithTable
}
Database is the interface of a database with underlying sql.DB object.
type DateExpression ¶
type DateExpression interface {
Expression
}
type DateField ¶
type DateField interface {
DateExpression
GetTable() Table
}
func NewDateField ¶
NewDateField creates a reference to a time.Time field. It should only be called from generated code.
type Expression ¶
type Expression interface {
// get the SQL string
GetSQL(scope scope) (string, error)
// <> operator
NotEquals(other interface{}) BooleanExpression
// == operator
Equals(other interface{}) BooleanExpression
// < operator
LessThan(other interface{}) BooleanExpression
// <= operator
LessThanOrEquals(other interface{}) BooleanExpression
// > operator
GreaterThan(other interface{}) BooleanExpression
// >= operator
GreaterThanOrEquals(other interface{}) BooleanExpression
IsNull() BooleanExpression
IsNotNull() BooleanExpression
IsTrue() BooleanExpression
IsNotTrue() BooleanExpression
IsFalse() BooleanExpression
IsNotFalse() BooleanExpression
In(values ...interface{}) BooleanExpression
NotIn(values ...interface{}) BooleanExpression
Between(min interface{}, max interface{}) BooleanExpression
NotBetween(min interface{}, max interface{}) BooleanExpression
Desc() OrderBy
As(alias string) Alias
If(trueValue interface{}, falseValue interface{}) UnknownExpression
IfNull(altValue interface{}) UnknownExpression
// contains filtered or unexported methods
}
Expression is the interface of an SQL expression.
type Field ¶
type Field interface {
Expression
GetTable() Table
}
Field is the interface of a generated field.
type InterceptorFunc ¶
type InterceptorFunc = func(ctx context.Context, sql string, invoker InvokerFunc) error
InterceptorFunc is the function type of an interceptor. An interceptor should implement this function to fulfill it's purpose.
type InvokerFunc ¶
InvokerFunc is the function type of the actual invoker. It should be called in an interceptor.
type Model ¶
type Model interface {
GetTable() Table
GetValues() []interface{}
}
Model is the interface of generated model struct
type NumberExpression ¶
type NumberExpression interface {
Expression
Add(other interface{}) NumberExpression
Sub(other interface{}) NumberExpression
Mul(other interface{}) NumberExpression
Div(other interface{}) NumberExpression
IntDiv(other interface{}) NumberExpression
Mod(other interface{}) NumberExpression
Sum() NumberExpression
Avg() NumberExpression
Min() UnknownExpression
Max() UnknownExpression
}
NumberExpression is the interface of an SQL expression with number value.
func Count ¶
func Count(arg interface{}) NumberExpression
Count creates an expression of COUNT aggregator.
func Length ¶
func Length(arg interface{}) NumberExpression
Length creates an expression of LENGTH function.
type NumberField ¶
type NumberField interface {
NumberExpression
GetTable() Table
}
NumberField is the interface of a generated field of number type.
func NewNumberField ¶
func NewNumberField(table Table, fieldName string) NumberField
NewNumberField creates a reference to a number field. It should only be called from generated code.
type Scanner ¶
type Scanner interface {
Scan(dest ...interface{}) error
}
Scanner is the interface that wraps the Scan method.
type StringExpression ¶
type StringExpression interface {
Expression
Min() UnknownExpression
Max() UnknownExpression
Like(other interface{}) BooleanExpression
Contains(substring string) BooleanExpression
Concat(other interface{}) StringExpression
IfEmpty(altValue interface{}) StringExpression
IsEmpty() BooleanExpression
Lower() StringExpression
Upper() StringExpression
Left(count interface{}) StringExpression
Right(count interface{}) StringExpression
Trim() StringExpression
}
StringExpression is the interface of an SQL expression with string value.
func Concat ¶
func Concat(args ...interface{}) StringExpression
Concat creates an expression of CONCAT function.
type StringField ¶
type StringField interface {
StringExpression
GetTable() Table
}
StringField is the interface of a generated field of string type.
func NewStringField ¶
func NewStringField(table Table, fieldName string) StringField
NewStringField creates a reference to a string field. It should only be called from generated code.
type Transaction ¶
type Transaction interface {
GetDB() *sql.DB
GetTx() *sql.Tx
Query(sql string) (Cursor, error)
Execute(sql string) (sql.Result, error)
Select(fields ...interface{}) selectWithFields
SelectDistinct(fields ...interface{}) selectWithFields
SelectFrom(tables ...Table) selectWithTables
InsertInto(table Table) insertWithTable
Update(table Table) updateWithSet
DeleteFrom(table Table) deleteWithTable
}
Transaction is the interface of a transaction with underlying sql.Tx object. It provides methods to execute DDL and TCL operations.
type UnknownExpression ¶
type UnknownExpression interface {
Expression
And(other interface{}) BooleanExpression
Or(other interface{}) BooleanExpression
Xor(other interface{}) BooleanExpression
Not() BooleanExpression
Add(other interface{}) NumberExpression
Sub(other interface{}) NumberExpression
Mul(other interface{}) NumberExpression
Div(other interface{}) NumberExpression
IntDiv(other interface{}) NumberExpression
Mod(other interface{}) NumberExpression
Sum() NumberExpression
Avg() NumberExpression
Min() UnknownExpression
Max() UnknownExpression
Like(other interface{}) BooleanExpression
Contains(substring string) BooleanExpression
Concat(other interface{}) StringExpression
IfEmpty(altValue interface{}) StringExpression
IsEmpty() BooleanExpression
Lower() StringExpression
Upper() StringExpression
Left(count interface{}) StringExpression
Right(count interface{}) StringExpression
Trim() StringExpression
}
UnknownExpression is the interface of an SQL expression with unknown value.
func Function ¶
func Function(name string, args ...interface{}) UnknownExpression
Function creates an expression of the call to specified function.
func If ¶
func If(predicate Expression, trueValue interface{}, falseValue interface{}) (result UnknownExpression)
If creates an expression of IF function.
type WellKnownBinary ¶
type WellKnownBinary []byte
WellKnownBinary is the type of geometry well-known binary (WKB) field.
type WellKnownBinaryExpression ¶
type WellKnownBinaryExpression interface {
Expression
STAsText() StringExpression
}
WellKnownBinaryExpression is the interface of an SQL expression with binary geometry (WKB) value.
func STGeomFromText ¶
func STGeomFromText(text interface{}) WellKnownBinaryExpression
func STGeomFromTextf ¶
func STGeomFromTextf(format string, a ...interface{}) WellKnownBinaryExpression
type WellKnownBinaryField ¶
type WellKnownBinaryField interface {
WellKnownBinaryExpression
GetTable() Table
}
WellKnownBinaryField is the interface of a generated field of binary geometry (WKB) type.
func NewWellKnownBinaryField ¶
func NewWellKnownBinaryField(table Table, fieldName string) WellKnownBinaryField
NewWellKnownBinaryField creates a reference to a geometry WKB field. It should only be called from generated code.