Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultLogger() func(e *Engine)
- func SetLevel(level int)
- func StructForScan(pointer interface{}) []interface{}
- func StructToMap(structObj interface{}) map[string]interface{}
- type Clause
- type Config
- type ConfigCluster
- type Engine
- func (c *Engine) GetDriver() string
- func (c *Engine) GetLogger() ILogger
- func (c *Engine) GetMasterDB() *sqlx.DB
- func (c *Engine) GetPrefix() string
- func (c *Engine) GetSlaveDB() *sqlx.DB
- func (c *Engine) Ping() error
- func (c *Engine) SetIgnoreName(arg string)
- func (c *Engine) SetLogger(logger ILogger)
- func (c *Engine) SetPrefix(prefix string)
- func (c *Engine) SetTagKey(arg string)
- func (c *Engine) Use(closers ...func(e *Engine))
- type Field
- type IEngine
- type ILogger
- type LogLevel
- type LogOption
- type Logger
- type Orm
- type Schema
- type Session
- func (s *Session) Begin() (err error)
- func (s Session) Clear()
- func (s *Session) Commit() (err error)
- func (s *Session) CreateTable() error
- func (s *Session) Delete(where ...interface{}) (int64, error)
- func (s *Session) DropTable() error
- func (s *Session) Exec(sqlStr string, values ...interface{}) (result sql.Result, err error)
- func (s *Session) Find(sliceType interface{}) error
- func (s *Session) HasTable() bool
- func (s *Session) Insert(values ...interface{}) (int64, error)
- func (s *Session) LastSql() string
- func (s *Session) Limit(num int) *Session
- func (s *Session) Model(value interface{}) *Session
- func (s *Session) Order(desc string) *Session
- func (s *Session) Query(sqlStr string, values ...interface{}) (rows *sqlx.Rows, err error)
- func (s *Session) QueryRow(sqlStr string, values ...interface{}) (row *sqlx.Row, err error)
- func (s *Session) Raw(sql string, value ...interface{}) *Session
- func (s *Session) RefTable() *Schema
- func (s *Session) Rollback() (err error)
- func (s *Session) SetTX(b bool)
- func (s *Session) Take(structType interface{}) error
- func (s *Session) Update(kv ...interface{}) (int64, error)
- func (s *Session) Where(desc string, args ...interface{}) *Session
- type Type
Constants ¶
View Source
const ( InfoLevel = iota ErrorLevel Disabled )
log levels 新增
Variables ¶
View Source
var ( Error = errorLog.Println Errorf = errorLog.Printf Info = infoLog.Println Infof = infoLog.Printf )
log methods 新增
View Source
var ( TagKey string Ignore string )
Functions ¶
func StructToMap ¶
func StructToMap(structObj interface{}) map[string]interface{}
StructToMap ...参数<structObj>是结构体对象
Types ¶
type Clause ¶
type Clause struct {
// contains filtered or unexported fields
}
type Config ¶
type Config struct { Driver string `json:"driver"` // 驱动: mysql/sqlite3/oracle/mssql/postgres/clickhouse, 如果集群配置了驱动, 这里可以省略 // mysql 示例: // root:root@tcp(localhost:3306)/test?charset=utf8mb4&parseTime=true Dsn string `json:"dsn"` // 数据库链接 SetMaxOpenConn int `json:"setMaxOpenConn"` // (连接池)最大打开的连接数,默认值为0表示不限制 SetMaxIdleConn int `json:"setMaxIdleConn"` // (连接池)闲置的连接数, 默认0 Prefix string `json:"prefix"` // 表前缀, 如果集群配置了前缀, 这里可以省略 }
Config 单点配置
type ConfigCluster ¶
type ConfigCluster struct { Master []Config // 主数据库配置节点 Slave []Config // 从数据库配置节点 Driver string // 驱动 Prefix string // 前缀 }
ConfigCluster 集群配置
type Engine ¶
type Engine struct { *Session // contains filtered or unexported fields }
Engine 全局配置 (初始化配置模块, 可以全局保存并复用。)
func (*Engine) SetIgnoreName ¶
SetIgnoreName 自定义结构体对应的orm忽略字段名字,默认-
type Field ¶
type Field struct { Name string // 字段名 Type string // 字段类型 Tag string // 字段约束,例如: primary key,unique ... }
表中的字段
type IEngine ¶
type IEngine interface { GetMasterDB() *sql.DB GetSlaveDB() *sql.DB GetPrefix() (prefix string) SetLogger(logger ILogger) GetLogger() ILogger GetDriver() string }
IEngine Engine实体的抽象接口,主要是用于与其他模块通信,便于传递 Engine 实例。
type ILogger ¶
type ILogger interface { Sql(sqlStr string, runtime time.Duration) Slow(sqlStr string, runtime time.Duration) Error(msg string) SqlLog() bool ErrorLog() bool SlowLog() float64 }
ILogger ...
type Schema ¶
type Schema struct { Model interface{} // 模型对象 Name string // 表名 Fields []*Field // 表中所有字段 FieldNames []string // 表中所有字段的名字 // contains filtered or unexported fields }
对象和表的映射
func (*Schema) FieldValues ¶
func (s *Schema) FieldValues(dest interface{}) []interface{}
FieldValues 获取结构体中所有字段的值,参数<dest>为 struct/*struct。
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session 真正操作数据库底层模块, 所有的操作, 最终都会走到这里来获取或修改数据。(Session 的核心功能是与数据库进行交互)
func (*Session) CreateTable ¶
CreateTable create a table in database with a model
func (*Session) Insert ¶
Insert 对应的 SQL 语句一般是这样的:
INSERT INTO table_name(col1, col2, col3, ...) VALUES (A1, A2, A3, ...),(B1, B2, B3, ...),... 例如: u1 := &User{Name: "Tom", Age: 18} u2 := &User{Name: "Sam", Age: 25} s.Insert(u1, u2, ...)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.