Documentation
¶
Overview ¶
Provides database connections in factory mode to optimize database connections
Example:
qSql = &qsql.Page{ CountSql:`SELECT count(1) FROM user_info WHERE create_time >= ? AND create_time <= ?`, DataSql:`SELECT mobile, balance FROM user_info WHERE create_time >= ? AND create_time <= ?` }
count, titles, result, err := qSql.QueryPageArray(db, true, condition, 0, 10) ... Or count, titles, result, err := qSql.QueryPageMap(db, true, condtion, 0, 10) ... if err != nil { ... }
Index ¶
- Constants
- func Close(closer io.Closer)
- func CloseCache()
- func Commit(tx *sql.Tx, fn func() error) error
- func InsertStruct(drvName string, exec Execer, obj interface{}, tbName string) (sql.Result, error)
- func InsertStructContext(drvName string, exec Execer, ctx context.Context, obj interface{}, ...) (sql.Result, error)
- func QueryElem(queryer Queryer, result interface{}, querySql string, args ...interface{}) error
- func QueryElemContext(queryer Queryer, ctx context.Context, result interface{}, querySql string, ...) error
- func QueryElems(queryer Queryer, result interface{}, querySql string, args ...interface{}) error
- func QueryElemsContext(queryer Queryer, ctx context.Context, result interface{}, querySql string, ...) error
- func QueryPageArr(queryer Queryer, querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
- func QueryPageArrContext(queryer Queryer, ctx context.Context, querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
- func QueryPageMap(queryer Queryer, querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
- func QueryPageMapContext(queryer Queryer, ctx context.Context, querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
- func QueryStruct(queryer Queryer, obj interface{}, querySql string, args ...interface{}) error
- func QueryStructContext(queryer Queryer, ctx context.Context, obj interface{}, querySql string, ...) error
- func QueryStructs(queryer Queryer, obj interface{}, querySql string, args ...interface{}) error
- func QueryStructsContext(queryer Queryer, ctx context.Context, obj interface{}, querySql string, ...) error
- func RegCache(key string, db *DB)
- func RegCacheWithIni(iniPath string)
- func Rollback(tx *sql.Tx)
- func ScanStruct(rows Rows, obj interface{}) error
- func ScanStructs(rows Rows, obj interface{}) error
- func StmtSliceArgs(args ...interface{}) []interface{}
- func StmtWhereIn(drvName string, paramStartIdx, paramsLen int) string
- type Bool
- type DB
- func (db *DB) Close() error
- func (db *DB) Commit(tx *sql.Tx, fn func() error) error
- func (db *DB) DriverName() string
- func (db *DB) InsertStruct(obj interface{}, tbName string) (sql.Result, error)
- func (db *DB) InsertStructContext(ctx context.Context, obj interface{}, tbName string) (sql.Result, error)
- func (db *DB) IsClose() bool
- func (db *DB) QueryElem(result interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryElemContext(ctx context.Context, result interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryElems(result interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryElemsContext(ctx context.Context, result interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryPageArr(querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
- func (db *DB) QueryPageArrContext(ctx context.Context, querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
- func (db *DB) QueryPageMap(querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
- func (db *DB) QueryPageMapContext(ctx context.Context, querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
- func (db *DB) QueryStruct(obj interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryStructContext(ctx context.Context, obj interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryStructs(obj interface{}, querySql string, args ...interface{}) error
- func (db *DB) QueryStructsContext(ctx context.Context, obj interface{}, querySql string, args ...interface{}) error
- func (db *DB) ScanStruct(rows Rows, obj interface{}) error
- func (db *DB) ScanStructs(rows Rows, obj interface{}) error
- func (db *DB) StmtWhereIn(paramStartIdx, paramsLen int) string
- type DBData
- type Execer
- type Float64
- type Int64
- type PageArgs
- type PageSql
- func (p PageSql) CountSql() string
- func (p PageSql) DataSql() string
- func (p PageSql) FmtPage(args ...interface{}) PageSql
- func (p *PageSql) QueryCount(db *DB, args ...interface{}) (int64, error)
- func (p *PageSql) QueryPageArr(db *DB, doCount bool, args *PageArgs) (int64, []string, [][]interface{}, error)
- func (p *PageSql) QueryPageMap(db *DB, doCount bool, args *PageArgs) (int64, []string, []map[string]interface{}, error)
- type Queryer
- type Rows
- type String
Constants ¶
const ( DRV_NAME_MYSQL = "mysql" DRV_NAME_ORACLE = "oracle" // or "oci8" DRV_NAME_POSTGRES = "postgres" DRV_NAME_SQLITE3 = "sqlite3" DRV_NAME_SQLSERVER = "sqlserver" // or "mssql" )
Variables ¶
This section is empty.
Functions ¶
func Commit ¶
A lazy function to commit the *sql.Tx if will auto commit when the function is nil error, or do a rollback and return the function error.
func InsertStruct ¶
Reflect one db data to the struct. the struct tag format like `db:"field_title"`, reference to: http://github.com/jmoiron/sqlx
func InsertStructContext ¶
func QueryElemContext ¶
func QueryElems ¶
Query one field to a sql.Scanner array.
func QueryElemsContext ¶
func QueryPageArr ¶
func QueryPageArr(queryer Queryer, querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
Reflect the query result to a string array.
func QueryPageArrContext ¶
func QueryPageMap ¶
func QueryPageMap(queryer Queryer, querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
Reflect the query result to a string map.
func QueryPageMapContext ¶
func QueryStruct ¶
Reflect the sql.Query result to a struct.
func QueryStructContext ¶
func QueryStructs ¶
Reflect the sql.Query result to a struct array. Return empty array if data not found.
func QueryStructsContext ¶
func RegCacheWithIni ¶
func RegCacheWithIni(iniPath string)
func ScanStruct ¶
Relect the sql.Rows to a struct.
func ScanStructs ¶
Reflect the sql.Rows to a struct array. Return empty array if data not found. Refere to: github.com/jmoiron/sqlx
func StmtSliceArgs ¶
func StmtSliceArgs(args ...interface{}) []interface{}
func StmtWhereIn ¶
Types ¶
type DB ¶
func (*DB) Commit ¶
A lazy function to commit the *sql.Tx if will auto commit when the function is nil error, or do a rollback and return the function error.
func (*DB) DriverName ¶
func (*DB) InsertStruct ¶
Reflect one db data to the struct. the struct tag format like `db:"field_title"`, reference to: http://github.com/jmoiron/sqlx
func (*DB) InsertStructContext ¶
func (*DB) QueryElemContext ¶
func (*DB) QueryElems ¶
Query one field to a sql.Scanner array.
func (*DB) QueryElemsContext ¶
func (*DB) QueryPageArr ¶
func (db *DB) QueryPageArr(querySql string, args ...interface{}) (titles []string, result [][]interface{}, err error)
Reflect the query result to a string array.
func (*DB) QueryPageArrContext ¶
func (*DB) QueryPageMap ¶
func (db *DB) QueryPageMap(querySql string, args ...interface{}) (titles []string, result []map[string]interface{}, err error)
Reflect the query result to a string map.
func (*DB) QueryPageMapContext ¶
func (*DB) QueryStruct ¶
Reflect the sql.Query result to a struct.
func (*DB) QueryStructContext ¶
func (*DB) QueryStructs ¶
Reflect the sql.Query result to a struct array. Return empty array if data not found.
func (*DB) QueryStructsContext ¶
func (*DB) ScanStruct ¶
Relect the sql.Rows to a struct.
func (*DB) ScanStructs ¶
Reflect the sql.Rows to a struct array. Return empty array if data not found. Refere to: github.com/jmoiron/sqlx
func (*DB) StmtWhereIn ¶
type PageArgs ¶
type PageArgs struct {
// contains filtered or unexported fields
}
func NewPageArgs ¶
func NewPageArgs(args ...interface{}) *PageArgs
type PageSql ¶
type PageSql struct {
// contains filtered or unexported fields
}
func NewPageSql ¶
func (PageSql) FmtPage ¶
fill the page sql with fmt arg, and return a new page Typically used for table name formatting
func (*PageSql) QueryCount ¶
func (*PageSql) QueryPageArr ¶
type Queryer ¶
type Queryer interface { Query(query string, args ...interface{}) (*sql.Rows, error) QueryRow(query string, args ...interface{}) *sql.Row QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }