Documentation ¶
Index ¶
- Constants
- Variables
- func Camel2Underline(s string) string
- func Code(err error) int
- func ColsIsExistIndex(index *Index, cols ...string) bool
- func GetFieldName(pkId interface{}, colName string) string
- func MapTableColumnFromTag(table *Table, seq int, columnName string, columnType string, rdsTagStr string) error
- func SetBoolFromStr(ptr *bool, s string) error
- func SetDefaultValue(col *Column, value *reflect.Value)
- func SetFloat32FromStr(ptr *float32, s string) error
- func SetFloat64FromStr(ptr *float64, s string) error
- func SetInt32FromStr(ptr *int32, s string) error
- func SetInt64FromStr(ptr *int64, s string) error
- func SetIntFromStr(ptr *int, s string) error
- func SetUint16FromStr(ptr *uint16, s string) error
- func SetUint32FromStr(ptr *uint32, s string) error
- func SetUint64FromStr(ptr *uint64, s string) error
- func SetUint8FromStr(ptr *uint8, s string) error
- func SetUintFromStr(ptr *uint, s string) error
- func SetValue(val interface{}, value *reflect.Value)
- func ToString(v interface{}) string
- func Underline2Camel(s string) string
- type Column
- type ColumnsModel
- type Conf
- type Engine
- func (e *Engine) Count(searchCon *SearchCondition, beanAry interface{}) (int64, error)
- func (e *Engine) Delete(bean interface{}) error
- func (e *Engine) DeleteByCondition(bean interface{}, searchCon *SearchCondition) (int, error)
- func (e *Engine) DeleteByPK(table *Table, pkInt int64) error
- func (e *Engine) FileterCols(table *Table, cols ...string) []string
- func (e *Engine) Find(offset, limit int64, searchCon *SearchCondition, beanAry interface{}) (int64, error)
- func (e *Engine) Get(bean interface{}) (bool, error)
- func (e *Engine) GetByCondition(bean interface{}, searchCon *SearchCondition) (bool, error)
- func (e *Engine) GetDefaultValue(bean interface{}) error
- func (e *Engine) GetTableByName(tableName string) (*Table, bool)
- func (e *Engine) GetTableByReflect(beanValue, beanIndirectValue reflect.Value) (*Table, error)
- func (e *Engine) Incr(bean interface{}, col string, val int64) (int64, error)
- func (e *Engine) Insert(bean interface{}) error
- func (e *Engine) InsertByMap(table *Table, columnValMap map[string]string) error
- func (e *Engine) InsertMulti(beans ...interface{}) (int, error)
- func (e *Engine) IsShowLog(isShow bool)
- func (e *Engine) Printf(format string, a ...interface{})
- func (e *Engine) Printfln(format string, a ...interface{})
- func (e *Engine) Query(offset, limit int64, condition *SearchCondition, table *Table, cols ...string) ([]map[string]interface{}, int64, error)
- func (e *Engine) Quit()
- func (e *Engine) SetSync2DB(mysqlOrm *xorm.Engine, lazyTimeSecond int)
- func (e *Engine) Sum(bean interface{}, searchCon *SearchCondition, col string) (int64, error)
- func (e *Engine) TableFromBeanAryReflect(beanAry interface{}) (*Table, error)
- func (e *Engine) TableName(v reflect.Value) string
- func (e *Engine) TableTruncate(bean interface{}) error
- func (e *Engine) TableTruncateByTable(table *Table) error
- func (e *Engine) Update(bean interface{}, cols ...string) error
- func (e *Engine) UpdateByMap(table *Table, columnValMap map[string]string) error
- func (e *Engine) UpdateMulti(bean interface{}, searchCon *SearchCondition, cols ...string) (int, error)
- type ErrorWithCode
- type ErrorWithCoder
- type Index
- type IndexEngine
- func (ixe *IndexEngine) Count(table *Table, searchCon *SearchCondition) (count int64, err error)
- func (ixe *IndexEngine) Delete(table *Table, idInt int64) error
- func (ixe *IndexEngine) Drop(table *Table, except ...string) error
- func (ixe *IndexEngine) DropSingleIndex(dropIndex *Index) error
- func (ixe *IndexEngine) GetId(table *Table, searchCon *SearchCondition) (int64, error)
- func (ixe *IndexEngine) IdIsExist(table *Table, pkId int64) (bool, error)
- func (ixe *IndexEngine) IsExistData(table *Table, beanValue, reflectVal reflect.Value, cols ...string) (int64, error)
- func (ixe *IndexEngine) IsExistDataByMap(table *Table, valMap map[string]string) (int64, error)
- func (ixe *IndexEngine) Range(table *Table, searchCon *SearchCondition, offset, count int64) (idAry []string, err error)
- func (ixe *IndexEngine) ReBuild(bean interface{}) error
- func (ixe *IndexEngine) ReBuildByTable(table *Table) error
- func (ixe *IndexEngine) Update(table *Table, beanValue, reflectVal reflect.Value, cols ...string) error
- func (ixe *IndexEngine) UpdateByMap(table *Table, pkInt int64, valMap map[string]string) error
- type IndexType
- type RedisClientProxy
- func (c *RedisClientProxy) Del(keys ...string) *redis.IntCmd
- func (c *RedisClientProxy) HDel(key string, fields ...string) *redis.IntCmd
- func (c *RedisClientProxy) HGet(key string, field string) *redis.StringCmd
- func (c *RedisClientProxy) HIncrBy(key, field string, incr int64) *redis.IntCmd
- func (c *RedisClientProxy) HIncrByFloat(key, field string, incr float64) *redis.FloatCmd
- func (c *RedisClientProxy) HIncrby(key string, field string, intVal int64) *redis.IntCmd
- func (c *RedisClientProxy) HIncrbyFloat(key string, field string, intVal float64) *redis.FloatCmd
- func (c *RedisClientProxy) HMGet(key string, fields ...string) *redis.SliceCmd
- func (c *RedisClientProxy) HMSet(key string, fields map[string]interface{}) *redis.StatusCmd
- func (c *RedisClientProxy) ZAdd(key string, members ...redis.Z) *redis.IntCmd
- func (c *RedisClientProxy) ZAddNX(key string, members ...redis.Z) *redis.IntCmd
- func (c *RedisClientProxy) ZCount(key, min, max string) *redis.IntCmd
- func (c *RedisClientProxy) ZRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd
- func (c *RedisClientProxy) ZRem(key string, members ...interface{}) *redis.IntCmd
- func (c *RedisClientProxy) ZRemRangeByScores(key string, min, max string) *redis.IntCmd
- func (c *RedisClientProxy) ZRevRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd
- func (c *RedisClientProxy) ZScore(key, member string) *redis.FloatCmd
- type RedisOrm
- func (r *RedisOrm) Count(value interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Create(value interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Delete(value interface{}, where ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Exec(sql string, values ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Find(out interface{}, where ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) First(out interface{}, where ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Group(query string) (redisRom *RedisOrm)
- func (r *RedisOrm) Limit(limit interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Model(value interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Not(query interface{}, args ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Offset(offset interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Or(query interface{}, args ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Order(value interface{}, reorder ...bool) (redisRom *RedisOrm)
- func (r *RedisOrm) Raw(sql string, values ...interface{}) (redisRom *RedisOrm)
- func (r *RedisOrm) Select(query interface{}, args ...interface{})
- func (r *RedisOrm) Sync2DB()
- func (r *RedisOrm) Sync2Redis()
- func (r *RedisOrm) Table(name string) (redisRom *RedisOrm)
- func (r *RedisOrm) Update(values interface{}, ignoreProtectedAttrs ...bool) (redisRom *RedisOrm)
- func (r *RedisOrm) Where(query interface{}, args ...interface{}) (redisRom *RedisOrm)
- type SchemaColumnsTb
- type SchemaEngine
- func (s *SchemaEngine) AddColumn(bean interface{}, cols ...string) error
- func (s *SchemaEngine) AddIndex(bean interface{}, cols ...string) error
- func (s *SchemaEngine) AlterTable(sql string) error
- func (s *SchemaEngine) CreateTable(bean interface{}) error
- func (s *SchemaEngine) CreateTableByTable(table *Table) error
- func (s *SchemaEngine) ReloadTable(tableName string) (*Table, error)
- func (s *SchemaEngine) ReloadTables() ([]*Table, error)
- func (s *SchemaEngine) RemoveColumn(bean interface{}, cols ...string) error
- func (s *SchemaEngine) RemoveIndex(bean interface{}, cols ...string) error
- func (s *SchemaEngine) ShowTables() []string
- func (s *SchemaEngine) TableDrop(table *Table) error
- type SchemaIndexsTb
- type SchemaTablesTb
- type SearchCondition
- type Table
Constants ¶
const ( TagIdentifier = "redis_orm" // TagIndex 定义是否索引,索引名自动生成 e.g.fmt.Sprintf("%s%s_%s", KeyIndexPrefix, strings.ToLower(table.Name), strings.ToLower(columnName)), TagIndex = "index" // TagUniqueIndex 唯一索引 hash和走zscore一样都是O(1) 针对IndexType_IdMember有效,IndexType_IdScore的索引本来就是唯一的~ TagUniqueIndex = "unique" /* 要支持一种查询条件就得增加一个索引,定义用&连接联合索引中的字段,e.g.Status&Uid 组合索引 字符串则唯一!集合数据结构决定; 除非用int64,44或224或2222来存放Score,即44:前4个字节uint32和后4个字节uint32 1、id作为score, 可以组合但是member唯一,唯一查询可用 此情况下的组合索引,直接按顺序拼接即可 2、id作为member,同一个member只能有一个score,该字段类型必须是长整型,数值索引可用,可以查询范围 此情况下的组合索引,仅仅支持两整型字段,左边32位 右边32位,支持范围查询的放左边 */ TagCombinedindex = "combinedindex" // TagDefaultValue 默认值 TagDefaultValue = "dft" // TagPrimaryKey 是否主键 TagPrimaryKey = "pk" // TagAutoIncrement 自增~ 应用于主键 TagAutoIncrement = "autoincr" // TagSync2DB 配置在主键的tag上,配置了该tag才能生效,同步到数据库 TagSync2DB = "sync2db" // TagComment 备注名 TagComment = "comment" // TagCreatedAt 是否支持自动写创建时间 TagCreatedAt = "created_at" // TagUpdatedAt 是否支持自动写更新时间 TagUpdatedAt = "updated_at" // TagEnum 枚举类型 TagEnum = "enum" // KeyTbPrefix 表key前缀+表名 KeyTbPrefix = "tb:" // KeyIndexPrefix 索引key前缀+表名+字段名 KeyIndexPrefix = "ix:" // KeyAutoIncrPrefix 自增前缀+自增字段名 KeyAutoIncrPrefix = "autoincr_last_" ScoreMax = "+inf" ScoreMin = "-inf" NeedMapTable = "schematablestb,schemacolumnstb,schemaindexstb" ChannelSchemaChangedSubscribe = "channel_schema_change" )
Done: 多个独立的tag辩识和书写更方便些~ 需要加统一前缀,免得跟其他功能定义的tag冲突,然后又太长了,先不改
const ( ErrorCodeSuccess = 0 ErrorCodeUnexpected = iota + 100 ErrorCodeUnKnowField ErrorCodeUnKnowTable ErrorCodeUnKnowError ErrorCodeNotSupportIndexField ErrorCodeUnSupportedType ErrorCodeUnSupportedTableModel ErrorCodeFieldValueInvalid ErrorCodePrimaryKeyNotFound ErrorCodePrimaryKeyTypeInvalid ErrorCodeMoreThanOneIncrementColumn ErrorCodeDataNotAvailable ErrorCodeDataHadAvailable ErrorCodeCombinedIndexColCountOver ErrorCodeCombinedIndexTypeError ErrorCodeNeedPointer ErrorCodeNeedSlice ErrorCodeNotSupportPointer2Pointer ErrorCodeNilArgument ErrorCodeFieldValueInvalidForEnum )
Variables ¶
var ( Err_Unexpected = Error(ErrorCodeUnexpected, "redis-orm-error:unexpected error") ERR_UnKnowField = Error(ErrorCodeUnKnowField, "redis-orm-error:unknown column") ERR_UnKnowTable = Error(ErrorCodeUnKnowTable, "redis-orm-error:unknown table") ERR_UnKnowError = Error(ErrorCodeUnKnowError, "redis-orm-error:unknown error") ERR_NotSupportIndexField = Error(ErrorCodeNotSupportIndexField, "redis-orm-error:not support this field's index") Err_UnSupportedType = Error(ErrorCodeUnSupportedType, "redis-orm-error:unsupported type") Err_UnSupportedTableModel = Error(ErrorCodeUnSupportedTableModel, "redis-orm-error:unsupported table model") Err_FieldValueInvalid = Error(ErrorCodeFieldValueInvalid, "redis-orm-error:column value invalid") Err_PrimaryKeyNotFound = Error(ErrorCodePrimaryKeyNotFound, "redis-orm-error:primarykey not found") Err_PrimaryKeyTypeInvalid = Error(ErrorCodePrimaryKeyTypeInvalid, "redis-orm-error:primarykey type invalid") Err_MoreThanOneIncrementColumn = Error(ErrorCodeMoreThanOneIncrementColumn, "redis-orm-error:more than one increment column") Err_DataNotAvailable = Error(ErrorCodeDataNotAvailable, "redis-orm-error:data not exist") Err_DataHadAvailable = Error(ErrorCodeDataHadAvailable, "redis-orm-error:data had exist") Err_CombinedIndexColCountOver = Error(ErrorCodeCombinedIndexColCountOver, "redis-orm-error:combined index not support more than 2 column") Err_CombinedIndexTypeError = Error(ErrorCodeCombinedIndexTypeError, "redis-orm-error:combined index not support this type of column") Err_NeedPointer = Error(ErrorCodeNeedPointer, "redis-orm-error:needs a pointer to a value") Err_NeedSlice = Error(ErrorCodeNeedSlice, "redis-orm-error:value needs to be a slice") Err_NotSupportPointer2Pointer = Error(ErrorCodeNotSupportPointer2Pointer, "redis-orm-error:pointer to pointer is not supported") Err_NilArgument = Error(ErrorCodeNilArgument, "redis-orm-error:argument is nil") Err_FieldValueInvalidForEnum = Error(ErrorCodeFieldValueInvalidForEnum, "redis-orm-error:column value invalid for enum") )
Functions ¶
func Camel2Underline ¶
func ColsIsExistIndex ¶
func GetFieldName ¶
func MapTableColumnFromTag ¶
func SetBoolFromStr ¶
func SetDefaultValue ¶
func SetFloat32FromStr ¶
func SetFloat64FromStr ¶
func SetInt32FromStr ¶
func SetInt64FromStr ¶
func SetIntFromStr ¶
func SetUint16FromStr ¶
func SetUint32FromStr ¶
func SetUint64FromStr ¶
func SetUint8FromStr ¶
func SetUintFromStr ¶
func Underline2Camel ¶
Types ¶
type Column ¶
type Column struct { Seq byte Name string DefaultValue string IsPrimaryKey bool IsAutoIncrement bool IsCreated bool IsUpdated bool IsCombinedIndex bool EnumOptions map[string]int Comment string DataType string }
func ColumnFromSchemaColumns ¶
func ColumnFromSchemaColumns(v *SchemaColumnsTb, schemaTable *SchemaTablesTb) *Column
func NewEmptyColumn ¶
type ColumnsModel ¶
type ColumnsModel []*Column
func (ColumnsModel) Len ¶
func (c ColumnsModel) Len() int
func (ColumnsModel) Less ¶
func (c ColumnsModel) Less(i, j int) bool
func (ColumnsModel) Swap ¶
func (c ColumnsModel) Swap(i, j int)
type Engine ¶
type Engine struct { Tables map[string]*Table TZLocation *time.Location Schema *SchemaEngine Index *IndexEngine // contains filtered or unexported fields }
type ORM interface { Insert() Update() Delete() Find() Get() }
从tag获取 索引, 只支持数值 字符 唯一索引的 自增 默认值
todo:链式查询
todo:权限控制~
todo:concurrency safe 并发的处理 1、唯一值的写入 解决方案: 2、自增(HIncrBy,HIncrByFloat)的原子可靠性 3、CAS
func (*Engine) Count ¶
func (e *Engine) Count(searchCon *SearchCondition, beanAry interface{}) (int64, error)
func (*Engine) DeleteByCondition ¶
func (e *Engine) DeleteByCondition(bean interface{}, searchCon *SearchCondition) (int, error)
func (*Engine) Find ¶
func (e *Engine) Find(offset, limit int64, searchCon *SearchCondition, beanAry interface{}) (int64, error)
func (*Engine) GetByCondition ¶
func (e *Engine) GetByCondition(bean interface{}, searchCon *SearchCondition) (bool, error)
only support one searchCondition to get or find
func (*Engine) GetDefaultValue ¶
func (*Engine) GetTableByReflect ¶
func (*Engine) InsertByMap ¶
func (*Engine) InsertMulti ¶
func (*Engine) Sum ¶
func (e *Engine) Sum(bean interface{}, searchCon *SearchCondition, col string) (int64, error)
func (*Engine) TableFromBeanAryReflect ¶
func (*Engine) TableTruncate ¶
TableTruncate del the hashkey, it will del all elements for this hash
func (*Engine) TableTruncateByTable ¶
func (*Engine) UpdateByMap ¶
func (*Engine) UpdateMulti ¶
func (e *Engine) UpdateMulti(bean interface{}, searchCon *SearchCondition, cols ...string) (int, error)
type ErrorWithCode ¶
type ErrorWithCode struct {
// contains filtered or unexported fields
}
func (ErrorWithCode) Append ¶
func (e ErrorWithCode) Append(format string, a ...interface{}) ErrorWithCoder
func (ErrorWithCode) Code ¶
func (e ErrorWithCode) Code() int
func (*ErrorWithCode) Equal ¶
func (e *ErrorWithCode) Equal(err error) bool
func (ErrorWithCode) Error ¶
func (e ErrorWithCode) Error() string
type ErrorWithCoder ¶
type ErrorWithCoder interface { error Code() int Append(format string, a ...interface{}) ErrorWithCoder Equal(err error) bool }
func Error ¶
func Error(code int, format string, a ...interface{}) ErrorWithCoder
type Index ¶
type Index struct { Seq byte NameKey string IndexColumn []string Comment string Type IndexType IsUnique bool }
func IndexFromSchemaIndexs ¶
func IndexFromSchemaIndexs(v *SchemaIndexsTb) *Index
type IndexEngine ¶
type IndexEngine struct {
// contains filtered or unexported fields
}
func NewIndexEngine ¶
func NewIndexEngine(e *Engine) *IndexEngine
func (*IndexEngine) Count ¶
func (ixe *IndexEngine) Count(table *Table, searchCon *SearchCondition) (count int64, err error)
func (*IndexEngine) DropSingleIndex ¶
func (ixe *IndexEngine) DropSingleIndex(dropIndex *Index) error
func (*IndexEngine) GetId ¶
func (ixe *IndexEngine) GetId(table *Table, searchCon *SearchCondition) (int64, error)
GetId Done:combined index
func (*IndexEngine) IdIsExist ¶
func (ixe *IndexEngine) IdIsExist(table *Table, pkId int64) (bool, error)
func (*IndexEngine) IsExistData ¶
func (ixe *IndexEngine) IsExistData(table *Table, beanValue, reflectVal reflect.Value, cols ...string) (int64, error)
IsExistData 当前数据是否已经存在,存在则返回主键ID,唯一索引的才需要判断是否存在!
func (*IndexEngine) IsExistDataByMap ¶
func (*IndexEngine) Range ¶
func (ixe *IndexEngine) Range(table *Table, searchCon *SearchCondition, offset, count int64) (idAry []string, err error)
func (*IndexEngine) ReBuild ¶
func (ixe *IndexEngine) ReBuild(bean interface{}) error
ReBuild todo:ReBuild single index
func (*IndexEngine) ReBuildByTable ¶
func (ixe *IndexEngine) ReBuildByTable(table *Table) error
func (*IndexEngine) Update ¶
func (ixe *IndexEngine) Update(table *Table, beanValue, reflectVal reflect.Value, cols ...string) error
Update todo: no thread safety! watch?
func (*IndexEngine) UpdateByMap ¶
type RedisClientProxy ¶
type RedisClientProxy struct {
// contains filtered or unexported fields
}
func NewRedisCliProxy ¶
func NewRedisCliProxy(redisCli redis.Cmdable) *RedisClientProxy
func (*RedisClientProxy) HDel ¶
func (c *RedisClientProxy) HDel(key string, fields ...string) *redis.IntCmd
func (*RedisClientProxy) HGet ¶
func (c *RedisClientProxy) HGet(key string, field string) *redis.StringCmd
func (*RedisClientProxy) HIncrBy ¶
func (c *RedisClientProxy) HIncrBy(key, field string, incr int64) *redis.IntCmd
func (*RedisClientProxy) HIncrByFloat ¶
func (c *RedisClientProxy) HIncrByFloat(key, field string, incr float64) *redis.FloatCmd
func (*RedisClientProxy) HIncrbyFloat ¶
func (*RedisClientProxy) HMGet ¶
func (c *RedisClientProxy) HMGet(key string, fields ...string) *redis.SliceCmd
func (*RedisClientProxy) HMSet ¶
func (c *RedisClientProxy) HMSet(key string, fields map[string]interface{}) *redis.StatusCmd
func (*RedisClientProxy) ZCount ¶
func (c *RedisClientProxy) ZCount(key, min, max string) *redis.IntCmd
func (*RedisClientProxy) ZRangeByScore ¶
func (c *RedisClientProxy) ZRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd
func (*RedisClientProxy) ZRem ¶
func (c *RedisClientProxy) ZRem(key string, members ...interface{}) *redis.IntCmd
func (*RedisClientProxy) ZRemRangeByScores ¶
func (c *RedisClientProxy) ZRemRangeByScores(key string, min, max string) *redis.IntCmd
func (*RedisClientProxy) ZRevRangeByScore ¶
func (c *RedisClientProxy) ZRevRangeByScore(key string, opt redis.ZRangeBy) *redis.StringSliceCmd
type RedisOrm ¶
type RedisOrm struct {
// contains filtered or unexported fields
}
func NewRedisOrm ¶
func NewRedisOrm() *RedisOrm
func (*RedisOrm) Select ¶
func (r *RedisOrm) Select(query interface{}, args ...interface{})
Select Select
type SchemaColumnsTb ¶
type SchemaColumnsTb struct { Id int64 `redis_orm:"pk autoincr comment 'ID'"` TableId int64 `redis_orm:"index comment '表ID'"` Seq byte `redis_orm:"comment '列顺序'"` ColumnName string `redis_orm:"comment '列名'"` ColumnComment string `redis_orm:"dft '' comment '列注释'"` DataType string `redis_orm:"comment '数据类型'"` DefaultValue string `redis_orm:"comment '默认值'"` TableIdColumnName string `redis_orm:"combinedindex TableId&ColumnName comment '组合索引(表ID&列名)'"` CreatedAt int64 `redis_orm:"created_at comment '创建时间'"` UpdatedAt int64 `redis_orm:"updated_at comment '修改时间'"` }
func SchemaColumnsFromColumn ¶
func SchemaColumnsFromColumn(tableId int64, v *Column) *SchemaColumnsTb
type SchemaEngine ¶
type SchemaEngine struct {
*Engine
}
todo:DB隔离, DB如何兼容已有的Table,暂不用吧,redis有自己的DB
Done:存表、字段、索引结构
Done:逆向生成表Table模型
Done:改表结构? pub/sub, 修改了表结构需要reload table, schemaTable -> mapTable 增加,修改,删除字段,有索引的会自动删除索引 增加,修改,删除索引,重建索引
func NewSchemaEngine ¶
func NewSchemaEngine(e *Engine) *SchemaEngine
func (*SchemaEngine) AddColumn ¶
func (s *SchemaEngine) AddColumn(bean interface{}, cols ...string) error
the bean is new, the column which it is the new need to be added
func (*SchemaEngine) AddIndex ¶
func (s *SchemaEngine) AddIndex(bean interface{}, cols ...string) error
func (*SchemaEngine) AlterTable ¶
func (s *SchemaEngine) AlterTable(sql string) error
createTable by AST ALTER TABLE table_name ADD COLUMN column_name string DEFAULT abc COMMENT 测试列 AFTER updated_at;
ALTER TABLE table_name ADD INDEX index_name uid;
ALTER TABLE table_name ADD INDEX index_name (uid, name);
CREATE TABLE table_name (
column_name1 INT(11) COMMENT 列1, column_name2 string DEFAULT abc COMMENT 列2, column_name3 BIGINT(20) created_at COMMENT 添加时间,
) pk(column_name1) autoincr=1 sync2db COMMENT='xx表';
func (*SchemaEngine) CreateTable ¶
func (s *SchemaEngine) CreateTable(bean interface{}) error
func (*SchemaEngine) CreateTableByTable ¶
func (s *SchemaEngine) CreateTableByTable(table *Table) error
func (*SchemaEngine) ReloadTable ¶
func (s *SchemaEngine) ReloadTable(tableName string) (*Table, error)
func (*SchemaEngine) ReloadTables ¶
func (s *SchemaEngine) ReloadTables() ([]*Table, error)
func (*SchemaEngine) RemoveColumn ¶
func (s *SchemaEngine) RemoveColumn(bean interface{}, cols ...string) error
func (*SchemaEngine) RemoveIndex ¶
func (s *SchemaEngine) RemoveIndex(bean interface{}, cols ...string) error
func (*SchemaEngine) ShowTables ¶
func (s *SchemaEngine) ShowTables() []string
func (*SchemaEngine) TableDrop ¶
func (s *SchemaEngine) TableDrop(table *Table) error
type SchemaIndexsTb ¶
type SchemaIndexsTb struct { Id int64 `redis_orm:"pk autoincr comment 'ID'"` TableId int64 `redis_orm:"index comment '表ID'"` Seq byte `redis_orm:"comment '索引顺序'"` IndexName string `redis_orm:"comment '索引名'"` IndexComment string `redis_orm:"dft '' comment '索引注释'"` IndexColumn string `redis_orm:"comment '索引字段,&分割'"` IndexType int `redis_orm:"comment '数据类型'"` IsUnique bool `redis_orm:"comment '是否唯一索引'"` TableIdIndexName string `redis_orm:"combinedindex TableId&IndexName comment '组合索引(表ID&索引名)'"` CreatedAt int64 `redis_orm:"created_at comment '创建时间'"` UpdatedAt int64 `redis_orm:"updated_at comment '修改时间'"` }
func SchemaIndexsFromColumn ¶
func SchemaIndexsFromColumn(tableId int64, v *Index) *SchemaIndexsTb
type SchemaTablesTb ¶
type SchemaTablesTb struct { Id int64 `redis_orm:"pk autoincr comment 'ID'"` TableName string `redis_orm:"unique comment '唯一'"` TableComment string `redis_orm:"dft '' comment '表注释'"` //暂时没用上 PrimaryKey string `redis_orm:"comment '主键字段'"` AutoIncrement string `redis_orm:"comment '自增字段'"` IsSync2DB bool `redis_orm:"comment '是否同步到数据库'"` Created string `redis_orm:"comment '创建时间字段'"` Updated string `redis_orm:"comment '更新时间字段'"` //Version int32 `redis_orm:"comment '版本'"` CreatedAt int64 `redis_orm:"created_at comment '创建时间'"` UpdatedAt int64 `redis_orm:"updated_at comment '修改时间'"` }
SET @table_schema='employees'; SELECT
table_name, table_type, engine, table_rows, avg_row_length, data_length, index_length, table_collation, create_time
FROM
information_schema.tables
WHERE
table_schema = @table_schema
ORDER BY table_name;
func SchemaTablesFromTable ¶
func SchemaTablesFromTable(table *Table) *SchemaTablesTb
type SearchCondition ¶
type SearchCondition struct { SearchColumn []string //IndexType IndexType FieldMaxValue interface{} FieldMinValue interface{} IsAsc bool }
func NewSearchCondition ¶
func NewSearchCondition(indexType IndexType, minVal, maxVal interface{}, column ...string) *SearchCondition
NewSearchCondition will be deprecated, please use NewSearchConditionV2 instead
func NewSearchConditionV2 ¶
func NewSearchConditionV2(minVal, maxVal interface{}, column ...string) *SearchCondition
func (*SearchCondition) IsEqualIndexName ¶
func (s *SearchCondition) IsEqualIndexName(index *Index) bool
func (*SearchCondition) Name ¶
func (s *SearchCondition) Name() string
type Table ¶
type Table struct { TableId int64 Name string Comment string ColumnsSeq []string ColumnsMap map[string]*Column IndexesMap map[string]*Index PrimaryKey string AutoIncrement string IsSync2DB bool Created string Updated string // contains filtered or unexported fields }
func NewEmptyTable ¶
func NewEmptyTable() *Table
func TableFromSchemaTables ¶
func TableFromSchemaTables(table *SchemaTablesTb) *Table