Documentation ¶
Index ¶
- Constants
- Variables
- func CompileTemplate(template string) (string, []string, error)
- func DumpResult(result sql.Result) string
- func DumpRows(rows *sql.Rows) string
- func FormatSqlValue(dbType ansi.DbType, v interface{}) string
- func Read(rows *sql.Rows, dest interface{}) error
- func ReadRow(rows *sql.Rows, dest interface{}) error
- func ReadRowScan(rows *sql.Rows, dest ...interface{}) error
- func RegisterCompiler(driver string, compiler Compiler)
- func RegisterDSN(name, driver, source string)
- func RegisterDialecter(driver string, dialecter Dialecter)
- func RegisterSchemaer(driver string, schemaer Schemaer)
- func SafeSql(v string) string
- type Aggregate
- type AnsiDialecter
- func (ansi AnsiDialecter) ColumnsSql(name string) string
- func (ad AnsiDialecter) DbType(nativeType string) ansi.DbType
- func (ad AnsiDialecter) FunctionSql(s string) string
- func (ad AnsiDialecter) Name() string
- func (ad AnsiDialecter) ParameterPlaceHolder() string
- func (ad AnsiDialecter) ParametersSql(name string) string
- func (ad AnsiDialecter) Quote(s string) string
- func (ad AnsiDialecter) QuoteString(s string) string
- func (ad AnsiDialecter) SplitStatement() string
- func (ad AnsiDialecter) SupportIndexedParameter() bool
- func (ad AnsiDialecter) SupportNamedParameter() bool
- func (ansi AnsiDialecter) TableSql(name string) string
- type Column
- type Compiler
- type Condition
- type Conditions
- func (c *Conditions) And() *Conditions
- func (c *Conditions) CloseParentheses() *Conditions
- func (c *Conditions) Compare(op Operator, column string, value interface{}) *Conditions
- func (c *Conditions) Condition(op Operator, left, right Expression) *Conditions
- func (c *Conditions) Equals(column string, value interface{}) *Conditions
- func (c *Conditions) Exists(exp Expression) *Conditions
- func (c *Conditions) GreaterOrEquals(column string, value interface{}) *Conditions
- func (c *Conditions) GreaterThan(column string, value interface{}) *Conditions
- func (c *Conditions) In(column string, value interface{}) *Conditions
- func (c *Conditions) IsNotNull(column string) *Conditions
- func (c *Conditions) IsNull(column string) *Conditions
- func (c *Conditions) LessOrEquals(column string, value interface{}) *Conditions
- func (c *Conditions) LessThan(column string, value interface{}) *Conditions
- func (c *Conditions) Like(column string, value string) *Conditions
- func (c *Conditions) NotEquals(column string, value interface{}) *Conditions
- func (c *Conditions) NotExists(exp Expression) *Conditions
- func (c *Conditions) NotIn(column string, value interface{}) *Conditions
- func (c *Conditions) NotLike(column string, value string) *Conditions
- func (c *Conditions) OpenParentheses() *Conditions
- func (c *Conditions) Or() *Conditions
- func (c *Conditions) Sql(sqlStr string) *Conditions
- func (c *Conditions) String() string
- type DB
- func (db *DB) Close() error
- func (db *DB) Compile(exp Expression) (sql string, args []interface{}, err error)
- func (db *DB) DB() *sql.DB
- func (db *DB) Delete(table string, conditions ...interface{}) (sql.Result, error)
- func (db *DB) DeleteByCol(table string, column string, value interface{}) (sql.Result, error)
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecExp(exp Expression) (sql.Result, error)
- func (db *DB) ExecFunc(name string, args Getter) (sql.Result, error)
- func (db *DB) ExecText(query string, args Getter) (sql.Result, error)
- func (db *DB) Function(name string) (fn *ansi.DbFunction, err error)
- func (db *DB) Insert(table string, data Getter) (sql.Result, error)
- func (db *DB) Open() error
- func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (db *DB) QueryExp(exp Expression) (*sql.Rows, error)
- func (db *DB) QueryFunc(name string, args Getter) (*sql.Rows, error)
- func (db *DB) QueryText(template string, args Getter) (*sql.Rows, error)
- func (db *DB) SelectAll(table string, conditions ...interface{}) (*sql.Rows, error)
- func (db *DB) SelectCount(table string, conditions ...interface{}) (count int64, err error)
- func (db *DB) SelectExists(table string, conditions ...interface{}) (bool, error)
- func (db *DB) Table(name string) (table *ansi.DbTable, err error)
- func (db *DB) Update(table string, data Getter, conditions ...interface{}) (sql.Result, error)
- func (db *DB) UpdateColumn(table string, column string, value interface{}, conditions ...interface{}) (int64, error)
- type DSN
- type Delete
- type Dialecter
- type Driver
- type Expression
- type Field
- type From
- func (f *From) CrossJoin(toTable, toTableAlias string) *Join
- func (f *From) FindTable(name string) *Table
- func (f *From) InnerJoin(toTable, toTableAlias string) *Join
- func (f *From) Join(join *Join) *From
- func (f *From) LeftJoin(toTable, toTableAlias string) *Join
- func (f *From) Node() NodeType
- func (f *From) RightJoin(toTable, toTableAlias string) *Join
- func (f *From) String() string
- func (f *From) ThenFrom(table, alias string) *From
- type Func
- type GEntity
- type Getter
- type GroupBy
- type Having
- func (h *Having) Avg(op Operator, column string, value interface{}) *Having
- func (h *Having) Count(op Operator, column string, value interface{}) *Having
- func (h *Having) Max(op Operator, column string, value interface{}) *Having
- func (h *Having) Min(op Operator, column string, value interface{}) *Having
- func (h *Having) Node() NodeType
- func (h *Having) String() string
- func (h *Having) Sum(op Operator, column string, value interface{}) *Having
- type Insert
- type Iterater
- type Join
- type JoinType
- type Map
- type MssqlDialecter
- func (mssql MssqlDialecter) ColumnsSql(name string) string
- func (mssql MssqlDialecter) FunctionSql(name string) string
- func (mssql MssqlDialecter) Name() string
- func (mssql MssqlDialecter) ParametersSql(name string) string
- func (mssql MssqlDialecter) Quote(s string) string
- func (mssql MssqlDialecter) TableSql(name string) string
- type MysqlDialecter
- func (mysql MysqlDialecter) ColumnsSql(name string) string
- func (mysql MysqlDialecter) FunctionSql(name string) string
- func (mysql MysqlDialecter) Name() string
- func (mysql MysqlDialecter) ParametersSql(name string) string
- func (mysql MysqlDialecter) Quote(s string) string
- func (mysql MysqlDialecter) QuoteString(s string) string
- func (mysql MysqlDialecter) TableSql(name string) string
- type NodeType
- type Null
- type Operator
- type OracleSQLDialecter
- func (oracle OracleSQLDialecter) ColumnsSql(name string) string
- func (oracle OracleSQLDialecter) FunctionSql(name string) string
- func (oracle OracleSQLDialecter) Name() string
- func (oracle OracleSQLDialecter) ParameterPlaceHolder() string
- func (oracle OracleSQLDialecter) ParametersSql(name string) string
- func (oracle OracleSQLDialecter) Quote(s string) string
- func (oracle OracleSQLDialecter) SplitStatement() string
- func (oracle OracleSQLDialecter) SupportIndexedParameter() bool
- func (oracle OracleSQLDialecter) SupportNamedParameter() bool
- func (oracle OracleSQLDialecter) TableSql(name string) string
- type OrderBy
- type OrderByField
- type Parameter
- type PostgreSQLDialecter
- func (pgsql PostgreSQLDialecter) ColumnsSql(name string) string
- func (pgsql PostgreSQLDialecter) FunctionSql(name string) string
- func (pgsql PostgreSQLDialecter) Name() string
- func (pgsql PostgreSQLDialecter) ParameterPlaceHolder() string
- func (pgsql PostgreSQLDialecter) ParametersSql(name string) string
- func (pgsql PostgreSQLDialecter) Quote(s string) string
- func (pgsql PostgreSQLDialecter) QuoteString(s string) string
- func (pgsql PostgreSQLDialecter) SupportIndexedParameter() bool
- func (pgsql PostgreSQLDialecter) TableSql(name string) string
- type Procedure
- func (pc *Procedure) FindParameter(name string) (*Parameter, bool)
- func (t *Procedure) HasOutParameter() bool
- func (pc *Procedure) Node() NodeType
- func (pc *Procedure) Parameter(p *Parameter)
- func (pc *Procedure) ReturnParameterName() string
- func (pc *Procedure) Set(name string, value interface{}) *Procedure
- func (pc *Procedure) SetDir(name string, value interface{}, dir ansi.Dir) *Procedure
- func (pc *Procedure) String() string
- type Query
- type RawSqler
- type Schemaer
- type Select
- func (s *Select) Aggregate(name Func, exp Expression, alias string) *Select
- func (s *Select) All() *Select
- func (s *Select) Avg(column string, alias string) *Select
- func (s *Select) Column(columns ...string) *Select
- func (s *Select) ColumnAs(column, alias string) *Select
- func (s *Select) Count(column string, alias string) *Select
- func (s *Select) Exp(exp Expression, alias string) *Select
- func (s *Select) Max(column string, alias string) *Select
- func (s *Select) Min(column string, alias string) *Select
- func (s *Select) Node() NodeType
- func (s *Select) String() string
- func (s *Select) Sum(column string, alias string) *Select
- type Set
- type SortDir
- type Sql
- type SqlDriver
- type SqliteDialecter
- type StmtCompiler
- type Table
- type Text
- type Update
- type Value
- type Where
Constants ¶
const ( // Opened means conection opened Opened state = 3 // Closed means connection closed Closed state = 9 )
const ( // LogNone means doesn't log LogNone int = 0 // LogDebug means log err & debug information LogDebug int = 1 // LogError means log err LogError int = 3 )
Variables ¶
var ErrNoResult = errors.New("rows no result")
ErrNoResult means rows doesn't have result
var ExplictSchema = true
ExplictSchema is true mean must use schema when insert/update
var LogLevel int = 0
LogLevel
var Logger *log.Logger
Logger
Functions ¶
func CompileTemplate ¶
CompileTemplate parse template, return formated template, parameter names
func FormatSqlValue ¶
FormatSqlValue format v to native sql according dbType
func Read ¶
Read iterate rows and scan value to dest. dest can be *[]T, *[]map, *[]sliece, *[]struct.
func ReadRowScan ¶
func RegisterCompiler ¶
RegisterCompiler makes a compiler available by the provided driver name.
func RegisterDialecter ¶
RegisterDialecter makes a dialecter available by the provided driver name.
func RegisterSchemaer ¶
RegisterSchemaer makes a schemaer available by the provided driver name.
Types ¶
type Aggregate ¶
type Aggregate struct { Name Func Exp Expression }
Aggregate is sql aggregate Func
func NewAggregate ¶
func NewAggregate(name Func, exp Expression) *Aggregate
NewAggregate return *Aggregate
type AnsiDialecter ¶
type AnsiDialecter struct { }
AnsiDialecter is ansi sql dialect
func (AnsiDialecter) ColumnsSql ¶
func (ansi AnsiDialecter) ColumnsSql(name string) string
ColumnsSql return sql to query table columns schema
func (AnsiDialecter) FunctionSql ¶
func (ad AnsiDialecter) FunctionSql(s string) string
FunctionSql return ""
func (AnsiDialecter) ParameterPlaceHolder ¶
func (ad AnsiDialecter) ParameterPlaceHolder() string
ParameterPlaceHolder return ?
func (AnsiDialecter) ParametersSql ¶
func (ad AnsiDialecter) ParametersSql(name string) string
ParametersSql return sql to query procedure paramters schema
func (AnsiDialecter) QuoteString ¶
func (ad AnsiDialecter) QuoteString(s string) string
QuoteString quote s as sql native string
func (AnsiDialecter) SplitStatement ¶
func (ad AnsiDialecter) SplitStatement() string
SplitStatement return ;
func (AnsiDialecter) SupportIndexedParameter ¶
func (ad AnsiDialecter) SupportIndexedParameter() bool
SupportIndexedParameter return false
func (AnsiDialecter) SupportNamedParameter ¶
func (ad AnsiDialecter) SupportNamedParameter() bool
SupportNamedParameter return false
func (AnsiDialecter) TableSql ¶
func (ansi AnsiDialecter) TableSql(name string) string
TableSql return ""
type Column ¶
type Column string
Column is an column, like, table.coumn, column, table.*, *
type Compiler ¶
type Compiler interface {
Compile(source string, exp Expression) (query string, args []interface{}, err error)
}
Compiler is a interface that compile expression to native sql & args
func GetCompiler ¶
GetCompiler return a a compiler by driver name
type Condition ¶
type Condition struct { Right Expression Left Expression Op Operator }
Condition is condition in where or having
type Conditions ¶
type Conditions struct { Conditions []Expression // contains filtered or unexported fields }
Conditions is collection of condition
func (*Conditions) CloseParentheses ¶
func (c *Conditions) CloseParentheses() *Conditions
CloseParentheses append a ')'
func (*Conditions) Compare ¶
func (c *Conditions) Compare(op Operator, column string, value interface{}) *Conditions
Compare append compare operation
func (*Conditions) Condition ¶
func (c *Conditions) Condition(op Operator, left, right Expression) *Conditions
Condition append a condition
func (*Conditions) Equals ¶
func (c *Conditions) Equals(column string, value interface{}) *Conditions
GreaterThan append = operation
func (*Conditions) Exists ¶
func (c *Conditions) Exists(exp Expression) *Conditions
Exists append operation Exists
func (*Conditions) GreaterOrEquals ¶
func (c *Conditions) GreaterOrEquals(column string, value interface{}) *Conditions
GreaterOrEquals append >= operation
func (*Conditions) GreaterThan ¶
func (c *Conditions) GreaterThan(column string, value interface{}) *Conditions
GreaterThan append > operation
func (*Conditions) In ¶
func (c *Conditions) In(column string, value interface{}) *Conditions
In append in(...) operation
func (*Conditions) IsNotNull ¶
func (c *Conditions) IsNotNull(column string) *Conditions
IsNotNull append is not null operation
func (*Conditions) IsNull ¶
func (c *Conditions) IsNull(column string) *Conditions
IsNull append is null operation
func (*Conditions) LessOrEquals ¶
func (c *Conditions) LessOrEquals(column string, value interface{}) *Conditions
LessOrEquals append <= operation
func (*Conditions) LessThan ¶
func (c *Conditions) LessThan(column string, value interface{}) *Conditions
LessThan append < operation
func (*Conditions) Like ¶
func (c *Conditions) Like(column string, value string) *Conditions
Like append Like operation
func (*Conditions) NotEquals ¶
func (c *Conditions) NotEquals(column string, value interface{}) *Conditions
NotEquals append <> operation
func (*Conditions) NotExists ¶
func (c *Conditions) NotExists(exp Expression) *Conditions
NotExists append operation NotExists
func (*Conditions) NotIn ¶
func (c *Conditions) NotIn(column string, value interface{}) *Conditions
NotIn append not in(...) operation
func (*Conditions) NotLike ¶
func (c *Conditions) NotLike(column string, value string) *Conditions
NotLike append NotLike operation
func (*Conditions) OpenParentheses ¶
func (c *Conditions) OpenParentheses() *Conditions
OpenParentheses append a '('
type DB ¶
type DB struct { DSN *DSN // contains filtered or unexported fields }
DB is wrap of *sql.DB
func (*DB) Compile ¶
func (db *DB) Compile(exp Expression) (sql string, args []interface{}, err error)
Compile compile expression to native sql
func (*DB) Delete ¶
Delete delete table by conditions, conditions format is column, operator, value, ...
func (*DB) DeleteByCol ¶
DeleteByCol delete table with condition column = value
func (*DB) ExecExp ¶
func (db *DB) ExecExp(exp Expression) (sql.Result, error)
ExecExp execute a expression
func (*DB) Function ¶
func (db *DB) Function(name string) (fn *ansi.DbFunction, err error)
Function return schema of store procedure
func (*DB) QueryExp ¶
func (db *DB) QueryExp(exp Expression) (*sql.Rows, error)
QueryExp query a expression
func (*DB) SelectAll ¶
SelectAll return table.* by conditions, conditions format is column, operator, value, ...
func (*DB) SelectCount ¶
SelectCount query select count(*) from [table] where conditions...
func (*DB) SelectExists ¶
SelectExists return true if exists conditions
type DSN ¶
type DSN struct { // Name is name of data source Name string // Driver is driver name Driver string // Source is driver-specific data source name Source string }
DSN is data souce config
type Delete ¶
type Delete struct { //Table is the table to delete Table *Table // From is from clause From *From // Where is where clause Where *Where // OrderBy is order by clause OrderBy *OrderBy // Count is limit count Count int }
Delete is sql delete clause
func (*Delete) UseOrderBy ¶
UseOrderBy new a *OrderBy and set to d.OrderBy
type Dialecter ¶
type Dialecter interface { // Name return mysql,postgres,oracle,mssql,sqlite,... Name() string // SupportNamedParameter, like @para1 SupportNamedParameter() bool // SupportIndexedParameter, like $1 SupportIndexedParameter() bool // ParameterPlaceHolder, like ?, $, @ ParameterPlaceHolder() string // QuoteString quote s as sql native string QuoteString(s string) string // Quote quote object name, like 'table', [table] Quote(string) string // TableSql return sql to query table schema of name TableSql(name string) string // ColumnsSql return sql to query table columns schema ColumnsSql(name string) string // FunctionSql return sql to query function schema of name FunctionSql(name string) string // ParametersSql return sql to query procedure paramters schema ParametersSql(name string) string // DbType convert native data type to ansi.DbType DbType(nativeType string) ansi.DbType // SplitStatement return string to split sql statement; return ; generally SplitStatement() string }
Dialecter is interface of sql dialect
func GetDialecter ¶
GetDialecter return a a dialecter by driver name
type Expression ¶
type Expression interface {
Node() NodeType
}
Expression is interface of sql expression
type Field ¶
type Field struct { Exp Expression Alias string }
Field is each field in sql select clause
type From ¶
From is sql from clause
type GEntity ¶
type GEntity struct { Data interface{} // contains filtered or unexported fields }
GEntity wrap a struct, provide interface Getter and Iterater
type Getter ¶
type Getter interface { // Get return inner field value by name, return [nil, false] if name doesn't exist Get(name string) (interface{}, bool) }
Getter is wrap of Get(name string) (interface{}, bool)
type Having ¶
type Having struct {
*Conditions
}
Having is sql having clause
type Insert ¶
type Insert struct { // Table is table to insert Table *Table // Sets is set[column=value] Sets []*Set }
Insert is sql "insert into x values(...)" clause
type Iterater ¶
type Iterater interface { // Fields return all field name Fields() []string }
Iterater iterat fields
type Join ¶
type Join struct { JoinType JoinType Left *Table Right *Table *Conditions }
Join is sql join clause
func NewJoinTable ¶
NewJoinTable means [left] join [right]
type MssqlDialecter ¶
type MssqlDialecter struct {
AnsiDialecter
}
MssqlDialecter is ms sql server dialect
func (MssqlDialecter) ColumnsSql ¶
func (mssql MssqlDialecter) ColumnsSql(name string) string
ColumnsSql return sql to query table columns schema
func (MssqlDialecter) FunctionSql ¶
func (mssql MssqlDialecter) FunctionSql(name string) string
FunctionSql return sql to query procedure schema
func (MssqlDialecter) ParametersSql ¶
func (mssql MssqlDialecter) ParametersSql(name string) string
ParametersSql return sql to query procedure paramters schema
func (MssqlDialecter) Quote ¶
func (mssql MssqlDialecter) Quote(s string) string
Quote quote s as [s]
func (MssqlDialecter) TableSql ¶
func (mssql MssqlDialecter) TableSql(name string) string
TableSql return sql to query table schema
type MysqlDialecter ¶
type MysqlDialecter struct {
AnsiDialecter
}
MysqlDialecter is Mysql dialect
func (MysqlDialecter) ColumnsSql ¶
func (mysql MysqlDialecter) ColumnsSql(name string) string
ColumnsSql return sql to query table columns schema
func (MysqlDialecter) FunctionSql ¶
func (mysql MysqlDialecter) FunctionSql(name string) string
FunctionSql return sql to query procedure schema
func (MysqlDialecter) ParametersSql ¶
func (mysql MysqlDialecter) ParametersSql(name string) string
ParametersSql return sql to query procedure paramters schema
func (MysqlDialecter) Quote ¶
func (mysql MysqlDialecter) Quote(s string) string
Quote quote s as 's'
func (MysqlDialecter) QuoteString ¶
func (mysql MysqlDialecter) QuoteString(s string) string
QuoteString quote s as sql native string
func (MysqlDialecter) TableSql ¶
func (mysql MysqlDialecter) TableSql(name string) string
TableSql return sql to query table schema
type NodeType ¶
type NodeType int
NodeType
const ( NodeZero NodeType = 0 NodeText NodeType = 1 NodeProcedure NodeType = 2 NodeInsert NodeType = 3 NodeQuery NodeType = 4 NodeUpdate NodeType = 5 NodeDelete NodeType = 6 NodeNull NodeType = 11 NodeValue NodeType = 12 NodeSql NodeType = 13 NodeTable NodeType = 31 NodeColumn NodeType = 32 NodeAlias NodeType = 33 NodeCondition NodeType = 34 NodeSet NodeType = 35 NodeAggregate NodeType = 36 NodeSelect NodeType = 41 NodeFrom NodeType = 42 NodeJoin NodeType = 43 NodeWhere NodeType = 44 NodeGroupBy NodeType = 45 NodeHaving NodeType = 46 NodeOrderBy NodeType = 47 NodeOutput NodeType = 48 NodeOperator = 61 NodeFunc = 62 NodeParameter = 63 )
type Operator ¶
type Operator string
Operator is operator in sql
const ( IsNull Operator = ansi.IsNull IsNotNull Operator = ansi.IsNotNull LessThan Operator = ansi.LessThan LessOrEquals Operator = ansi.LessOrEquals GreaterThan Operator = ansi.GreaterThan GreaterOrEquals Operator = ansi.GreaterOrEquals Equals Operator = ansi.Equals NotEquals Operator = ansi.NotEquals Like Operator = ansi.Like NotLike Operator = ansi.NotLike In Operator = ansi.In NotIn Operator = ansi.NotIn Exists Operator = ansi.Exists NotExists Operator = ansi.NotExists All Operator = ansi.All Some Operator = ansi.Some Any Operator = ansi.Any And Operator = ansi.And Or Operator = ansi.Or OpenParentheses Operator = ansi.OpenParentheses CloseParentheses Operator = ansi.CloseParentheses )
type OracleSQLDialecter ¶
type OracleSQLDialecter struct {
AnsiDialecter
}
OracleSQLDialecter is oracle dialect
func (OracleSQLDialecter) ColumnsSql ¶
func (oracle OracleSQLDialecter) ColumnsSql(name string) string
Columns return sql to query table columns schema
func (OracleSQLDialecter) FunctionSql ¶
func (oracle OracleSQLDialecter) FunctionSql(name string) string
Function return sql to query procedure schema
func (OracleSQLDialecter) Name ¶
func (oracle OracleSQLDialecter) Name() string
Name return "oracle"
func (OracleSQLDialecter) ParameterPlaceHolder ¶
func (oracle OracleSQLDialecter) ParameterPlaceHolder() string
ParameterPlaceHolder return :
func (OracleSQLDialecter) ParametersSql ¶
func (oracle OracleSQLDialecter) ParametersSql(name string) string
Parameters return sql to query procedure paramters schema
func (OracleSQLDialecter) Quote ¶
func (oracle OracleSQLDialecter) Quote(s string) string
Quote doesn't quote identifier
func (OracleSQLDialecter) SplitStatement ¶
func (oracle OracleSQLDialecter) SplitStatement() string
SplitStatement return nothing
func (OracleSQLDialecter) SupportIndexedParameter ¶
func (oracle OracleSQLDialecter) SupportIndexedParameter() bool
SupportIndexedParameter regturn true
func (OracleSQLDialecter) SupportNamedParameter ¶
func (oracle OracleSQLDialecter) SupportNamedParameter() bool
SupportNamedParameter return true
func (OracleSQLDialecter) TableSql ¶
func (oracle OracleSQLDialecter) TableSql(name string) string
Table return sql to query table schema
type OrderBy ¶
type OrderBy struct {
Fields []*OrderByField
}
OrderBy is sql order by clause
func (*OrderBy) By ¶
func (od *OrderBy) By(direction SortDir, exp Expression) *OrderBy
By append a orderby field with direction
type OrderByField ¶
type OrderByField struct { Exp Expression Direction SortDir }
OrderByField is each field in sql order by clause
type Parameter ¶
type Parameter struct { // Name is parameter name, some driver don't support named parameter Name string // Value is value of this parameter Value interface{} // Dir is direction, in,out, inout or return Dir ansi.Dir }
Parameter is parameter of sql statement or store procedure
type PostgreSQLDialecter ¶
type PostgreSQLDialecter struct {
AnsiDialecter
}
PostgreSQLDialecter is PostgreSQL dialect
func (PostgreSQLDialecter) ColumnsSql ¶
func (pgsql PostgreSQLDialecter) ColumnsSql(name string) string
Columns return sql to query table columns schema
func (PostgreSQLDialecter) FunctionSql ¶
func (pgsql PostgreSQLDialecter) FunctionSql(name string) string
Function return sql to query procedure schema
func (PostgreSQLDialecter) Name ¶
func (pgsql PostgreSQLDialecter) Name() string
Name return "postgres"
func (PostgreSQLDialecter) ParameterPlaceHolder ¶
func (pgsql PostgreSQLDialecter) ParameterPlaceHolder() string
ParameterPlaceHolder return $
func (PostgreSQLDialecter) ParametersSql ¶
func (pgsql PostgreSQLDialecter) ParametersSql(name string) string
Parameters return sql to query procedure paramters schema
func (PostgreSQLDialecter) Quote ¶
func (pgsql PostgreSQLDialecter) Quote(s string) string
Quote quote s as 's'
func (PostgreSQLDialecter) QuoteString ¶
func (pgsql PostgreSQLDialecter) QuoteString(s string) string
QuoteString quote s as sql native string
func (PostgreSQLDialecter) SupportIndexedParameter ¶
func (pgsql PostgreSQLDialecter) SupportIndexedParameter() bool
SupportIndexedParameter regturn true
func (PostgreSQLDialecter) TableSql ¶
func (pgsql PostgreSQLDialecter) TableSql(name string) string
Table return sql to query table schema
type Procedure ¶
type Procedure struct { // Name is name of store procedure ot function Name string // Parameters is parameters of store procedure Parameters []*Parameter }
Procedure is sql store procedure
func NewProcedure ¶
NewProcedure return a *Procedure with provided name
func (*Procedure) FindParameter ¶
FindParameter return a parameter by name
func (*Procedure) HasOutParameter ¶
HasOutParameter return true if any parameter is output/inputoutput
func (*Procedure) ReturnParameterName ¶
ReturnParameterName return parameter name if parameter is ansi.DirReturn
type Query ¶
type Query struct { Select *Select From *From Where *Where GroupBy *GroupBy Having *Having OrderBy *OrderBy IsDistinct bool Offset int Count int }
Query is sql query clause
func (*Query) UseGroupBy ¶
UseGroupBy initialize q.GroupBy then return it
func (*Query) UseOrderBy ¶
UseOrderBy initialize q.OrderBy then return it
type RawSqler ¶
type RawSqler interface { // ToSql return native sql ToSql() string }
RawSqler is wrap of ToSql() string
type Schemaer ¶
type Schemaer interface { // Table return schema of table,view Table(db *sql.DB, name string) (*ansi.DbTable, error) // Function return schema of store procedure,function Function(db *sql.DB, name string) (*ansi.DbFunction, error) }
Schemaer is a interface that get schema of table,view,function
func GetSchemaer ¶
GetSchemaer return a a schemaer by driver name
type Select ¶
type Select struct {
Fields []*Field
}
Select is sql select clause
func (*Select) Aggregate ¶
func (s *Select) Aggregate(name Func, exp Expression, alias string) *Select
Aggregate append a aggregate function
type SqliteDialecter ¶
type SqliteDialecter struct {
AnsiDialecter
}
SqliteDialecter is sqlite dialect
func (SqliteDialecter) Function ¶
func (sqlite SqliteDialecter) Function(db *sql.DB, name string) (*ansi.DbFunction, error)
Function return schema of store procedure,function
type StmtCompiler ¶
type StmtCompiler struct { // Dialecter is a provided Dialecter Dialecter Dialecter // contains filtered or unexported fields }
StmtCompiler can compile Update, Insert, Delete, Query
func NewStmtCompiler ¶
func NewStmtCompiler(dialecter Dialecter) *StmtCompiler
NewStmtCompiler return *StmtCompiler with provided Dialecter
func (*StmtCompiler) Compile ¶
func (sc *StmtCompiler) Compile(exp Expression, source string) (query string, args []interface{}, err error)
Compile compile expression to ansi sql
type Text ¶
type Text struct { // Sql is raw sql statement Sql string // Parameters is parameters of Sql Parameters []*Parameter }
Text is sql statement
func (*Text) FindParameter ¶
FindParameter return a paramter by name
type Update ¶
type Update struct { //T able is table to update Table *Table // Sets is set[column=value] Sets []*Set // Where is where clause Where *Where // OrderBy is order by clause OrderBy *OrderBy // Count is limit count Count int }
Update is sql update clause