Documentation
¶
Index ¶
- func GetDB() *sql.DB
- type Connection
- func (conn *Connection) Close() error
- func (conn *Connection) Execute(args ...interface{}) (int64, error)
- func (conn *Connection) GetInstance() *Database
- func (conn *Connection) JsonEncode(arg interface{}) string
- func (conn *Connection) Ping() error
- func (conn *Connection) Query(args ...interface{}) ([]map[string]interface{}, error)
- func (conn *Connection) Table(table string) *Database
- type Database
- func (dba *Database) Avg(avg string) (interface{}, error)
- func (dba *Database) Begin()
- func (dba *Database) Chunk(limit int, callback func([]map[string]interface{}))
- func (dba *Database) Commit()
- func (dba *Database) Count(args ...interface{}) (int, error)
- func (dba *Database) Data(data interface{}) *Database
- func (dba *Database) Delete() (int, error)
- func (dba *Database) Distinct() *Database
- func (dba *Database) Execute(args ...interface{}) (int64, error)
- func (dba *Database) Fields(fields string) *Database
- func (dba *Database) First(args ...interface{}) (map[string]interface{}, error)
- func (dba *Database) Get() ([]map[string]interface{}, error)
- func (dba *Database) Group(group string) *Database
- func (dba *Database) Having(having string) *Database
- func (dba *Database) Insert() (int, error)
- func (dba *Database) Join(args ...interface{}) *Database
- func (dba *Database) JsonEncode(data interface{}) string
- func (dba *Database) LeftJoin(args ...interface{}) *Database
- func (dba *Database) Limit(limit int) *Database
- func (dba *Database) Max(max string) (interface{}, error)
- func (dba *Database) Min(min string) (interface{}, error)
- func (dba *Database) Offset(offset int) *Database
- func (dba *Database) OrWhere(args ...interface{}) *Database
- func (dba *Database) Order(order string) *Database
- func (dba *Database) Page(page int) *Database
- func (dba *Database) Query(args ...interface{}) ([]map[string]interface{}, error)
- func (dba *Database) Reset()
- func (dba *Database) RightJoin(args ...interface{}) *Database
- func (dba *Database) Rollback()
- func (dba *Database) Sum(sum string) (interface{}, error)
- func (dba *Database) Table(table string) *Database
- func (dba *Database) Transaction(closure func() error) bool
- func (dba *Database) Update() (int, error)
- func (dba *Database) Value(arg string) (interface{}, error)
- func (dba *Database) Where(args ...interface{}) *Database
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Connection ¶
type Connection struct {
// all config sets
DbConfig map[string]interface{}
// default database
Default string
// current config on use
CurrentConfig map[string]string
//// all sql logs
//SqlLog []string
//// if in transaction, the code auto change
//Trans bool
// max open connections
SetMaxOpenConns int
// max freedom connections leave
SetMaxIdleConns int
}
Connection is the database pre handle
var ( // DB is origin DB DB *sql.DB // Tx is transaction DB //Tx *sql.Tx // Connect is the Connection Object Connect Connection )
func Open ¶
func Open(args ...interface{}) (Connection, error)
Open instance of sql.DB.Oper if args has 1 param , it will be derect connection or with default config set if args has 2 params , the second param will be the default dirver key
func (*Connection) Execute ¶
func (conn *Connection) Execute(args ...interface{}) (int64, error)
Execute str
func (*Connection) GetInstance ¶
func (conn *Connection) GetInstance() *Database
GetInstance , get the database object
func (*Connection) JsonEncode ¶
func (conn *Connection) JsonEncode(arg interface{}) string
JsonEncode : parse json
func (*Connection) Query ¶
func (conn *Connection) Query(args ...interface{}) ([]map[string]interface{}, error)
Query str
func (*Connection) Table ¶
func (conn *Connection) Table(table string) *Database
Table is set table from database
type Database ¶
type Database struct {
RowsAffected int // insert affected rows
LastInsertId int // insert last insert id
SqlLogs []string
LastSql string
// contains filtered or unexported fields
}
Database is data mapper struct
func (*Database) JsonEncode ¶
JsonEncode : parse json
func (*Database) Transaction ¶
func (dba *Database) LastSql() string {
if len(Connect.SqlLog) > 0 {
return Connect.SqlLog[len(Connect.SqlLog)-1:][0]
}
return ""
}
func (dba *Database) SqlLogs() []string {
return Connect.SqlLog
}
*
- simple transaction
Click to show internal directories.
Click to hide internal directories.
