Documentation ¶
Index ¶
- Variables
- func Conn(name string) *sql.DB
- func DefConn() *sql.DB
- func DefXConn() *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 JsonObject(value interface{}) (json.RawMessage, error)
- func QueryRowx(query string, args ...interface{}) *sqlx.Row
- func Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
- func Reg(name, dbType string, dataSource string, maxOpenConns int) error
- func RegisterDialect(name string, dialect Dialect)
- 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 SetLogger(l Logger)
- func SetLogging(logging bool)
- func Tx(fn func(tx *DB) error) error
- func Txx(ctx context.Context, fn func(ctx context.Context, tx *DB) error) error
- func XConn(name string) *sqlx.DB
- 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
- type BuilderChainFunc
- type DB
- func (w *DB) Begin() (*DB, error)
- func (w *DB) Commit() error
- func (w *DB) DriverName() string
- func (w *DB) Exec(query string, args ...interface{}) (result sql.Result, err error)
- func (w *DB) Get(dest interface{}, query string, args ...interface{}) (err error)
- func (w *DB) Import(f string) ([]sql.Result, error)
- func (w *DB) Model(m interface{}) *Builder
- func (w *DB) Preparex(query string) (*sqlx.Stmt, error)
- func (w *DB) QueryRowx(query string, args ...interface{}) (rows *sqlx.Row)
- func (w *DB) Queryx(query string, args ...interface{}) (rows *sqlx.Rows, err error)
- func (w *DB) Rebind(query string) string
- func (w *DB) Relation(name string, fn BuilderChainFunc) *DB
- func (w *DB) Rollback() error
- func (w *DB) Select(dest interface{}, query string, args ...interface{}) (err error)
- func (w *DB) ShowSql() *DB
- func (w *DB) Table(t string) *Mapper
- func (w *DB) Tx(fn func(w *DB) error) (err error)
- func (w *DB) Txx(ctx context.Context, fn func(ctx context.Context, tx *DB) error) (err error)
- type DBConfig
- type DBConn
- type Dialect
- type Hook
- type IModel
- type ISqlx
- type JSONText
- func (j JSONText) MarshalBinary() ([]byte, error)
- func (j JSONText) MarshalJSON() ([]byte, error)
- func (j *JSONText) Scan(src interface{}) error
- func (j JSONText) String() string
- func (j *JSONText) Unmarshal(v interface{}) error
- func (j *JSONText) UnmarshalBinary(data []byte) error
- func (j *JSONText) UnmarshalJSON(data []byte) error
- func (j JSONText) Value() (driver.Value, error)
- 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
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", } )
Functions ¶
func DefXConn ¶
获得default *sqlx.DB
获得前必须保证 Reg 过,否则会 panic
请不要使用migration特性
@see github.com/jmoiron/sqlx
func Expr ¶
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 JsonObject ¶
func JsonObject(value interface{}) (json.RawMessage, error)
func RegisterDialect ¶
RegisterDialect register new dialect
func RelationAll ¶
func RelationAll(data interface{}, chains map[string]BuilderChainFunc) error
RelationAll is gets the associated relational data for multiple pieces of data
func RelationOne ¶
func RelationOne(data interface{}, chains map[string]BuilderChainFunc) error
RelationOne is get the associated relational data for a single piece of data
Types ¶
type Builder ¶
type Builder struct { SQLBuilder // contains filtered or unexported fields }
func (*Builder) Relation ¶
func (b *Builder) Relation(fieldName string, fn BuilderChainFunc) *Builder
Relation association table builder handle
type BuilderChainFunc ¶
type BuilderChainFunc func(b *Builder)
type DB ¶
type DB struct { RelationMap map[string]BuilderChainFunc // contains filtered or unexported fields }
func Begin ¶
Beginx begins a transaction for default database and returns an *gosql.DB instead of an *sql.Tx.
func Relation ¶
func Relation(name string, fn BuilderChainFunc) *DB
Relation association table builder handle
func UseDefault ¶
func UseDefault() *DB
func (*DB) Model ¶
Model database handler from to struct for example: gosql.Use("db2").Model(&users{})
func (*DB) Relation ¶
func (w *DB) Relation(name string, fn BuilderChainFunc) *DB
Relation association table builder handle
type Dialect ¶
type Dialect interface { // GetName get dialect's name GetName() string // Quote quotes field name to avoid SQL parsing exceptions by using a reserved word as a field name Quote(key string) string }
Dialect interface contains behaviors that differ across SQL database
func GetDialect ¶
GetDialect gets the dialect for the specified dialect name
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) Preparex(query string) (*sqlx.Stmt, error) Rebind(query string) string DriverName() string }
type JSONText ¶
type JSONText json.RawMessage
JSONText is a json.RawMessage, which is a []byte underneath. Value() validates the json format in the source, and returns an error if the json is not valid. Scan does no validation. JSONText additionally implements `Unmarshal`, which unmarshals the json within to an interface{}
func (JSONText) MarshalBinary ¶
func (JSONText) MarshalJSON ¶
MarshalJSON returns the *j as the JSON encoding of j.
func (*JSONText) UnmarshalBinary ¶
func (*JSONText) UnmarshalJSON ¶
UnmarshalJSON sets *j to a copy of data
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 ¶
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{})