Documentation ¶
Index ¶
- func CountWhere(model interface{}, psql string, param ...interface{}) (count int64)
- func CreateInBatches(model interface{}, count int) (RowsAffected int64, err error)
- func Escape(val interface{}) string
- func EscapeInLocation(val interface{}, loc *time.Location) string
- func Exec(psql string, param ...interface{}) (RowsAffected int64, err error)
- func FindOne(dest interface{}, cond ...interface{})
- func FindOneByCond(dest interface{}, cond interface{})
- func FindOneWhere(dest interface{}, psql string, param ...interface{})
- func FindWhere(dest interface{}, psql string, param ...interface{})
- func FormatInLocation(query string, loc *time.Location, args ...interface{}) string
- func GetDB() *sql.DB
- func Raw(dest interface{}, psql string, param ...interface{})
- func Save(model interface{}) (RowsAffected int64, err error)
- func SaveByFields(model interface{}, fields ...string) (RowsAffected int64, err error)
- func Scan(rows *sql.Rows, dest interface{}) error
- func ScanResult(rows *sql.Rows, dest interface{}) error
- func ScanSlice(rows *sql.Rows, dest interface{}) error
- func SetSingleQuoteEscaper(escaper string)
- func TableCount(table string) (count int64)
- func Updates(model interface{}, data map[string]interface{}) (RowsAffected int64, err error)
- type Client
- type ClientConfig
- type ClientDSN
- type Config
- type DB
- func (db *DB) Begin() (*Trans, error)
- func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Trans, error)
- func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (db *DB) Init(conf Config, logger *zap.Logger)
- func (db *DB) Query(query string, args ...interface{}) *RowsResult
- func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
- func (db *DB) QueryRow(query string, args ...interface{}) *RowResult
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *RowResult
- func (db *DB) RawDB() *sql.DB
- type DelStatus
- type Driver
- type Mssql
- type Mysql
- type Orm
- type RowResult
- type RowsResult
- type SQL
- type Trans
- func (tx *Trans) Commit() error
- func (tx *Trans) Exec(query string, args ...interface{}) (sql.Result, error)
- func (tx *Trans) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (tx *Trans) Query(query string, args ...interface{}) *RowsResult
- func (tx *Trans) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
- func (tx *Trans) QueryRow(query string, args ...interface{}) *RowResult
- func (tx *Trans) QueryRowContext(ctx context.Context, query string, args ...interface{}) *RowResult
- func (tx *Trans) Rollback() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CountWhere ¶
CountWhere 根据条件统计指定模型的数据记录总行数
func CreateInBatches ¶
CreateInBatches 分批批量插入
func EscapeInLocation ¶
EscapeInLocation escape the val with time.Location
func FindOneByCond ¶
func FindOneByCond(dest interface{}, cond interface{})
FindOneByCond 根据条件获取一条数据
func FindOneWhere ¶
func FindOneWhere(dest interface{}, psql string, param ...interface{})
FindOneWhere 根据预处理语句获取一条数据 psql(Prepared SQL Statement)预处理语句
func FindWhere ¶
func FindWhere(dest interface{}, psql string, param ...interface{})
FindWhere 根据预处理语句获取数据 psql(Prepared SQL Statement)预处理语句
func FormatInLocation ¶
FormatInLocation format the sql with args
func SaveByFields ¶
SaveByFields 保存一条数据,并制定字段
func ScanResult ¶
func SetSingleQuoteEscaper ¶
func SetSingleQuoteEscaper(escaper string)
SetSingleQuoteEscaper set the singleQuoteEscaper default:\' , e.g. ” 、 \'
Types ¶
type Client ¶
type Client struct { Clients map[string]*DB Configs ClientConfig // contains filtered or unexported fields }
func Open ¶
func Open(configs ClientConfig, log *zap.Logger) (*Client, error)
Open init all the database clients
func (*Client) CreateClient ¶
CreateClient create the db pool for the database
type ClientConfig ¶
type DB ¶
func (*DB) Begin ¶
Begin starts a transaction. The default isolation level is dependent on the driver.
func (*DB) BeginTx ¶
BeginTx starts a transaction.
The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context provided to BeginTx is canceled.
The provided TxOptions is optional and may be nil if defaults should be used. If a non-default isolation level is used that the driver doesn't support, an error will be returned.
func (*DB) ExecContext ¶
func (db *DB) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext 执行查询而不返回任何行 args 用于查询中的任何占位符参数
func (*DB) Query ¶
func (db *DB) Query(query string, args ...interface{}) *RowsResult
Query 执行一个返回 RowsResult 的查询,通常是一个 SELECT args 用于查询中的任何占位符参数
func (*DB) QueryContext ¶
func (db *DB) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
QueryContext 执行一个返回 RowsResult 的查询,通常是一个 SELECT args 用于查询中的任何占位符参数
func (*DB) QueryRow ¶
QueryRow 执行一个预期最多返回一行的查询 QueryRow 总是返回一个非零值。 错误被推迟到调用行的 Scan 方法 否则,*Row 的 Scan 扫描第一个选定的行并丢弃其余的部分
func (*DB) QueryRowContext ¶
QueryRowContext 执行一个预期最多返回一行的查询 QueryRowContext 总是返回一个非零值。 错误被推迟到调用行的 Scan 方法。 如果查询没有选择任何行,*Row 的 Scan 将返回 ErrNoRows 否则,*Row 的 Scan 扫描第一个选定的行并丢弃其余的部分
type Mysql ¶
type Mysql struct { }
func (*Mysql) GetDSN ¶
GetDSN 获取数据源名称 https://github.com/go-sql-driver/mysql [driver[:password]@(host)][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
type RowResult ¶
type RowResult struct { LastError error // contains filtered or unexported fields }
type RowsResult ¶
type Trans ¶
func (*Trans) Exec ¶
Exec executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Trans) ExecContext ¶
func (tx *Trans) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
ExecContext executes a query that doesn't return rows. For example: an INSERT and UPDATE.
func (*Trans) Query ¶
func (tx *Trans) Query(query string, args ...interface{}) *RowsResult
Query executes a query that returns rows, typically a SELECT.
func (*Trans) QueryContext ¶
func (tx *Trans) QueryContext(ctx context.Context, query string, args ...interface{}) *RowsResult
QueryContext executes a query that returns rows, typically a SELECT.
func (*Trans) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. Otherwise, the *Row's Scan scans the first selected row and discards the rest.
func (*Trans) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called. Otherwise, the *Row's Scan scans the first selected row and discards the rest.