Documentation ¶
Index ¶
- Variables
- func QueryFmt(fmtStr string, args ...interface{}) (string, error)
- type Affected
- type Boolean
- type CapFunc
- type Capsule
- func (c *Capsule) Close() error
- func (c *Capsule) Delete(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (c *Capsule) Exec(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (c *Capsule) ExecMany(ctx context.Context, queries []string) error
- func (c *Capsule) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (c *Capsule) Insert(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (c *Capsule) InsertMany(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- func (c *Capsule) IsTrans(ctx context.Context) (bool, error)
- func (c *Capsule) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (c *Capsule) StartCapsule(ctx context.Context, isTrans bool, capFunc CapFunc) (interface{}, error)
- func (c *Capsule) Update(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (c *Capsule) UpdateMany(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- type NullBool
- type NullFloat64
- type NullInt32
- type NullInt64
- type NullString
- type NullTime
- type Option
- type SqlY
- func (s *SqlY) Close() error
- func (s *SqlY) Delete(query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) DeleteCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) Exec(query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) ExecCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) ExecMany(queries []string) error
- func (s *SqlY) ExecManyCtx(ctx context.Context, queries []string) error
- func (s *SqlY) Get(dest interface{}, query string, args ...interface{}) error
- func (s *SqlY) GetCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (s *SqlY) Insert(query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) InsertCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) InsertMany(query string, args [][]interface{}) (*Affected, error)
- func (s *SqlY) InsertManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- func (s *SqlY) NewTrans() (*Trans, error)
- func (s *SqlY) Ping() error
- func (s *SqlY) Query(dest interface{}, query string, args ...interface{}) error
- func (s *SqlY) QueryCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (s *SqlY) Transaction(txFunc TxFunc) (interface{}, error)
- func (s *SqlY) Update(query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) UpdateCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (s *SqlY) UpdateMany(query string, args [][]interface{}) (*Affected, error)
- func (s *SqlY) UpdateManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- type Trans
- func (t *Trans) Commit() error
- func (t *Trans) Delete(query string, args ...interface{}) (*Affected, error)
- func (t *Trans) DeleteCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (t *Trans) Exec(query string, args ...interface{}) (*Affected, error)
- func (t *Trans) ExecCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (t *Trans) ExecMany(queries []string) error
- func (t *Trans) ExecManyCtx(ctx context.Context, queries []string) error
- func (t *Trans) Get(dest interface{}, query string, args ...interface{}) error
- func (t *Trans) GetCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (t *Trans) Insert(query string, args ...interface{}) (*Affected, error)
- func (t *Trans) InsertCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (t *Trans) InsertMany(query string, args [][]interface{}) (*Affected, error)
- func (t *Trans) InsertManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- func (t *Trans) Query(dest interface{}, query string, args ...interface{}) error
- func (t *Trans) QueryCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
- func (t *Trans) Rollback() error
- func (t *Trans) Update(query string, args ...interface{}) (*Affected, error)
- func (t *Trans) UpdateCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
- func (t *Trans) UpdateMany(query string, args [][]interface{}) (*Affected, error)
- func (t *Trans) UpdateManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
- type TxFunc
Constants ¶
This section is empty.
Variables ¶
var ( // ErrQueryFmt sql statement format error ErrQueryFmt = errors.New("query can't be formatted") // ErrArgType sql statement format type error ErrArgType = errors.New("invalid variable type for argument") // ErrStatement sql syntax error ErrStatement = errors.New("sql statement syntax error") // ErrContainer container for results ErrContainer = errors.New("invalid container for scanning (struct pointer, not nil)") // ErrFieldsMatch fields not match ErrFieldsMatch = errors.New("queried fields not match with struct fields") // ErrMultiRes multi result for get ErrMultiRes = errors.New("get more than one results for get query") // ErrEmpty empty ErrEmpty = errors.New("no result for get query ") // ErrCapsule Invalid Capsule ErrCapsule = errors.New("query capsule is not available") ErrEmptyArrayInStatement = errors.New("has empty array in query arguments") )
errors
Functions ¶
Types ¶
type Affected ¶
Affected to record lastId for insert, and affected rows for update, inserts, delete statement
type Capsule ¶ added in v1.3.0
type Capsule struct {
// contains filtered or unexported fields
}
Capsule 胶囊对象
func (*Capsule) Get ¶ added in v1.3.0
func (c *Capsule) Get(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Get query one
func (*Capsule) InsertMany ¶ added in v1.3.0
func (c *Capsule) InsertMany(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
InsertMany insert many
func (*Capsule) Query ¶ added in v1.3.0
func (c *Capsule) Query(ctx context.Context, dest interface{}, query string, args ...interface{}) error
Query query
func (*Capsule) StartCapsule ¶ added in v1.3.0
func (c *Capsule) StartCapsule(ctx context.Context, isTrans bool, capFunc CapFunc) (interface{}, error)
StartCapsule 开启查询胶囊
type NullBool ¶
NullBool is an alias for sql.NullBool
func (*NullBool) MarshalJSON ¶
MarshalJSON for NullBool
func (*NullBool) UnmarshalJSON ¶
UnmarshalJSON for NullBool
type NullFloat64 ¶
type NullFloat64 sql.NullFloat64
NullFloat64 is an alias for sql.NullFloat64
func (*NullFloat64) MarshalJSON ¶
func (ns *NullFloat64) MarshalJSON() ([]byte, error)
MarshalJSON for NullFloat64
func (*NullFloat64) Scan ¶
func (ns *NullFloat64) Scan(val interface{}) error
Scan implements the Scanner interface for NullFloat64
func (*NullFloat64) UnmarshalJSON ¶
func (ns *NullFloat64) UnmarshalJSON(b []byte) error
UnmarshalJSON for NullFloat64
type NullInt32 ¶
NullInt32 is an alias for sql.NullInt32
func (*NullInt32) MarshalJSON ¶
MarshalJSON for NullInt32
func (*NullInt32) UnmarshalJSON ¶
UnmarshalJSON for NullInt32
type NullInt64 ¶
NullInt64 is an alias for sql.NullInt64
func (*NullInt64) MarshalJSON ¶
MarshalJSON for NullInt64
func (*NullInt64) UnmarshalJSON ¶
UnmarshalJSON for NullInt64
type NullString ¶
type NullString sql.NullString
NullString is an alias for sql.NullString
func (*NullString) MarshalJSON ¶
func (ns *NullString) MarshalJSON() ([]byte, error)
MarshalJSON for NullString
func (*NullString) Scan ¶
func (ns *NullString) Scan(val interface{}) error
Scan implements the Scanner interface for NullString
func (*NullString) UnmarshalJSON ¶
func (ns *NullString) UnmarshalJSON(b []byte) error
UnmarshalJSON for NullString
type NullTime ¶
NullTime is an alias for sql.NullTime
func (*NullTime) MarshalJSON ¶
MarshalJSON for NullTime
func (*NullTime) UnmarshalJSON ¶
UnmarshalJSON for NullTime
type Option ¶
type Option struct { Dsn string `json:"dsn"` // database server name DriverName string `json:"driver_name"` // database driver MaxIdleConns int `json:"max_idle_conns"` // limit the number of idle connections MaxOpenConns int `json:"max_open_conns"` // limit the number of total open connections ConnMaxLifeTime time.Duration `json:"conn_max_life_time"` // maximum amount of time a connection may be reused }
Option sqly config option
type SqlY ¶
type SqlY struct {
// contains filtered or unexported fields
}
SqlY struct
func (*SqlY) ExecManyCtx ¶
ExecManyCtx execute multi sql statement with context
func (*SqlY) GetCtx ¶
func (s *SqlY) GetCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
GetCtx query the database working with one result
func (*SqlY) InsertMany ¶
InsertMany insert many values to database
func (*SqlY) InsertManyCtx ¶
func (s *SqlY) InsertManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
InsertManyCtx insert many with context
func (*SqlY) QueryCtx ¶
func (s *SqlY) QueryCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
QueryCtx query the database working with results
func (*SqlY) Transaction ¶
Transaction start transaction with callback function
func (*SqlY) UpdateMany ¶ added in v1.2.1
UpdateMany update many
type Trans ¶
type Trans struct {
// contains filtered or unexported fields
}
Trans sql struct for transaction
func (*Trans) DeleteCtx ¶
func (t *Trans) DeleteCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
DeleteCtx delete
func (*Trans) ExecManyCtx ¶
ExecManyCtx execute multi sql statement
func (*Trans) GetCtx ¶
func (t *Trans) GetCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
GetCtx query one row
func (*Trans) InsertCtx ¶
func (t *Trans) InsertCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
InsertCtx insert
func (*Trans) InsertMany ¶
InsertMany insert many rows
func (*Trans) InsertManyCtx ¶
func (t *Trans) InsertManyCtx(ctx context.Context, query string, args [][]interface{}) (*Affected, error)
InsertManyCtx insert many rows
func (*Trans) QueryCtx ¶
func (t *Trans) QueryCtx(ctx context.Context, dest interface{}, query string, args ...interface{}) error
QueryCtx query results
func (*Trans) UpdateCtx ¶
func (t *Trans) UpdateCtx(ctx context.Context, query string, args ...interface{}) (*Affected, error)
UpdateCtx update
func (*Trans) UpdateMany ¶ added in v1.2.1
UpdateMany update many