Documentation
¶
Overview ¶
数据库处理
Index ¶
- Constants
- Variables
- func BuildTableStruct(tableName, dbName string, dbConf *DBConfig)
- func BuildTableStructSqlType(tableName, dbName string, dbConf *DBConfig, isSqlType bool)
- func InitDB(db_dsn string, pool_size int) error
- func InitDb(conf *DBConfig) (*sql.DB, error)
- func InitMongo(conf *MongoDBConfig) error
- func InitMysqlDb(conf *DBConfig) (*sql.DB, error)
- func InitSqliteDb(conf *DBConfig) (*sql.DB, error)
- type BoltDB
- func (b *BoltDB) Close()
- func (b *BoltDB) Delete(bucket_name string, key ...string) error
- func (b *BoltDB) ForEach(bucketName string, callback func([]byte, []byte) error) error
- func (b *BoltDB) Get(bucket_name string, key string) ([]byte, error)
- func (b *BoltDB) Path() string
- func (b *BoltDB) Put(bucket_name string, key string, val interface{}) error
- type CKCollection
- func (ck *CKCollection) Aggregate(pipe ...bson.M) (bson.M, error)
- func (ck *CKCollection) Close()
- func (ck *CKCollection) Count(where bson.M) int
- func (ck *CKCollection) Delete(where bson.M) error
- func (ck *CKCollection) Drop() error
- func (ck *CKCollection) Find(where bson.M, row interface{}) error
- func (ck *CKCollection) Insert(rows ...interface{}) error
- func (ck *CKCollection) List(where bson.M, page int, number int, sort_list []string, ...) ([]interface{}, error)
- func (ck *CKCollection) Query(where bson.M, page int, number int, sort_list []string, ...) (*QueryResult, error)
- func (ck *CKCollection) Update(where bson.M, update bson.M) error
- func (ck *CKCollection) UpdateAll(where bson.M, update bson.M) (*mgo.ChangeInfo, error)
- func (ck *CKCollection) Upset(where bson.M, update bson.M) error
- type DBA
- func (d *DBA) BeginTrans() error
- func (d *DBA) Close()
- func (d *DBA) Commit() error
- func (d *DBA) ConvertData(orgData interface{}) (utils.M, error)
- func (d *DBA) Delete(where utils.M, table string) (int, error)
- func (d *DBA) Exec(sqlStr string, args ...interface{}) (sql.Result, error)
- func (d *DBA) FetchAll(query *sql.Rows) ([]utils.M, error)
- func (d *DBA) FetchAllOfStruct(query *sql.Rows, i interface{}) ([]interface{}, error)
- func (d *DBA) FetchAllOfStructV2(query *sql.Rows, i interface{}) ([]interface{}, error)
- func (d *DBA) FormatColumn(column string) string
- func (d *DBA) GetLastError() error
- func (d *DBA) HaltError(err error)
- func (d *DBA) Insert(table string, orgData interface{}) (int, bool)
- func (d *DBA) InsertMulti(table string, dataList []interface{}) (int, bool)
- func (d *DBA) Query(sqlStr string, args ...interface{}) ([]utils.M, error)
- func (d *DBA) QueryOne(sqlStr string, args ...interface{}) (utils.M, error)
- func (d *DBA) QueryOneStruct(structInterFace interface{}, sqlStr string, args ...interface{}) (interface{}, error)
- func (d *DBA) QueryRow(sqlStr string, args ...interface{}) *sql.Row
- func (d *DBA) QueryStruct(structInterFace interface{}, sqlStr string, args ...interface{}) ([]interface{}, error)
- func (d *DBA) Rollback() error
- func (d *DBA) SetQueryInterface(i interface{})
- func (d *DBA) Stats() sql.DBStats
- func (d *DBA) Table(tableName string) *DBATable
- func (d *DBA) Update(data utils.M, where utils.M, table string) error
- func (d *DBA) UpdateAny(data interface{}, where utils.M, table string) error
- func (d *DBA) WhereRecursion(where utils.M, icon string, table string) (string, []interface{})
- type DBATable
- func (t *DBATable) BeginTrans() error
- func (t *DBATable) Clear()
- func (t *DBATable) Commit() error
- func (t *DBATable) Delete() bool
- func (t *DBATable) Find() (utils.M, error)
- func (t *DBATable) FindStruct(i interface{}) (interface{}, error)
- func (t *DBATable) Insert(data interface{}) (int, bool)
- func (t *DBATable) InsertMulti(dataList []interface{}) (int, bool)
- func (t *DBATable) Join(fields [][]string) *DBATable
- func (t *DBATable) JoinOne(join *TBJoin) *DBATable
- func (t *DBATable) Limit(number int, page int) *DBATable
- func (t *DBATable) One(rowStruct interface{}) error
- func (t *DBATable) Order(orders utils.M) *DBATable
- func (t *DBATable) OrderIn(column string, rule []string) *DBATable
- func (t *DBATable) Query() *DBATable
- func (t *DBATable) Result() ([]utils.M, error)
- func (t *DBATable) ResultStruct(i interface{}) ([]interface{}, error)
- func (t *DBATable) Rollback() error
- func (t *DBATable) Rows() int
- func (t *DBATable) Select(fields utils.M) *DBATable
- func (t *DBATable) Update(data utils.M) bool
- func (t *DBATable) UpdateAny(data interface{}) bool
- func (t *DBATable) Where(fields utils.M, table string) *DBATable
- type DBColumn
- type DBConfig
- type DBMongo
- type DM
- type MongoDBConfig
- type QueryResult
- type TBField
- type TBJoin
Constants ¶
View Source
const ( DB_DRIVER_MYSQL = "mysql" DB_DRIVER_SQLITE = "sqlite" )
Variables ¶
View Source
var MysqlDrivers = make(map[string]*sql.DB)
View Source
var SqliteDrivers = make(map[string]*sql.DB)
Functions ¶
func BuildTableStruct ¶
输出表结构为GO struct
func BuildTableStructSqlType ¶ added in v1.2.9
Types ¶
type BoltDB ¶
type BoltDB struct {
// contains filtered or unexported fields
}
bolt DB 数据库处理
type CKCollection ¶
type CKCollection struct {
// contains filtered or unexported fields
}
func NewCollection ¶
func NewCollection(mdb *DBMongo, tab_name string) *CKCollection
func (*CKCollection) List ¶
func (ck *CKCollection) List(where bson.M, page int, number int, sort_list []string, struct_type interface{}, format func(interface{})) ([]interface{}, error)
查询数据库返回列表
func (*CKCollection) Query ¶
func (ck *CKCollection) Query(where bson.M, page int, number int, sort_list []string, struct_type interface{}, format func(interface{})) (*QueryResult, error)
查询数据库
type DBA ¶
type DBA struct { LastSql string LastArgs []interface{} LastError error // contains filtered or unexported fields }
func (*DBA) FetchAllOfStruct ¶
取得所有数据到结构体,没传结构体为默认 utils.M
func (*DBA) FetchAllOfStructV2 ¶
取得所有数据到结构体,没传结构体为默认 utils.M
func (*DBA) InsertMulti ¶ added in v1.0.1
插入多条记录
func (*DBA) QueryOneStruct ¶
func (d *DBA) QueryOneStruct(structInterFace interface{}, sqlStr string, args ...interface{}) (interface{}, error)
查询一条记录返回结构体
func (*DBA) QueryStruct ¶
func (d *DBA) QueryStruct(structInterFace interface{}, sqlStr string, args ...interface{}) ([]interface{}, error)
查询数据库并返回结果 (传入结构体)
func (*DBA) SetQueryInterface ¶
func (d *DBA) SetQueryInterface(i interface{})
type DBATable ¶
type DBATable struct {
// contains filtered or unexported fields
}
Table 主结构
func (*DBATable) FindStruct ¶
只得到一条记录,以传入类型返回该类型数组
func (*DBATable) InsertMulti ¶ added in v1.0.1
插入多条数据
func (*DBATable) ResultStruct ¶
得到所有列表结果集,以传入类型返回该类型数组
type DBConfig ¶
type DBConfig struct { DBDriver string `json:"db_driver" yaml:"db_driver"` DBServer string `json:"db_server" yaml:"db_server"` DBPort string `json:"db_port" yaml:"db_port"` DBName string `json:"db_name" yaml:"db_name"` DBUser string `json:"db_user" yaml:"db_user"` DBPassword string `json:"db_password" yaml:"db_password"` DBPoolSize int `json:"db_pool_size" yaml:"db_pool_size"` DBIdleSize int `json:"db_Idle_size" yaml:"db_Idle_size"` MaxLife int `json:"max_life" yaml:"max_life"` DBDebug bool `json:"db_debug" yaml:"db_debug"` }
数据库配置
type DBMongo ¶
type DBMongo struct {
// contains filtered or unexported fields
}
func (*DBMongo) Collection ¶
func (this *DBMongo) Collection(collection_name string) *CKCollection
type MongoDBConfig ¶
type MongoDBConfig struct { DBHost string `json:"db_host" yaml:"db_host"` DBPort string `json:"db_port" yaml:"db_port"` DBUser string `json:"db_user" yaml:"db_user"` DBPasswd string `json:"db_passwd" yaml:"db_passwd"` DBAuth string `json:"db_auth" yaml:"db_auth"` DBName string `json:"db_name" yaml:"db_name"` DBPoolSize int `json:"db_pool_size" yaml:"db_pool_size"` }
dsn mongodb://root:WiaQ82n7B3L5Cz*2#10m@172.18.76.150:27017?authSource=admin
type QueryResult ¶
type QueryResult struct { List interface{} `json:"list"` Count int `json:"count"` }
查询结果
Click to show internal directories.
Click to hide internal directories.