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 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 Select(dest interface{}, query string, args ...interface{}) error
- 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) 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) ShowSQL() *Builder
- func (b *Builder) Update(zeroValues ...string) (affected int64, err error)
- func (b *Builder) Where(str string, args ...interface{}) *Builder
- 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
- 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) 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 ¶
View Source
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", } )
View Source
var Default = "default"
Default set database default tag name
View Source
var FatalExit = true
If database fatal exit
Functions ¶
Types ¶
type Builder ¶
type Builder struct { SQLBuilder // contains filtered or unexported fields }
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) }
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
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 {
// contains filtered or unexported fields
}
func (*Wrapper) Table ¶
Table database handler from to table name for example gosql.Use("db2").Table("users")
Click to show internal directories.
Click to hide internal directories.