Documentation ¶
Index ¶
- Variables
- func Connect(configs map[string]*Config) (err error)
- func DB(name ...string) *sqlx.DB
- func Exec(query string, args ...interface{}) (sql.Result, error)
- func Expr(expression string, args ...interface{}) *expr
- func Get(dest interface{}, query string, args ...interface{}) error
- func Import(f string) ([]sql.Result, error)
- func IsZero(val reflect.Value) bool
- func List() map[string]*sqlx.DB
- func QueryRowx(query string, args ...interface{}) *sqlx.Row
- func Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
- func RelationAll(data interface{}, chains map[string]BuilderChainFunc) error
- func RelationOne(data interface{}, chains map[string]BuilderChainFunc) error
- func Select(dest interface{}, query string, args ...interface{}) error
- func SetDefaultLink(db string)
- func SetLogger(l Logger)
- func SetLogging(logging bool)
- func Tx(fn func(tx *sqlx.Tx) error) error
- func Txx(ctx context.Context, fn func(ctx context.Context, tx *sqlx.Tx) error) error
- type Builder
- func (b *Builder) All() (err error)
- func (b *Builder) Count(zeroValues ...string) (num int64, err error)
- func (b *Builder) Create() (lastInsertId int64, err error)
- func (b *Builder) Delete(zeroValues ...string) (affected int64, err error)
- func (b *Builder) ForceIndex(i string) *Builder
- func (b *Builder) Get(zeroValues ...string) (err error)
- func (b *Builder) Hint(hint string) *Builder
- func (b *Builder) Limit(i int) *Builder
- func (b *Builder) Offset(i int) *Builder
- func (b *Builder) OrderBy(str string) *Builder
- func (b *Builder) Relation(fieldName string, fn BuilderChainFunc) *Builder
- func (b *Builder) Select(fields string) *Builder
- func (b *Builder) ShowSQL() *Builder
- func (b *Builder) Update(zeroValues ...string) (affected int64, err error)
- func (b *Builder) Where(str string, args ...interface{}) *Builder
- func (b *Builder) WithTx(tx *sqlx.Tx) *Builder
- type BuilderChainFunc
- type Config
- type Hook
- type IModel
- type ISqlx
- type Logger
- type Mapper
- func (m *Mapper) Count() (num int64, err error)
- func (m *Mapper) Create(data map[string]interface{}) (lastInsertId int64, err error)
- func (m *Mapper) Delete() (affected int64, err error)
- func (m *Mapper) ShowSQL() *Mapper
- func (m *Mapper) Update(data map[string]interface{}) (affected int64, err error)
- func (m *Mapper) Where(str string, args ...interface{}) *Mapper
- func (m *Mapper) WithTx(tx *sqlx.Tx) *Mapper
- type QueryStatus
- type ReflectMapper
- type SQLBuilder
- type Wrapper
- func (w *Wrapper) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (w *Wrapper) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (w *Wrapper) Import(f string) ([]sql.Result, error)
- func (w *Wrapper) QueryRowx(query string, args ...interface{}) (rows *sqlx.Row)
- func (w *Wrapper) Queryx(query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (w *Wrapper) Rebind(query string) string
- func (w *Wrapper) Relation(name string, fn BuilderChainFunc) *Wrapper
- func (w *Wrapper) Select(dest interface{}, query string, args ...interface{}) (err error)
- func (w *Wrapper) Table(t string) *Mapper
- func (w *Wrapper) Tx(fn func(tx *sqlx.Tx) error) (err error)
- func (w *Wrapper) Txx(ctx context.Context, fn func(ctx context.Context, tx *sqlx.Tx) error) (err error)
Constants ¶
This section is empty.
Variables ¶
var ( //Insert database automatically updates fields AUTO_CREATE_TIME_FIELDS = []string{ "create_time", "create_at", "created_at", "update_time", "update_at", "updated_at", } //Update database automatically updates fields AUTO_UPDATE_TIME_FIELDS = []string{ "update_time", "update_at", "updated_at", } )
var FatalExit = true
If database fatal exit
Functions ¶
func Expr ¶ added in v1.0.10
func Expr(expression string, args ...interface{}) *expr
Expr generate raw SQL expression, for example:
gosql.Table("user").Update(map[string]interface{}{"price", gorm.Expr("price * ? + ?", 2, 100)})
func RelationAll ¶ added in v1.1.0
func RelationAll(data interface{}, chains map[string]BuilderChainFunc) error
RelationAll is gets the associated relational data for multiple pieces of data
func RelationOne ¶ added in v1.1.0
func RelationOne(data interface{}, chains map[string]BuilderChainFunc) error
RelationOne is get the associated relational data for a single piece of data
func SetDefaultLink ¶ added in v1.1.9
func SetDefaultLink(db string)
SetDefaultLink set default link name
Types ¶
type Builder ¶
type Builder struct { SQLBuilder // contains filtered or unexported fields }
func (*Builder) ForceIndex ¶ added in v1.1.7
ForceIndex
func (*Builder) Relation ¶ added in v1.1.0
func (b *Builder) Relation(fieldName string, fn BuilderChainFunc) *Builder
Relation association table builder handle
type BuilderChainFunc ¶ added in v1.1.1
type BuilderChainFunc func(b *Builder)
type Config ¶
type Config struct { Enable bool `toml:"enable" json:"enable"` Driver string `toml:"driver" json:"driver"` Dsn string `toml:"dsn" json:"dsn"` MaxOpenConns int `toml:"max_open_conns" json:"max_open_conns"` MaxIdleConns int `toml:"max_idle_conns" json:"max_idle_conns"` MaxLifetime int `toml:"max_lefttime" json:"max_lefttime"` ShowSql bool `toml:"show_sql" json:"show_sql"` }
Config is database connection configuration
type Hook ¶ added in v1.0.1
type Hook struct { Errs []error // contains filtered or unexported fields }
type ISqlx ¶
type ISqlx interface { Queryx(query string, args ...interface{}) (*sqlx.Rows, error) QueryRowx(query string, args ...interface{}) *sqlx.Row Get(dest interface{}, query string, args ...interface{}) error Select(dest interface{}, query string, args ...interface{}) error Exec(query string, args ...interface{}) (sql.Result, error) Rebind(query string) string }
type Logger ¶
type Logger interface {
Printf(format string, v ...interface{})
}
Logger represents a logging collector. You can pass a logging collector to gosql.SetLogger(myCollector) to make it collect QueryStatus messages after executing a query.
type Mapper ¶
type Mapper struct { SQLBuilder // contains filtered or unexported fields }
type QueryStatus ¶
QueryStatus represents the status of a query after being executed.
func (*QueryStatus) String ¶
func (q *QueryStatus) String() string
String returns a formatted log message.
type ReflectMapper ¶
type ReflectMapper struct {
// contains filtered or unexported fields
}
func NewReflectMapper ¶
func NewReflectMapper(tagName string) *ReflectMapper
func (*ReflectMapper) FieldByName ¶ added in v1.1.0
FieldByName returns a field by its mapped name as a reflect.Value. Panics if v's Kind is not Struct or v is not Indirectable to a struct Kind. Returns zero Value if the name is not found.
type SQLBuilder ¶
type SQLBuilder struct {
// contains filtered or unexported fields
}
func (*SQLBuilder) Where ¶
func (s *SQLBuilder) Where(str string, args ...interface{})
type Wrapper ¶
type Wrapper struct { RelationMap map[string]BuilderChainFunc // contains filtered or unexported fields }
func Relation ¶ added in v1.1.1
func Relation(name string, fn BuilderChainFunc) *Wrapper
Relation association table builder handle
func (*Wrapper) Relation ¶ added in v1.1.1
func (w *Wrapper) Relation(name string, fn BuilderChainFunc) *Wrapper
Relation association table builder handle
func (*Wrapper) Table ¶
Table database handler from to table name for example gosql.Use("db2").Table("users")