Documentation ¶
Index ¶
- Variables
- func BuildDBDriver(opts *Options) string
- type Count
- type DBConnect
- func (db *DBConnect) Exec(ctx context.Context, query string, args ...any) (lastInsertId, rowsAffected int64, err error)
- func (db *DBConnect) Query(ctx context.Context, query string, args ...any) (results []map[string]any, count int64, err error)
- func (db *DBConnect) Select(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
- func (db *DBConnect) SelectAll(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
- func (db *DBConnect) SelectMany(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
- func (db *DBConnect) SelectOne(ctx context.Context, dest any, query string, args ...any) (err error)
- type Map
- type MultiSelect
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
View Source
var ( RegCount = regexp.MustCompile("(?is)^(SELECT).*?(FROM)") RegLimit = regexp.MustCompile(`(?is)(ORDER BY \S+(\s+(ASC|DESC))?\s+)?LIMIT\s+(\d+|\?)(?:\s*,\s*(\d+|\?))*\s*$`) )
Functions ¶
func BuildDBDriver ¶
BuildDBDriver return a driver like "user:pass@tcp(host:port)/dbName?charset=utf8&loc=Asia%%2FShanghai"
Types ¶
type DBConnect ¶
type DBConnect struct { *sql.DB Options *Options ContextTx contextKey // contains filtered or unexported fields }
func (*DBConnect) Exec ¶
func (db *DBConnect) Exec(ctx context.Context, query string, args ...any) (lastInsertId, rowsAffected int64, err error)
Exec exec query by prepare sql, eg: INSERT, UPDATE, DELETE
func (*DBConnect) Query ¶
func (db *DBConnect) Query(ctx context.Context, query string, args ...any) (results []map[string]any, count int64, err error)
Query query by prepare sql, eg: SELECT
func (*DBConnect) Select ¶ added in v1.5.0
func (db *DBConnect) Select(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
Select 查询数据
func (*DBConnect) SelectAll ¶ added in v1.6.3
func (db *DBConnect) SelectAll(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
SelectAll 返回所有数据,如果最后有 limit 会删除
type MultiSelect ¶ added in v1.6.3
type MultiSelect func(ctx context.Context, dest any, query string, args ...any) (count int64, err error)
MultiSelect Select, SelectMany, SelectAll 函数签名
type Option ¶
type Option func(opts *Options)
func WithCharset ¶
func WithDBName ¶
func WithPoolSize ¶
Click to show internal directories.
Click to hide internal directories.