Documentation
¶
Index ¶
- Variables
- func Any2Slice(data any) []any
- func Any2Time(i any) (time.Time, bool)
- func Build(ctx context.Context, b Builder) (string, []any)
- func Close() error
- func ColNamesWithTagOpt(d interface{}, tag string, opt *Option) []string
- func Connect(ctx context.Context) error
- func Count(ctx context.Context, filter any, opt *Option) (int64, error)
- func CountBy(ctx context.Context, dst any, filter any, group []string, opt *Option) error
- func DefaultProvider(isMaster bool) *sqlx.DB
- func DeleteByID(ctx context.Context, id any, opt *Option) error
- func DeleteWhere(ctx context.Context, filter any, opt *Option) error
- func Distinct(ctx context.Context, column string, filter any, opt *Option) ([]any, error)
- func Exec(ctx context.Context, sql string, args ...interface{}) (driver.Result, error)
- func ExecTx(ctx context.Context, tx *sqlx.Tx, sql string, args ...interface{}) (driver.Result, error)
- func Exist(ctx context.Context, filter any, opt *Option) (bool, error)
- func Float64(v interface{}) (f float64, err error)
- func FromMaster(ctx context.Context) context.Context
- func FromSlave(ctx context.Context) context.Context
- func Get(ctx context.Context, dest interface{}, sql string, args ...interface{}) error
- func GetByID(ctx context.Context, dst any, id any, opt *Option) error
- func GetTx(ctx context.Context, tx *sqlx.Tx, dest interface{}, sql string, ...) error
- func GetWhere(ctx context.Context, dst any, filter any, opt *Option) error
- func Init(ctx context.Context, opt *Option) error
- func InsertIgnore(ctx context.Context, data []any, opt *Option) error
- func InsertMany(ctx context.Context, data []any, opt *Option) error
- func InsertOne(ctx context.Context, data any, opt *Option) (int64, error)
- func IsDuplicate(err error) bool
- func IsNotFound(err error) bool
- func Master() *sqlx.DB
- func NewInsertBuilderFromStruct(ctx context.Context, data []any, opt *Option) (*sb.InsertBuilder, error)
- func NewSelectBuilderFromStruct(data any, opt *Option) (*sb.SelectBuilder, error)
- func NewUpdateBuilderFromStruct(data any, opt *Option) (*sb.UpdateBuilder, bool)
- func ParseOptionStr(str string) map[string]string
- func PatchByID(ctx context.Context, id any, data any, opt *Option) error
- func PatchWhere(ctx context.Context, data any, filter any, opt *Option) (int64, error)
- func Replace(ctx context.Context, data any, opt *Option) (int64, error)
- func RunInLock(ctx context.Context, table string, f func(ctx context.Context) error) (err error)
- func RunInRLock(ctx context.Context, table string, f func(ctx context.Context) error) (err error)
- func RunTxContext(ctx context.Context, f func(ctx context.Context, tx *sqlx.Tx) error) error
- func RunTxWithOptionContext(ctx context.Context, opts *sql.TxOptions, ...) error
- func Select(ctx context.Context, dest interface{}, sql string, args ...interface{}) error
- func SelectTx(ctx context.Context, tx *sqlx.Tx, dest interface{}, sql string, ...) error
- func SelectWhere(ctx context.Context, dst any, filter any, opt *Option) error
- func SetGlobalOption(opt *Option)
- func SetLogger(l zerolog.Logger)
- func SetMetricHandler(h MetricHandler)
- func Slave() *sqlx.DB
- func TableName(d any, opt *Option) string
- func WhereFrom(c *sb.Cond, filter any, dst []string, opt *Option) []string
- func WhereFromID(c *sb.Cond, id int64, dst []string) []string
- func WhereFromIDs(c *sb.Cond, idList []int64, dst []string) []string
- func WhereFromKVs(c *sb.Cond, filter KVs, dst []string) []string
- func WhereFromStruct(c *sb.Cond, data any, dst []string, opt *Option) []string
- type Builder
- type DBProvider
- type FieldOptioner
- type KV
- type KVs
- type M
- type MetricHandler
- type Option
- func (opt *Option) Copy() *Option
- func (opt *Option) Fields(value ...string) *Option
- func (opt *Option) FromMaster() *Option
- func (opt *Option) IgnoreNamespace() *Option
- func (opt *Option) Isolation(level sql.IsolationLevel) *Option
- func (opt *Option) Namespace(value string) *Option
- func (opt *Option) NamespaceColumnName(value string) *Option
- func (opt *Option) Page(page, pageSize int) *Option
- func (opt *Option) PrimaryKey(value string) *Option
- func (opt *Option) Sorts(value ...string) *Option
- func (opt *Option) Table(value any) *Option
- func (opt *Option) TablePrefix(value string) *Option
- func (opt *Option) TagName(value string) *Option
- func (opt *Option) Tx(tx *sqlx.Tx) *Option
- func (opt *Option) With(ctx context.Context) context.Context
Constants ¶
This section is empty.
Variables ¶
var Raw = sb.Raw
Functions ¶
func Build ¶
Build is same with builder.Build, but it will try to inject namespace(which defined in context) filter into where condition in sql
func ColNamesWithTagOpt ¶
ColNamesWithTagOpt will column names from structure data, the type of d must be a struct, otherwise will return []string{}.
ColNamesWithTagOpt will try to filter the filter the struct field which having <tag> specified in StructField.Tag if <tag> is not empty
func DefaultProvider ¶
DefaultProvider return the sqlx.DB created by Connect()
func DeleteByID ¶
DeleteWhere delete rows by id in transaction from the table
func DeleteWhere ¶
DeleteWhereTx delete rows that match the filter in transaction from the given table
func ExecTx ¶
func ExecTx(ctx context.Context, tx *sqlx.Tx, sql string, args ...interface{}) (driver.Result, error)
Exec execute a sql in transaction
func FromMaster ¶
FromMaster force ormx execute sql on master instance when called by this context
func Get ¶
Get will get one data into dest with raw sql and args.
it will auto query from master if the context having FromMaster
func GetTx ¶
func GetTx(ctx context.Context, tx *sqlx.Tx, dest interface{}, sql string, args ...interface{}) error
Get will get one data from tx by using raw sql and args.
func InsertIgnore ¶
InsertIgnore insert new data into database and ingore the rows on duplicate keys using transaction
func InsertMany ¶
InsertMany insert rows in transaction, the all data type should be same structure.
func Master ¶
Master return master *sqlx.DB which returned by DBProvider, panic if DBProvider is not Initilized
func NewInsertBuilderFromStruct ¶
func NewInsertBuilderFromStruct(ctx context.Context, data []any, opt *Option) (*sb.InsertBuilder, error)
NewInsertBuilderFromStruct create a new insert builder from data, the struct field with 'insert' option in field tag will be inserted
such as: db:"columnName,insert" or db:",insert"
the struct field with no insert tag option, will be ignored
func NewSelectBuilderFromStruct ¶
func NewSelectBuilderFromStruct(data any, opt *Option) (*sb.SelectBuilder, error)
NewSelectBuilderFromStruct create select sql builder by data
func NewUpdateBuilderFromStruct ¶
func NewUpdateBuilderFromStruct(data any, opt *Option) (*sb.UpdateBuilder, bool)
NewUpdateBuilderFromStruct 使用 data 数据定义 update builder
func ParseOptionStr ¶
ParseOptionStr will decode key-value data from a string which format like k1:v1,k2:v2,k3:v3. it will always return a non-nil value map such as:
- k1:v1,k2:v2 will parsed to {"k1":"v1","k2":"v2"}
- k1,k2 will parsed to {"k1":"","k2":""}
- k1:v2,k2 will parsed to {"k1":"v2","k2":""}
func PatchWhere ¶
PatchWhereTx updates the data that matchthe filter in the table using a transaction. The filter is used as the condition and can be of type KVs, struct, []int64, int64.
func RunInRLock ¶
func RunTxContext ¶
RunTxContext execute a transiction
func RunTxWithOptionContext ¶
func RunTxWithOptionContext(ctx context.Context, opts *sql.TxOptions, f func(ctx context.Context, tx *sqlx.Tx) error) error
RunTxContext execute a transiction with custom options
func Select ¶
Select will query data into dest with raw sql and args.
it will auto query from master if the context having FromMaster
func SelectTx ¶
func SelectTx(ctx context.Context, tx *sqlx.Tx, dest interface{}, sql string, args ...interface{}) error
Select will query data into dest with raw sql and args.
it will auto query from master if the context having FromMaster
func SelectWhere ¶
GetWhere 使用自定义条件跟新数据
func SetGlobalOption ¶
func SetGlobalOption(opt *Option)
SetGlobalOption set option for all the sql execution
func SetMetricHandler ¶
func SetMetricHandler(h MetricHandler)
func Slave ¶
Master return slave *sqlx.DB which returned by DBProvider, panic if DBProvider is not Initilized
func TableName ¶
TableName auto recoganize the table name from data, it will auto prepend the tableNamePrefix which can be set by SetTableNamePrefix to the result.
- having Table() method, it will call d.Table() to get the table name
- type of struct, it will use the struct name, and snake case it
- type of string, return the name.
- type of other, return fmt.Sprintf("%s", d)
func WhereFromKVs ¶
WhereFromStruct generate where exprs from []KV, the returned value can be used by builder.Where method
Types ¶
type FieldOptioner ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option for select or insert data