Documentation ¶
Index ¶
- Constants
- func BootLogger() func(*Connection)
- func NewBuilder(ormApi across.OrmApi, operType ...string) (string, error)
- func NewLogger() func(*Connection)
- func NewTableToStruct(c *Connection) *converter.Table2Struct
- type Connection
- func (conn *Connection) Close() error
- func (c *Connection) Execute(arg string, params ...interface{}) (int64, error)
- func (c *Connection) GetExecuteDb() *sql.DB
- func (c *Connection) GetQueryDb() (db *sql.DB)
- func (c *Connection) NewSession() *Session
- func (c *Connection) Query(arg string, params ...interface{}) ([]map[string]interface{}, error)
- func (c *Connection) Table(arg interface{}) *Session
- func (conn *Connection) Use(options ...func(*Connection)) *Connection
- type DbConfigCluster
- type DbConfigSingle
- type Session
- func (dba *Session) AddFields(fields ...string) *Session
- func (dba *Session) Avg(avg string) (interface{}, error)
- func (dba *Session) Begin()
- func (dba *Session) BuildSql(operType ...string) (string, error)
- func (dba *Session) Chunk(limit int, callback func([]map[string]interface{}))
- func (dba *Session) Commit()
- func (dba *Session) Count(args ...string) (int64, error)
- func (dba *Session) CrossJoin(args ...interface{}) *Session
- func (dba *Session) Data(data interface{}) *Session
- func (dba *Session) Decrement(args ...interface{}) (int64, error)
- func (dba *Session) Delete() (int64, error)
- func (dba *Session) Distinct() *Session
- func (dba *Session) Execute(sqlstring string, params ...interface{}) (int64, error)
- func (dba *Session) ExecuteAct(operType string) (int64, error)
- func (dba *Session) Fields(fields ...string) *Session
- func (dba *Session) First() (result map[string]interface{}, err error)
- func (dba *Session) Force(arg ...bool) *Session
- func (dba *Session) Get() (result []map[string]interface{}, err error)
- func (dba *Session) Group(group string) *Session
- func (dba *Session) GroupBy(group string) *Session
- func (dba *Session) Having(having string) *Session
- func (dba *Session) Increment(args ...interface{}) (int64, error)
- func (dba *Session) InnerJoin(args ...interface{}) *Session
- func (dba *Session) Insert() (int64, error)
- func (dba *Session) InsertGetId() (int64, error)
- func (dba *Session) Join(args ...interface{}) *Session
- func (dba *Session) JsonEncode(data interface{}) string
- func (dba *Session) LeftJoin(args ...interface{}) *Session
- func (dba *Session) Limit(limit int) *Session
- func (dba *Session) Loop(limit int, callback func([]map[string]interface{}))
- func (dba *Session) Max(max string) (interface{}, error)
- func (dba *Session) Min(min string) (interface{}, error)
- func (dba *Session) Offset(offset int) *Session
- func (dba *Session) OrWhere(args ...interface{}) *Session
- func (dba *Session) OrWhereBetween(field string, arr interface{}) *Session
- func (dba *Session) OrWhereIn(field string, arr interface{}) *Session
- func (dba *Session) OrWhereNotBetween(field string, arr interface{}) *Session
- func (dba *Session) OrWhereNotIn(field string, arr interface{}) *Session
- func (dba *Session) OrWhereNotNull(arg string) *Session
- func (dba *Session) OrWhereNull(arg string) *Session
- func (dba *Session) Order(order string) *Session
- func (dba *Session) OrderBy(order string) *Session
- func (dba *Session) Page(page int) *Session
- func (dba *Session) ParseTable() error
- func (dba *Session) Pluck(args ...string) (interface{}, error)
- func (dba *Session) Query(sqlstring string, params ...interface{}) (result []map[string]interface{}, errs error)
- func (dba *Session) Reset(source string)
- func (dba *Session) ResetWhere()
- func (dba *Session) RightJoin(args ...interface{}) *Session
- func (dba *Session) Rollback()
- func (dba *Session) Scan(rows *sql.Rows) (result []map[string]interface{}, err error)
- func (dba *Session) ScanAll(rows *sql.Rows, dst interface{}) error
- func (dba *Session) ScanMap(rows *sql.Rows) (result []map[string]interface{}, err error)
- func (dba *Session) ScanRow(rows *sql.Rows, dst interface{}) error
- func (dba *Session) Select() (err error)
- func (dba *Session) Skip(offset int) *Session
- func (dba *Session) Sum(sum string) (interface{}, error)
- func (dba *Session) Table(arg interface{}) *Session
- func (dba *Session) Take(limit int) *Session
- func (dba *Session) Transaction(closure func() error) error
- func (dba *Session) UnionAct(union, field string) (interface{}, error)
- func (dba *Session) UnionJoin(args ...interface{}) *Session
- func (dba *Session) Update() (int64, error)
- func (dba *Session) Value(arg string) (interface{}, error)
- func (dba *Session) Where(args ...interface{}) *Session
- func (dba *Session) WhereBetween(field string, arr interface{}) *Session
- func (dba *Session) WhereIn(field string, arr interface{}) *Session
- func (dba *Session) WhereNotBetween(field string, arr interface{}) *Session
- func (dba *Session) WhereNotIn(field string, arr interface{}) *Session
- func (dba *Session) WhereNotNull(arg string) *Session
- func (dba *Session) WhereNull(arg string) *Session
Constants ¶
const ( VERSION_TEXT = "\ngolang orm of gorose's version : " VERSION_NO = "1.0.4" VERSION = VERSION_TEXT + VERSION_NO + GOROSE_IMG )
const GOROSE_IMG = `` /* 772-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func BootLogger ¶ added in v1.0.4
func BootLogger() func(*Connection)
func NewBuilder ¶
NewBuilder : sql构造器
func NewLogger ¶ added in v1.0.4
func NewLogger() func(*Connection)
func NewTableToStruct ¶ added in v1.0.5
func NewTableToStruct(c *Connection) *converter.Table2Struct
Types ¶
type Connection ¶
type Connection struct { DbConfig *DbConfigCluster Db sqlDb Logger cors.LoggerHandler // 持久化sql日志,如果为空则不持久化 }
func NewConnection ¶
func NewConnection() *Connection
func Open ¶
func Open(args ...interface{}) (*Connection, error)
Open 链接数据库入口, 传入配置 args 接收一个或2个参数, 一个参数时:struct配置文件(across.DbConfigCluster{})
两个参数时: 第一个是驱动或文件类型, 第二个是dsn或文件路径
func (*Connection) Execute ¶
func (c *Connection) Execute(arg string, params ...interface{}) (int64, error)
func (*Connection) GetExecuteDb ¶
func (c *Connection) GetExecuteDb() *sql.DB
func (*Connection) GetQueryDb ¶
func (c *Connection) GetQueryDb() (db *sql.DB)
func (*Connection) NewSession ¶
func (c *Connection) NewSession() *Session
func (*Connection) Query ¶
func (c *Connection) Query(arg string, params ...interface{}) ([]map[string]interface{}, error)
func (*Connection) Table ¶
func (c *Connection) Table(arg interface{}) *Session
func (*Connection) Use ¶ added in v1.0.4
func (conn *Connection) Use(options ...func(*Connection)) *Connection
Use : cors
type DbConfigCluster ¶
type DbConfigCluster struct { Slave []*DbConfigSingle // 多台读服务器, 如果启用则需要放入对应的多台从服务器配置 Master *DbConfigSingle // 一台主服务器负责写数据 }
数据库集群配置 如果不启用集群, 则直接使用 DbConfig 即可 如果仍然使用此配置为非集群, 则 Slave 配置置空即可, 等同于使用 DbConfig
func NewDbConfigCluster ¶
func NewDbConfigCluster() *DbConfigCluster
func NewFileParser ¶
func NewFileParser(fileOrDriverType, dsnOrFile string) (*DbConfigCluster, error)
NewFileParser : 配置解析器
type DbConfigSingle ¶
type DbConfigSingle struct { Driver string // 驱动: mysql/sqlite3/oracle/mssql/postgres EnableQueryLog bool // 是否开启sql日志 SetMaxOpenConns int // (连接池)最大打开的连接数,默认值为0表示不限制 SetMaxIdleConns int // (连接池)闲置的连接数 Prefix string // 表前缀 Dsn string // 数据库链接 }
单一数据库配置
type Session ¶
type Session struct { across.OrmApi Connection *Connection }
func (*Session) AddFields ¶
AddFields : If you already have a query builder instance and you wish to add a column to its existing select clause, you may use the AddFields method:
func (*Session) BuildSql ¶
// BuildSql : build sql string , but not execute sql really // operType : select/insert/update/delete
func (*Session) Decrement ¶
Decrement : auto Decrement -1 default we can define step (such as 2, 3, 6 ...) if give the second params
func (*Session) Increment ¶
Increment : auto Increment +1 default we can define step (such as 2, 3, 6 ...) if give the second params we can use this method as decrement with the third param as "-"
func (*Session) InsertGetId ¶
insertGetId : insert data and get id
func (*Session) JsonEncode ¶
JsonEncode : parse json
func (*Session) OrWhereBetween ¶
OrWhereBetween : like WhereNull , the relation is or,
func (*Session) OrWhereNotBetween ¶
OrWhereNotBetween : like WhereNotNull , the relation is or,
func (*Session) OrWhereNotIn ¶
OrWhereNotIn : as WhereNotIn, the relation is or
func (*Session) OrWhereNotNull ¶
OrWhereNotNull : like WhereNotNull , the relation is or,
func (*Session) OrWhereNull ¶
OrWhereNull : like WhereNull , the relation is or,
func (*Session) ParseTable ¶
func (*Session) Query ¶
func (dba *Session) Query(sqlstring string, params ...interface{}) (result []map[string]interface{}, errs error)
Query : query instance of sql.DB.Query
func (*Session) ResetWhere ¶
func (dba *Session) ResetWhere()
ResetWhere : in transaction, when you need update several tables in difference condition
func (*Session) ScanAll ¶
ScanAll scans all sql result rows into a slice of structs. It reads all rows and closes rows when finished. dst should be a pointer to a slice of the appropriate type. The new results will be appended to any existing data in dst.
func (*Session) Transaction ¶
Transaction : is a simple usage of trans
func (*Session) Value ¶
Value : If you don't even need an entire row, you may extract a single value from a record using the value method. This method will return the value of the column directly:
func (*Session) WhereBetween ¶
WhereBetween : a column's value is between two values:
func (*Session) WhereNotBetween ¶
WhereNotBetween : a column's value lies outside of two values:
func (*Session) WhereNotIn ¶
WhereNotIn : the given column's value is not contained in the given array
func (*Session) WhereNotNull ¶
WhereNotNull : like where , where filed is not null,