Documentation ¶
Index ¶
- Variables
- type BasicDB
- type BasicEntity
- type DSField
- type DSFields
- type DataSetFieldDef
- type Database
- type DatabaseInitializer
- type Dataset
- type DatasetRow
- type DbConfig
- type DbConfigCluster
- type DbConn
- type DbLogger
- type DbMysqlConfig
- type DbQueryBinder
- type DbType
- type DbTypeS
- type DbTypeSD
- type EFBinary
- type EFBool
- type EFByte
- type EFDate
- type EFDouble
- type EFExpr
- type EFFloat
- type EFForeign
- type EFInt
- type EFInt16
- type EFInt32
- type EFInt64
- type EFInt8
- type EFString
- type EFUint
- type EFUint16
- type EFUint32
- type EFUint64
- type EFUint8
- type EntField
- type EntFieldIndex
- type Entity
- type EntityAttribute
- type EntityCUD
- type EntityClass
- type EntityDeleteObserver
- type EntityEditor
- type EntityFieldAttribute
- type EntityFieldClass
- type EntityForeignFieldAttribute
- type EntityInsert
- type EntityInsertChecker
- type EntityInsertExecute
- type EntityInsertObserver
- type EntityInsertRule
- type EntityQuery
- type EntityQueryOpen
- type EntitySelect
- type EntitySelectBuilder
- type EntitySelectConvert
- type EntitySelectList
- type EntitySelectPage
- type EntitySelectSingle
- type EntityTrans
- type EntityUpdate
- type EntityUpdateChecker
- type EntityUpdateExecute
- type EntityUpdateObserver
- type EntityUpdateRule
- type FieldConstructor
- type FieldDataType
- type FieldValid
- type FieldValue
- type LazyGetConditionFun
- type LazyGetFieldFun
- type LazyGetJoinConditionFun
- type LazyGetOrderFieldFun
- type MemDataset
- type Query
- type QueryBinderVisit
- type QueryColValue
- type QueryFrom
- type QueryGroup
- type QueryHaving
- type QueryInfo
- type QueryJoin
- type QueryLimit
- type QueryOrder
- type QueryPageInfo
- type QuerySelect
- type QueryWhere
- type SCPState
- type SqlAriExp
- type SqlAriType
- type SqlCase
- type SqlCaseThenElse
- type SqlCompareType
- type SqlCompileContext
- type SqlCompiler
- type SqlCondition
- type SqlConditionItem
- type SqlConditionLogic
- type SqlField
- type SqlFun
- type SqlFunId
- type SqlInsertExp
- type SqlInsertExpInfo
- type SqlJoin
- type SqlJoinItem
- type SqlJoinType
- type SqlLogic
- type SqlOrderDirect
- type SqlOrderField
- type SqlQuery
- type SqlStaticExpr
- type SqlTable
- type SqlTableField
- type SqlTableFields
- type SqlTables
- type SqlToken
- type SqlTokenType
- type SqlUpdateExp
- type SqlUpdateExpInfo
- type SqlVarExpr
- type TBinderName
- type TQueryColDef
- type TQueryColInfo
- type TQueryColValue
- type XqAttribute
- type XqAttributeMap
Constants ¶
This section is empty.
Variables ¶
View Source
var ( MapBinder = BinderName("map") JsonBinder = BinderName("json") XmlBinder = BinderName("xml") DatasetBinder = BinderName("dataset") SliceBinder = BinderName("slice") )
View Source
var FuncNameMapSqlFunId = map[string]SqlFunId{ "case": SFCase, "Substring": SFSubString, "FromBase64": SFFromBase64, "ToBase64": SFToBase64, "Concat": SFConcat, "substring": SFSubString, "DateAdd": SFDateAdd, "dateAdd": SFDateAdd, "DateSub": SFDateSub, "dateSub": SFDateSub, "DateFormat": SFDateFormat, "dateFormat": SFDateFormat, "DateDiff": SFDateDiff, "dateDiff": SFDateDiff, "DateToUnix": SFDateToUnix, "dateToUnix": SFDateToUnix, "UnixToDate": SFUnixToDate, "unixToDate": SFUnixToDate, "count": SFCount, "Count": SFCount, "max": SFMax, "Max": SFMax, "min": SFMin, "Min": SFMin, "avg": SFAvg, "Avg": SFAvg, "sum": SFSum, "Sum": SFSum, }
View Source
var SqlCompareTypeExps = map[SqlCompareType]string{ SqlCompareEQType: " = ", SqlCompareNEQType: " <> ", SqlCompareGTType: " > ", SqlCompareGTEType: " >= ", SqlCompareLTType: " < ", SqlCompareLTEType: " <= ", SqlCompareLKType: " like ", SqlCompareNLKType: " not like ", SqlCompareINType: " in ", SqlCompareNINType: " not in ", SqlCompareNTType: " not ", }
View Source
var SqlConditionLogicNames = map[SqlConditionLogic]string{ SqlConditionEqLogic: " = ", SqlConditionNeqLogic: " <> ", SqlConditionGtLogic: " > ", SqlConditionGteLogic: " >= ", SqlConditionLtLogic: " < ", SqlConditionLteLogic: " <= ", SqlConditionLkLogic: " LIKE ", SqlConditionNlkLogic: " NOT LIKE ", SqlConditionInLogic: " IN ", SqlConditionNinLogic: " NOT IN ", SqlConditionAndLogic: " AND ", SqlConditionOrLogic: " OR ", SqlConditionXorLogic: " XOR ", }
View Source
var SqlFunIdNames = map[SqlFunId]string{ SFCase: "case", SFSubString: "Substring", SFFromBase64: "FromBase64", SFToBase64: "ToBase64", SFConcat: "Concat", SFDateAdd: "DateAdd", SFDateSub: "DateSub", SFDateFormat: "DateFormat", SFDateDiff: "DateDiff", SFDateToUnix: "DateToUnix", SFUnixToDate: "UnixToDate", SFCount: "count", SFMax: "max", SFMin: "min", SFAvg: "avg", SFSum: "sum", }
View Source
var SqlJoinTypeExps = map[SqlJoinType]string{ SqlInnerJoinType: " JOIN ", SqlLeftJoinType: " LEFT JOIN ", SqlRightJoinType: " RIGHT JOIN ", SqlCrossJoinType: " CROSS JOIN ", }
View Source
var SqlOrderDirectExps = map[SqlOrderDirect]string{ SqlOrderAscDirect: " ASC ", SqlOrderDescDirect: " DESC ", }
View Source
var SqlTokenTypeNames = map[SqlTokenType]string{ SqlStaticTokenType: "staticToken", SqlVarTokenType: "varToken", SqlFieldTokenType: "fieldToken", SqlFieldAssignTokenType: "fieldAssignToken", SqlTableTokenType: "tableToken", SqlOrderFieldTokenType: "orderFieldToken", SqlArithmeticTokenType: "arithmeticToken", SqlConditionTokenType: "conditionToken", SqlConditionItemTokenType: "conditionItemToken", SqlFunExpressTokenType: "funExpressToken", SqlAggregateFunTokenType: "aggregateFunToken", SqlExpressTokenType: "sqlExpressToken", SqlQueryTokenType: "queryToken", SqlInsertTokenType: "insertToken", SqlUpdateTokenType: "updateToken", }
Functions ¶
This section is empty.
Types ¶
type BasicDB ¶
type BasicDB interface { Close() BeginTran() (err exception.IException) Rollback() (err exception.IException) Commit() (err exception.IException) Transaction(closers ...func(session BasicDB) error) (err exception.IException) // 查询数据并使用指定的binder数据绑定器序列化数据后返回,binder绑定器名称格式为 binderName:options, // 不传options时写为binderName,options格式支持yaml,json,xml,toml格式 Query(binder TBinderName, szSql string, args ...interface{}) (result interface{}, err exception.IException) QueryBind(binder DbQueryBinder, szSql string, args ...interface{}) (result interface{}, err exception.IException) //Query(makeRowFn func(row int, colInfos *[]QueryColValue) interface{}, szSql string, args ...interface{}) (interface{}, error) Execute(szSql string, args ...interface{}) (int64, exception.IException) GetConn() DbConn LastInsertId() int64 LastSql() string This() interface{} // 最后执行消耗时间 LastSqlDuration() time.Duration }
type BasicEntity ¶
type DSField ¶
type DSField interface { FieldName() string FieldType() FieldDataType FieldIndex() int Value() interface{} }
type DataSetFieldDef ¶
type DataSetFieldDef struct { FieldName string FieldType FieldDataType }
type Database ¶
type Database interface { BasicDB DatabaseInitializer Logger() DbLogger Conn() DbConn // 表前掇 Prefix() string // 数据库驱动名称 Driver() string // 创建数据库表 Create() exception.IException // 升级数据库表 Upgrade() exception.IException }
type DatabaseInitializer ¶
type DatabaseInitializer interface { Connection(conf ...interface{}) exception.IException Use(closers ...func(e DbConn)) }
type Dataset ¶
type Dataset interface { IsOpen() bool Close() bool DSField(index int) DSField DSFieldByName(name string) DSField // 字段值 FieldValue(index int) interface{} // 字段数 FieldCount() int // 记录数 RowCount() int // 第一行记录,无数据时返回false MoveFirst() bool // 最后一行记录,无数据时返回false MoveLast() bool // 下一行数据,无下一行时返回false Next() bool // 上一行数据,无上一行时返回false Prior() bool IsEmpty() bool IsEof() bool IsBof() bool ToMap() []map[string]interface{} MarshalJSON() (data []byte, err error) UnmarshalJSON(data []byte) error }
type DatasetRow ¶
type DbConfig ¶
type DbConfig interface { Driver() string // 驱动: mysql/sqlite3/oracle/mssql/postgres/clickhouse, 如果集群配置了驱动, 这里可以省略 // mysql 示例: // root:root@tcp(localhost:3306)/test?charset=utf8&parseTime=true Dsn() string // 数据库链接 MaxOpenCons() int // (连接池)最大打开的连接数,默认值为0表示不限制 MaxIdleCons() int // (连接池)闲置的连接数, 默认0 Prefix() string // 表前缀, 如果集群配置了前缀, 这里可以省略 This() interface{} String() string LoadFromMap(cfg map[string]interface{}) }
type DbConfigCluster ¶
type DbConfigCluster interface { Master() []DbConfig // 主 Slave() []DbConfig // 从 Driver() string // 驱动 Prefix() string // 前缀 This() interface{} String() string // 添加主数据库连接 AddMaster(config DbConfig) DbConfigCluster // 添加从数据库连接 AddSlave(config DbConfig) DbConfigCluster }
type DbConn ¶
type DbConn interface { // 使用部件 Use(closers ...func(e DbConn)) Ping() exception.IException SetPrefix(pre string) GetPrefix() string GetDriver() string // GetQueryDB : 获取一个从库用来做查询操作 GetQueryDB() *sql.DB // GetExecuteDB : 获取一个主库用来做查询之外的操作 GetExecuteDB() *sql.DB // 获取日志接口 GetLogger() DbLogger SetLogger(log DbLogger) This() interface{} }
type DbMysqlConfig ¶
type DbMysqlConfig interface { DbConfig // 连接协议tcp,udp Protocol() string // 数据库服务器地址 Host() string // 数据库服务器端口号 Port() int // 数据库名称 DbName() string // 账户名 User() string // 密码 Password() string // 字符编码,默认utf-8 Charset() string // 是否解析日期, 默认true ParseTime() bool // 其他连接参数 Params() map[string]string SetOption(host string, port int, user string, password string, db string, protocol ...string) DbMysqlConfig SetDatabase(db string) DbMysqlConfig SetCharset(charset string) DbMysqlConfig SetParseTime(b bool) DbMysqlConfig AddParam(name string, value string) DbMysqlConfig DbConfig() DbConfig }
type DbQueryBinder ¶
type DbQueryBinder interface { SetOptions(options map[string]interface{}) DbQueryBinder // 使用定义参数创建新实例 NewInstance(options ...map[string]interface{}) DbQueryBinder // 开始绑定,返回false时结束绑定 StartBuild(colInfos ...*TQueryColInfo) bool // 开始创建行,返回false忽略该行 // rowIndex: 行序号 // colCount: 总列数 StartBuildRow(rowIndex int, colCount int) bool // 创建行 // row:当前行号 // colInfos行中的列信息 // 返回:result行数据结构,exit: 返回true结束绑定 BuildRow(row int, colInfos *[]QueryColValue) (result interface{}, exit bool) // 行创建完成 // rowData为BuildRow所创建的行数据 EndBuildRow(rowData interface{}) // 绑定完成,返回所有行数据 EndBuild() interface{} //// 字段映射名 // @param qryName 查询字段名 // @return 返回输出需要的字段名 FieldName(colIndex int, qryName string) string // 字段数据转换 // @param qryName 字段名 // @param val 原数据 // @return 返回转换后的数据 FieldConvert(colIndex int, qryName string, val interface{}) interface{} }
type DbType ¶
type DbType interface { GetType() xdriveri.DbDataType GetSize() int GetDecimal() []int }
type EFForeign ¶
type EFForeign interface { EntField // 外联关键字 ForeignKey() string // 连接方式 JoinType() SqlJoinType JoinTable() SqlTable LookField() SqlField On() func(on SqlCondition, joinEnt interface{}, tables SqlTables) SqlCondition }
外联字段
type EntField ¶
type EntField interface { SqlField // 字段所属的实体 Entity() Entity Table() SqlTable FieldName() string Rule() string GetAnnotation(annName string) interface{} // 定义的名称 DefineName() string Value() interface{} // 是否打开 IsOpen() bool TryGetVal() interface{} Set(val interface{}) FieldValue Supper() EntField // 获取字段元注解 IsPrimary() bool // 是否外联字段 IsForeign() bool // 更新时字段运算 // 字段自增 Inc(step ...int) FieldValue // 字段自减 Dec(step ...int) FieldValue // 字段自乘 UnaryMul(val interface{}) FieldValue // 字段自乘 UnaryDiv(val interface{}) FieldValue Formatter() string NewInstance(alias string, inherited ...interface{}) EntField }
type EntFieldIndex ¶
type Entity ¶
type Entity interface { BasicEntity EntityTrans // 继承的父类 Supper() Entity // 设置实体继承类实例, 供构架内部调用 Implement(supper interface{}) // 实体构造方法 Constructor(attrs []XqAttribute, inherited ...interface{}) interface{} // 主键字段 KeyField() EntField LastSql() string // 最后插入的id LastInsertId() int64 EntityQuery // 在特定数据库中进行操作 Database(dbName string) Entity // 获取实体插入数据检查规则 GetInsertRules(cate ...string) []string // 获取实体更新数据检查规则 GetUpdateRules(cate ...string) []string // 使用更新规则过滤map参数 // @param validParams 默认为false,为true时过滤并检查数据有效性,否则不检查 FilterUpdateParams(params map[string]interface{}, validParams ...bool) (map[string]interface{}, error) // 使用插入规则过滤map参数 // @param validParams 默认为false,为true时过滤并检查数据有效性,否则不检查 FilterInsertParams(params map[string]interface{}, validParams ...bool) (map[string]interface{}, error) // 使用插入规则过滤map参数并转换成插入表达式中的值参数列表 // @param validParams 默认为false,为true时过滤并检查数据有效性,否则不检查 GetInsertValuesFromParams(params map[string]interface{}, validParams ...bool) ([]FieldValue, error) // 使用更新规则过滤map参数并转换成更新表达式中的值参数列表 GetUpdateValuesFromParams(params map[string]interface{}, validParams ...bool) ([]FieldValue, error) FieldFormat(defineName string) func(old interface{}) interface{} }
type EntityAttribute ¶
type EntityAttribute interface { XqAttribute TableName() string TableAlias() string }
实体属性
type EntityCUD ¶
type EntityCUD interface { // 根据主键值删除 DeleteByKey(keyVal interface{}) (int, error) // 根据条件删除 Delete(where ...SqlCondition) (int, error) // 插入数据 Insert(values ...FieldValue) EntityInsert // 使用map[string]interface数据源插入 InsertByMap(maps map[string]interface{}) (int, error) // 分散式插入数据开始, 之后使用字字段的set设置值 BeginInsert() bool // 提交插入数据 CommitInsert() (int, error) // 更新 Update(values ...FieldValue) EntityUpdate // 分散式更新开始, 使用字段的set相关方法设置值后更新 BeginUpdate() bool // 提交更新 CommitUpdate(where ...SqlCondition) (int, error) // 插入或更新,如果设置了主键则更新等于主键值的行,否则插入 SaveMap(data map[string]interface{}) (int, error) // 插入或更新,如果设置了主键则更新等于主键值的行,否则插入 Save(fields ...FieldValue) (int, error) // 在插入数据之前,先检查数据有效后才插入,实体需要实现EntityInsertChecker接口 ValidInsert(values []FieldValue, validRule ...string) (int, error) // 在更新数据之前,先检查数据有效后才更新,实体需要实现EntityUpdateChecker接口 ValidUpdate(values []FieldValue, where SqlCondition, validRule ...string) (int, error) // 使用参数数据源插入数据库,插入之前使用实体定义的插入规则过滤和检查数据有效性 InsertFromParams(params map[string]interface{}) (int, error) // 使用参数数据源更新数据库,更新之前使用实体定义的更新规则过滤和检查数据有效性 UpdateFromParams(params map[string]interface{}, where ...SqlCondition) (int, error) }
type EntityClass ¶
type EntityClass interface { EntType() reflect.Type Constructor() func() Entity // 实体属性 Attributes() []XqAttribute Annotations() map[string]map[string]anno.AnnotationContainer TableName() string TableAlias() string Create() interface{} Fields() map[string]EntityFieldClass UpdateValidItems() map[string]FieldValid InsertValidItems() map[string]FieldValid String() string }
type EntityDeleteObserver ¶
type EntityDeleteObserver interface { // 删除之前调用,返回false取消该次删除 BeforeDelete(where SqlCondition) bool }
type EntityEditor ¶
type EntityEditor interface {
FieldEdit(field EntField, value FieldValue) FieldValue
}
实体编辑器
type EntityFieldAttribute ¶
type EntityFieldClass ¶
type EntityFieldClass interface { FieldIndex() []int DefineName() string Annotations() map[string]anno.AnnotationContainer IsForeign() bool Constructor() FieldConstructor NewField(entity Entity, params ...interface{}) interface{} }
type EntityForeignFieldAttribute ¶
type EntityForeignFieldAttribute interface { XqAttribute // 外键名称 ForeignKey() string // 字段别名 FieldAlias() string Rule() string }
type EntityInsert ¶
type EntityInsert interface { Execute() (int, error) From(table SqlTable) EntityInsertExecute }
type EntityInsertChecker ¶
type EntityInsertChecker interface { // 检查数据是否有效,返回error != nil 取消该次插入 CheckInsertValid(values ...[]FieldValue) ([]FieldValue, error) }
实体插入数据规则检查,如果实体现实了该接口,ValidInsert方法将先调用该接口检查数据有效性,通过后才插入数据
type EntityInsertExecute ¶
type EntityInsertObserver ¶
type EntityInsertObserver interface { // 插入数据之前调用,返回false时,取消插入 BeforeInsert(fields []FieldValue) bool }
实体插入数据监听器
type EntityInsertRule ¶
type EntityInsertRule interface { // 返回字段验证规则,规格格式为: [字段名@]规格名[#提示消息] InsertRule(cate ...string) []string }
实体插入数据规则检查,如果实体现实了该接口,ValidInsert方法将先调用该接口检查数据有效性,通过后才插入数据
type EntityQuery ¶
type EntityQuery interface { Select(fields ...SqlField) EntitySelect // 按指定规则字段返回查询结果 SelectR(rule string) EntitySelect Open(fields ...SqlField) EntityQueryOpen // 只查询返回指定规则中的字段 OpenR(rule string) EntityQueryOpen // 以实体自身方式返回数据查询,返回满足条件的记录行数,从实体自定字段读取数据 OpenTop(count int, where SqlCondition, orders []SqlOrderField, fields ...SqlField) int // 获取一条数据,如果无指定条件的数据返回false,如果出错会panic OpenFirst(where SqlCondition, orders []SqlOrderField, fields ...SqlField) bool // 根据id获取一条数据,如果实体未设置主键或查询出错会panic,如果指定主键值不存在,返回false,其返回值从实体实例字段中读取 OpenById(id interface{}, fields ...SqlField) bool // 检查数据是否存在 Exists(where func(where SqlCondition, this interface{}) SqlCondition) (bool, error) // Exists的简化版本,出错时panic CheckExists(where ...SqlCondition) bool // 检查条件获取一条记录,简单查询方式 First(where SqlCondition, orders []SqlOrderField, fields ...SqlField) (map[string]interface{}, error) // 查找数据,简单查询方式 Find(where SqlCondition, orders []SqlOrderField, fields ...SqlField) ([]map[string]interface{}, error) // 根据主键ID获取一条map数据数据, 出错将会panic GetById(id interface{}, fields ...SqlField) map[string]interface{} // 根据条件获取指定条数的数据,出错将会panic GetTop(count int, where SqlCondition, orders []SqlOrderField, fields ...SqlField) []map[string]interface{} }
type EntityQueryOpen ¶
type EntityQueryOpen interface { // 打开数据, 以自身字段绑定数据 // 返回所有满足条件的数据 All() (int, error) // 最多返回count条数据 Top(count int) (int, error) Page(pageIndex int, pageSize int) (pageInfo QueryPageInfo, err error) // 查询条件 Where(where ...SqlCondition) EntityQueryOpen // 查询分组 Group(fields ...SqlField) EntityQueryOpen // 分组过滤条件 Having(fields ...SqlCondition) EntityQueryOpen // 排序 Order(fields ...SqlOrderField) EntityQueryOpen // 数据返回限制 Limit(rows int, offset ...int) EntityQueryOpen // 获取生成的sql语句表达式 Sql() (sql string, vars []interface{}) }
type EntitySelect ¶
type EntitySelect interface { Top(count int) EntitySelect Limit(rows int, offset ...int) EntitySelect Where(where ...SqlCondition) EntitySelect Order(fields ...SqlOrderField) EntitySelect Group(fields ...SqlField) EntitySelect Having(having ...SqlCondition) EntitySelect // 使用别名作为嵌套查询或更新的数据表源 Alias(alias string) SqlTable // 返回分页数据 Page(index, size int) EntitySelectPage // 返回数据类型相关方法 List() EntitySelectList // 返回单条数据 First() EntitySelectSingle // 生成sql脚本相关 Build() EntitySelectBuilder }
type EntitySelectBuilder ¶
type EntitySelectBuilder interface { // sql表达式 Sql() (sql string, vars []interface{}) Convert() EntitySelectConvert }
type EntitySelectConvert ¶
type EntitySelectConvert interface { Page(index, size int) EntitySelectPage // 返回数据类型相关方法 List() EntitySelectList // 生成sql脚本相关 Build() EntitySelectBuilder First() EntitySelectSingle }
type EntitySelectList ¶
type EntitySelectList interface { // 返回[]map[string]interface数据方法 Rows() (data []map[string]interface{}, err error) // 返回xml字符串 Xml() (data xxml.XmlStr, err error) // 返回json字符串 Json() (data xjson.JsonStr, err error) // 返回数据集 Dataset() (data Dataset, err error) // 返回slice数组 Slice() (data [][]interface{}, err error) // 访问返回数据并构造返回数据 Visit(visitor QueryBinderVisit) (data interface{}, err error) // 自定议绑定器绑定返回数据方法 Bind(binder DbQueryBinder) (data interface{}, err error) Convert() EntitySelectConvert }
type EntitySelectPage ¶
type EntitySelectPage interface { // map数组列表 Rows() (data []map[string]interface{}, info QueryPageInfo, err error) // xml 字符串 Xml() (data xxml.XmlStr, info QueryPageInfo, err error) // json字符串 Json() (data xjson.JsonStr, info QueryPageInfo, err error) // 返回数据集 Dataset() (data Dataset, info QueryPageInfo, err error) // 返回数组列表 Slice() (data [][]interface{}, info QueryPageInfo, err error) // 访问返回数据并构造返回数据 Visit(visitor QueryBinderVisit) (data interface{}, info QueryPageInfo, err error) // 自定议绑定器绑定返回数据方法 Bind(binder DbQueryBinder) (data interface{}, info QueryPageInfo, err error) Convert() EntitySelectConvert }
type EntitySelectSingle ¶
type EntitySelectSingle interface { Map() (data map[string]interface{}, err error) Xml() (data xxml.XmlStr, err error) Json() (data xjson.JsonStr, err error) Dataset() (data Dataset, err error) Slice() (data []interface{}, err error) Visit(visitor QueryBinderVisit) (data interface{}, err error) Convert() EntitySelectConvert }
type EntityTrans ¶ added in v1.0.1
type EntityUpdate ¶
type EntityUpdate interface { Join(table SqlTable, on func(joinEnt SqlTable, leftTables SqlTables) SqlCondition) EntityUpdate LeftJoin(table SqlTable, on func(joinEnt SqlTable, leftTables SqlTables) SqlCondition) EntityUpdate RightJoin(table SqlTable, on func(joinEnt SqlTable, leftTables SqlTables) SqlCondition) EntityUpdate CrossJoin(table SqlTable, on func(joinEnt SqlTable, leftTables SqlTables) SqlCondition) EntityUpdate Where(where ...SqlCondition) EntityUpdateExecute }
type EntityUpdateChecker ¶
type EntityUpdateChecker interface { // 检查数据是否有效,返回error != nil 将取消该次更新 CheckUpdateValid(values []FieldValue) ([]FieldValue, error) }
实体更新规则,如果实体实现该接口,ValidUpdate方法将先用该接口检查数据有效性,检查通过后才更新数据
type EntityUpdateExecute ¶
type EntityUpdateObserver ¶
type EntityUpdateObserver interface { // 调更前调用,返回false时取消该次更新 BeforeUpdate(fields []FieldValue) bool }
实体更新监听器
type EntityUpdateRule ¶
type EntityUpdateRule interface { // 返回字段验证规则,规格格式为: [字段名@]规格名[#提示消息] UpdateRule(cate ...string) []string }
实体更新规则,如果实体实现该接口,ValidUpdate方法将先用该接口检查数据有效性,检查通过后才更新数据
type FieldConstructor ¶
type FieldConstructor = func(entity Entity, defineName string, attrs []XqAttribute, annotations map[string]interface{}, params ...interface{}) interface{}
type FieldDataType ¶
type FieldDataType uint8
const ( FDTUnknown FieldDataType = iota FDTString FDTBool FDTInt FDTInt8 FDTInt16 FDTInt32 FDTInt64 FDTUint FDTUint8 FDTUint16 FDTUint32 FDTUint64 // float32 FDTFloat // float64 FDTDouble FDTByte FDTDatetime FDTBinary // 用户自定义类型起始值, 不允许用户定义类型与内值类型重复 FDTDefineBase )
func JsFieldDataTypeToType ¶
func JsFieldDataTypeToType(szType string) (FieldDataType, bool)
func QueryDataType2FieldType ¶
func QueryDataType2FieldType(gType reflect.Type, dbType string) FieldDataType
func (FieldDataType) Json ¶
func (fdt FieldDataType) Json(ut ...string) string
func (FieldDataType) String ¶
func (fdt FieldDataType) String() string
type FieldValid ¶
type FieldValue ¶
type FieldValue interface { // 字段 Field() SqlTableField // 给字段设置的值,可以是sql表达式或实际值 Value() interface{} // 是否是主键 IsPrimaryKey() bool String() string }
字段赋值表达式
type LazyGetConditionFun ¶
type LazyGetConditionFun func(tables SqlTables) SqlCondition
type LazyGetJoinConditionFun ¶
type LazyGetJoinConditionFun func(joinTable SqlTable, tables SqlTables) SqlCondition
type LazyGetOrderFieldFun ¶
type LazyGetOrderFieldFun func(tables SqlTables) []SqlOrderField
获取排序字段列表
type MemDataset ¶
type MemDataset interface { Dataset Fields() DSFields // 添加数据 Append(values ...interface{}) Dataset // 删除当前行 Delete() bool // 删除指定行 DeleteByRow(row int) bool // 生成数据集字段 CreateDataSet(fields ...*TQueryColDef) Dataset // 从map数据复制数据创建 CreateFromSliceMap(maps []map[string]interface{}) Dataset // 获取指定行数据 Row(rowIndex int) DatasetRow // 遍历所有记录 Iterator(iter func(row DatasetRow) bool) Current() DatasetRow Clear() Dataset }
type Query ¶
type Query interface { SqlCompiler QueryJoin QueryWhere QueryGroup QueryOrder QueryHaving QueryLimit Info() QueryInfo // 查询的数据库 DB() Database // 表达式取别名转换成table查询语句以供外层查询 Alias(alias string) SqlTable Xml() (xxml.XmlStr, error) // 获取xml结果 Json() (xjson.JsonStr, error) // 获取json结果 Rows() ([]map[string]interface{}, error) // 获取map Slices() ([][]interface{}, error) Dataset() (Dataset, error) Visitor(visitor func(row int, values ...interface{}) (interface{}, bool)) ([]interface{}, error) Bind(binder DbQueryBinder) (interface{}, error) Sql() (sql string, vars []interface{}) }
type QueryBinderVisit ¶
数据访问方法
type QueryColValue ¶
type QueryColValue = *TQueryColValue
type QueryGroup ¶
type QueryHaving ¶
type QueryHaving interface {
Having(exp func(having SqlCondition, tables SqlTables) SqlCondition) Query
}
type QueryInfo ¶
type QueryInfo interface { // 获取查询的表 GetTable() SqlTable // 获取查询的字段列表 GetSelectFields() []SqlField // 获取where条件表达式 GetWhere() SqlCondition // 获取having条件表达式 GetHaving() SqlCondition // 获取排序字段列表 GetOrders() []SqlOrderField // 获取分组字段列表 GetGroups() []SqlField // 获取联查字段列表 GetJoins() []SqlJoin // 获取查询表达式中所用到的表,包括join中的表 UseTables() []SqlTable }
type QueryJoin ¶
type QueryJoin interface { Join(table SqlTable, on func(joinTable SqlTable, otherTables SqlTables, on SqlCondition) SqlCondition) Query LeftJoin(table SqlTable, on func(joinTable SqlTable, otherTables SqlTables, on SqlCondition) SqlCondition) Query RightJoin(table SqlTable, on func(joinTable SqlTable, otherTables SqlTables, on SqlCondition) SqlCondition) Query CrossJoin(table SqlTable, on func(joinTable SqlTable, otherTables SqlTables, on SqlCondition) SqlCondition) Query }
type QueryLimit ¶
type QueryOrder ¶
type QueryOrder interface {
Order(fields func(tables SqlTables) []SqlOrderField) Query
}
type QueryPageInfo ¶
type QuerySelect ¶
type QueryWhere ¶
type QueryWhere interface {
Where(exp func(where SqlCondition, tables SqlTables) SqlCondition) Query
}
type SCPState ¶
type SCPState int
sql编译状态
const ( // 编译查询字段 SCPUnknown SCPState = iota SCPQrSelectFieldsState SCPQrSelectFieldState // 查询表达式字段状态 SCPQrSelectExprFieldState // 查询表 SCPQrSelectFromState SCPQrSelectWhereCondState SCPQrSelectJoinTableState SCPQrSelectJoinCondState SCPQrSelectJoinItemState SCPQrSelectGroupFieldState SCPQrSelectHavingCondState SCPQrSelectOrderFieldState // 生成参数名称 SCPQrSelectParamNameState SCPQrSelectFunParamState // 创建插入表名状态 SCPBuildInsertTableState // 创建插入字段名状态 SCPBuildInsertFieldNameState // 创建插入字段值状态 SCPBuildInsertFieldValueState // 创建从其他表源插入的from部份脚本状态 SCPBuildInsertFromState // 创建更新表的表名状态 SCPBuildUpdateTableState // 创建联合更新的表名 SCPBuildUpdateTableWithFromState // 创建更新字段状态 SCPBuildUpdateFieldState // 创建联合被更新的字段名 SCPBuildUpdateFieldWithFromState // 创建更新字段值表达式使用:表别名.字段名 SCPBuildUpdateFieldValueState // 创建联合更新字段值表达式 SCPBuildUpdateFieldValueFromState // 创建关联更新join部份表名状态 SCPBuildUpdateJoinTableState // 创建联合更新关联关系表达式状态 SCPBuildUpdateJoinOnState // 创建更新条件时的状态 SCPBuildUpdateWhereState // 创建联合更新时的条件表达式状态 SCPBuildUpdateWhereFromState // 创建被删除表名状态 SCPBuildDeleteTableState // 删除表条件表达式状态 SCPBuildDeleteWhereState )
type SqlAriExp ¶
type SqlAriExp interface { SqlCompiler // 运算符 Operator() SqlAriType // 运算符左则表达式 GetLExp() interface{} // 运算符右则表达式 GetRExp() interface{} }
算术表达式 Arithmetic expression
type SqlAriType ¶
type SqlAriType int
const ( // 加运算 + SqlAriPlusType SqlAriType = iota // 减运算 - SqlAriSubType // 乘运算 * SqlAriMulType // 除运算 / SqlAriDivType )
func (SqlAriType) Val ¶
func (sat SqlAriType) Val() string
type SqlCase ¶
type SqlCase interface { SqlCompiler SqlCaseThenElse When(when, then interface{}) SqlCase ElseEnd(val interface{}) SqlField End() SqlField FunId() SqlFunId }
type SqlCaseThenElse ¶
type SqlCaseThenElse interface { // when thenValue else elseValue end ThenElse(thenValue, elseValue interface{}) SqlField }
type SqlCompareType ¶
type SqlCompareType int
const ( // == SqlCompareEQType SqlCompareType = iota // <> SqlCompareNEQType // > SqlCompareGTType // >= SqlCompareGTEType // < SqlCompareLTType // <= SqlCompareLTEType // like SqlCompareLKType // not like SqlCompareNLKType // in SqlCompareINType // not in SqlCompareNINType // not SqlCompareNTType )
func (SqlCompareType) Exp ¶
func (sct SqlCompareType) Exp(rExp string) string
func (SqlCompareType) String ¶
func (sct SqlCompareType) String() string
func (SqlCompareType) Val ¶
func (sct SqlCompareType) Val() string
type SqlCompileContext ¶
type SqlCompileContext interface { // 添加参数到当前上下文 Add(val ...xdriveri.SqlParam) SqlCompileContext // 添加参数到编译上下文件 AddParam(name string, val interface{}) xdriveri.SqlParam // 所有已被收到的实参 Params() []xdriveri.SqlParam // 获取指定序号的参数 ParamByIndex(index int) xdriveri.SqlParam // 删除指定序号的参数 DeleteParam(index int) xdriveri.SqlParam // 根据参数名删除参数 DeleteParamByName(name string) xdriveri.SqlParam // 清空实参 ClearParams() SqlCompileContext // 清空参数、表及状态 Clear() SqlCompileContext // 拷贝实参 Copy(src SqlCompileContext) SqlCompileContext // 参数个数 ParamCount() int // 编译状态入栈 PushState(state SCPState) SqlCompileContext // 编辑状态出栈 PopState() SCPState // 获取最后状态 State() SCPState // 条件表达式左则表达式入规模 PushLExp(exp SqlCompiler) SqlCompileContext // 左则表达式出栈 PopLExp() SqlCompiler // 最后出栈的表达式 LExp() SqlCompiler // 生成参数名称 MakeParamId() string // 生成标识Id MakeIndentId() string AssignTables(src SqlTables) UseTable(table SqlTable) Tables() SqlTables SetDatabase(db Database) Database() Database TablePrefix() string }
sql参数化查询、预处理参数收集器
type SqlCompiler ¶
type SqlCompiler interface { // sql编译接口 // unPrepare默认为false, 为true时不建立参数化语句 // varReceiver 参数化查询时实参收集器 Compile(builder xdriveri.DbDriverSqlBuilder, cxt SqlCompileContext, unPrepare ...bool) SqlToken TokenType() SqlTokenType This() interface{} }
type SqlCondition ¶
type SqlCondition interface { SqlLogic Items() []SqlLogic And(exp ...SqlLogic) SqlCondition Or(exp ...SqlLogic) SqlCondition Xor(exp ...SqlLogic) SqlCondition }
type SqlConditionItem ¶
type SqlConditionItem interface { SqlLogic // 比较符号 Comparer() SqlCompareType }
type SqlConditionLogic ¶
type SqlConditionLogic int
const ( SqlConditionEqLogic SqlConditionLogic = iota SqlConditionNeqLogic SqlConditionGtLogic SqlConditionGteLogic SqlConditionLtLogic SqlConditionLteLogic SqlConditionLkLogic SqlConditionNlkLogic SqlConditionInLogic SqlConditionNinLogic // 逻辑与 and SqlConditionAndLogic // 逻辑颧 or SqlConditionOrLogic // 逻辑异或 xor = and (not value) SqlConditionXorLogic )
func (SqlConditionLogic) Exp ¶
func (sl SqlConditionLogic) Exp(rExpr string) string
func (SqlConditionLogic) String ¶
func (sl SqlConditionLogic) String() string
type SqlField ¶
type SqlField interface { SqlCompiler // 表达式 Exp() interface{} // 别名 AliasName() string Alias(alias string) SqlField Eq(val interface{}) SqlConditionItem Neq(val interface{}) SqlConditionItem Gt(val interface{}) SqlConditionItem Gte(val interface{}) SqlConditionItem Lt(val interface{}) SqlConditionItem Lte(val interface{}) SqlConditionItem In(arr interface{}) SqlConditionItem NotIn(arr interface{}) SqlConditionItem Like(val interface{}) SqlConditionItem NotLike(val interface{}) SqlConditionItem // ===== 算术运算 =======// // ======= 算术运算 ======= // // + Plus(val interface{}) SqlField // - Sub(val interface{}) SqlField // * Mul(val interface{}) SqlField // / Div(val interface{}) SqlField // ==== case when then 函数 ==// Case() SqlCase // case when field == v then else end CaseEq(v interface{}) SqlCaseThenElse // case when field != v then else end CaseNeq(v interface{}) SqlCaseThenElse // case when field > v then else end CaseGt(v interface{}) SqlCaseThenElse // case when field >= v then else end CaseGte(v interface{}) SqlCaseThenElse // case when field < v then else end CaseLt(v interface{}) SqlCaseThenElse // case when field <= v then else end CaseLte(v interface{}) SqlCaseThenElse // 数据类型转换 Cast(asType DbType) SqlField // ========== 聚合函数 ===== // Count() SqlField Max() SqlField Min() SqlField Avg() SqlField Sum() SqlField String() string // 子字符串 Substr(from, l int) SqlField FromBase64() SqlField ToBase64() SqlField // 字符串连接 Concat(val interface{}, more ...interface{}) SqlField // = Substr(from,l).Eq(eqVal) SubEq(from, l int, eqVal interface{}) SqlConditionItem // = Substr(from,l).Neq(neqVal) SubNeq(from, l int, neqVal interface{}) SqlConditionItem // = Substr(from,l).In(arr) SubIn(from, l int, arr interface{}) SqlConditionItem // = Substr(from,l).NotIn(arr) SubNotIn(from, l int, arr interface{}) SqlConditionItem // = Substr(from, l).Like(val) SubLike(from, l int, val interface{}) SqlConditionItem // = Substr(from,l).NotLike(val) SubNotLike(from, l int, val interface{}) SqlConditionItem // = not field Not() SqlConditionItem // = Concat(catVal).Eq(eqVal) ConcatEq(catVal interface{}, eqVal interface{}) SqlConditionItem // = Concat(catVal).Neq(neqVal) ConcatNeq(catVal interface{}, neqVal interface{}) SqlConditionItem // = Concat(catVal).In(arr) ConcatIn(catVal interface{}, arr interface{}) SqlConditionItem // = Concat(catVal).NotIn(arr) ConcatNotIn(catVal interface{}, arr interface{}) SqlConditionItem // = Concat(catVal).Like(val) ConcatLike(catVal interface{}, val interface{}) SqlConditionItem // = Concat(catVal).NotLike(val) ConcatNotLike(catVal interface{}, val interface{}) SqlConditionItem // 排序 Desc() SqlOrderField Asc() SqlOrderField }
type SqlFun ¶
type SqlFun interface { SqlCompiler FunId() SqlFunId }
type SqlInsertExp ¶
type SqlInsertExp interface { SqlCompiler SqlInsertExpInfo Table(table SqlTable) SqlInsertExp From(fromTable SqlTable) SqlInsertExp Values(fields ...FieldValue) SqlInsertExp }
type SqlInsertExpInfo ¶
type SqlInsertExpInfo interface { GetTable() SqlTable GetFromTable() SqlTable GetFields() []FieldValue }
type SqlJoin ¶
type SqlJoin interface { // 联查方式 JoinType() SqlJoinType // 连接的表 JoinTable() SqlTable OnCondition() SqlCondition }
type SqlJoinItem ¶
type SqlJoinItem interface { // 联查方式 JoinType() SqlJoinType // 连接的表 JoinTable() SqlTable // 连接条件表达式 LazyConditionFn() LazyGetJoinConditionFun }
type SqlJoinType ¶
type SqlJoinType int
const ( SqlInnerJoinType SqlJoinType = iota SqlLeftJoinType SqlRightJoinType SqlCrossJoinType )
func (SqlJoinType) Exp ¶
func (sjt SqlJoinType) Exp() string
func (SqlJoinType) String ¶
func (sjt SqlJoinType) String() string
type SqlLogic ¶
type SqlLogic interface { SqlCompiler // 左表达式 LExp() interface{} // 右表达式 RExp() interface{} // 左右表达式之间关联关系 Logic() SqlConditionLogic }
type SqlOrderDirect ¶
type SqlOrderDirect int
const ( SqlOrderAscDirect SqlOrderDirect = iota SqlOrderDescDirect )
func (SqlOrderDirect) Exp ¶
func (sod SqlOrderDirect) Exp() string
type SqlOrderField ¶
type SqlOrderField interface { SqlCompiler Field() SqlField OrderDir() SqlOrderDirect }
type SqlQuery ¶
type SqlQuery interface { SqlCompiler GetFromTable() SqlTable GetQueryFields() []SqlField GetJoins() []SqlJoin GetWhere() SqlCondition GetTables() SqlTables GetGroupFields() []SqlField GetHaving() SqlCondition GetOrderFields() []SqlOrderField GetLimitRows() int GetLimitOffset() int Fields(fields func(tables SqlTables) []SqlField) SqlQuery Where(condition func(tables SqlTables) SqlCondition) SqlQuery Join(table SqlTable, on func(joinTable SqlTable, tables SqlTables) SqlCondition) SqlQuery LeftJoin(table SqlTable, on func(joinTable SqlTable, tables SqlTables) SqlCondition) SqlQuery RightJoin(table SqlTable, on func(joinTable SqlTable, tables SqlTables) SqlCondition) SqlQuery CrossJoin(table SqlTable, on func(joinTable SqlTable, tables SqlTables) SqlCondition) SqlQuery Group(fields func(tables SqlTables) []SqlField) SqlQuery Having(condition func(tables SqlTables) SqlCondition) SqlQuery Order(fields func(tables SqlTables) []SqlOrderField) SqlQuery Limit(rows, offset int) SqlQuery Page(size, index int) SqlQuery Alias(alias string) SqlTable }
type SqlStaticExpr ¶
type SqlStaticExpr interface { SqlCompiler Val() interface{} }
type SqlTableField ¶
type SqlTableField interface { SqlField Table() SqlTable FieldName() string Set(val interface{}) FieldValue // 字段自增 Inc(step ...int) FieldValue // 字段自减 Dec(step ...int) FieldValue // 字段自乘 UnaryMul(val interface{}) FieldValue // 字段自乘 UnaryDiv(val interface{}) FieldValue }
SqlTableField兼容SqlField
type SqlTableFields ¶
type SqlTokenType ¶
type SqlTokenType int
const ( // 空节点 SqlEmptyTokenType SqlTokenType = iota // 常量 SqlStaticTokenType // sql变量 SqlVarTokenType // 字段类型 SqlFieldTokenType // 字段赋值表达式 SqlFieldAssignTokenType // 数据表节点 SqlTableTokenType // sql查询表达式表 SqlQueryTableTokenType // 序列字段 SqlOrderFieldTokenType // 算术运算表达式 SqlArithmeticTokenType // 关系表达式 SqlConditionTokenType // 关系表达式项 SqlConditionItemTokenType // 函数表达式 SqlFunExpressTokenType // 聚合函数表达式 SqlAggregateFunTokenType // 表达式 SqlExpressTokenType // 查询语句节点 SqlQueryTokenType // 插入语句 SqlInsertTokenType // 更新语句 SqlUpdateTokenType )
func (SqlTokenType) Name ¶
func (stt SqlTokenType) Name() string
type SqlUpdateExp ¶
type SqlUpdateExp interface { SqlCompiler SqlUpdateExpInfo // 要更新的表 Table(table SqlTable) SqlUpdateExp // 更新字段 Set(fields ...FieldValue) SqlUpdateExp // 更新数据条件 Where(condition SqlCondition) SqlUpdateExp // 从其他数据源关联更新 Join(joinType SqlJoinType, table SqlTable, on func(join SqlTable, others SqlTables) SqlCondition) SqlUpdateExp InnerJoin(table SqlTable, on func(join SqlTable, others SqlTables) SqlCondition) SqlUpdateExp LeftJoin(table SqlTable, on func(join SqlTable, others SqlTables) SqlCondition) SqlUpdateExp RightJoin(table SqlTable, on func(join SqlTable, others SqlTables) SqlCondition) SqlUpdateExp CrossJoin(table SqlTable, on func(join SqlTable, others SqlTables) SqlCondition) SqlUpdateExp }
type SqlUpdateExpInfo ¶
type SqlUpdateExpInfo interface { // 获取要更新的表 GetTable() SqlTable // 获取要更新的字段列表 GetFields() []FieldValue // 获取要更新的条件 GetWhere() SqlCondition // 获取更新的数据来源表,如果非从其他数据源更新,返回nil GetJoins() []SqlJoin }
type SqlVarExpr ¶
type SqlVarExpr interface { SqlCompiler Val() interface{} SetVal(v interface{}) SqlVarExpr }
type TBinderName ¶
type TBinderName struct {
// contains filtered or unexported fields
}
func BinderName ¶
func BinderName(name string, options ...map[string]interface{}) TBinderName
func (TBinderName) Name ¶
func (bn TBinderName) Name() string
func (TBinderName) Options ¶
func (bn TBinderName) Options() map[string]interface{}
func (TBinderName) String ¶
func (bn TBinderName) String() string
type TQueryColDef ¶
type TQueryColDef struct { // 字段名称 ColName string // 扫描数据类型 ColType FieldDataType }
func NewQueryColDef ¶
func NewQueryColDef(name string, fieldType FieldDataType) *TQueryColDef
func NewQueryColDefByType ¶
func NewQueryColDefByType(name string, gType reflect.Type, dbType ...string) *TQueryColDef
type TQueryColInfo ¶
type TQueryColInfo struct { TQueryColDef // 字段序号 ColIndex int // 数据库定义类型 DbType string }
查询字段信息
func NewQueryColInfo ¶
type TQueryColValue ¶
type TQueryColValue struct { *TQueryColInfo // 字段值 ColValue interface{} }
type XqAttribute ¶
type XqAttributeMap ¶
Source Files ¶
- xq_binder_name.go
- xq_inf_attribute.go
- xq_inf_data_type.go
- xq_inf_database.go
- xq_inf_dataset.go
- xq_inf_dataset_field.go
- xq_inf_dataset_fielddef.go
- xq_inf_dataset_fields.go
- xq_inf_dataset_row.go
- xq_inf_db_config.go
- xq_inf_db_conn.go
- xq_inf_db_logger.go
- xq_inf_db_mysql_config.go
- xq_inf_entity.go
- xq_inf_entity_attribute.go
- xq_inf_entity_class.go
- xq_inf_entity_field.go
- xq_inf_entity_field_attribute.go
- xq_inf_entity_foreign_field_attribute.go
- xq_inf_entity_query_open.go
- xq_inf_entity_select.go
- xq_inf_field_data_type.go
- xq_inf_field_valid.go
- xq_inf_field_value.go
- xq_inf_query_binder.go
- xq_inf_query_exp.go
- xq_inf_query_page_info.go
- xq_inf_sql_ari_exp.go
- xq_inf_sql_ari_type.go
- xq_inf_sql_compare_type.go
- xq_inf_sql_compile_context.go
- xq_inf_sql_compile_flags.go
- xq_inf_sql_compiler.go
- xq_inf_sql_condition.go
- xq_inf_sql_condition_item.go
- xq_inf_sql_condition_logic.go
- xq_inf_sql_field.go
- xq_inf_sql_fun.go
- xq_inf_sql_fun_case.go
- xq_inf_sql_func_define.go
- xq_inf_sql_insert_exp.go
- xq_inf_sql_join_item.go
- xq_inf_sql_join_type.go
- xq_inf_sql_lazy.go
- xq_inf_sql_order_dir.go
- xq_inf_sql_order_field.go
- xq_inf_sql_query.go
- xq_inf_sql_real_value.go
- xq_inf_sql_table.go
- xq_inf_sql_table_field.go
- xq_inf_sql_tables.go
- xq_inf_sql_token.go
- xq_inf_sql_token_type.go
- xq_inf_sql_update_exp.go
Click to show internal directories.
Click to hide internal directories.