Documentation ¶
Index ¶
- func BatchInsert(conn Executor, rows interface{}, opts ...InsertOpt) (result sql.Result, err error)
- func MakeBatchInsertSQL(rows interface{}, opts ...InsertOpt) (sql string, args []interface{})
- type Bitmap
- type Condition
- func (p *Condition) And(clause string, args ...interface{}) *Condition
- func (p *Condition) AndCond(c *Condition) *Condition
- func (p *Condition) Build() (string, []interface{})
- func (p *Condition) IfAnd(cond bool, clause string, args ...interface{}) *Condition
- func (p *Condition) IfAndCond(cond bool, c *Condition) *Condition
- func (p *Condition) IfOr(cond bool, clause string, args ...interface{}) *Condition
- func (p *Condition) IfOrCond(cond bool, c *Condition) *Condition
- func (p *Condition) Or(clause string, args ...interface{}) *Condition
- func (p *Condition) OrCond(c *Condition) *Condition
- func (p *Condition) String() string
- type ContextExecutor
- type Executor
- type InsertOpt
- type InsertOptions
- type JSON
- type LazyBinary
- type Unmarshaler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchInsert ¶
BatchInsert generates SQL and executes it on the provided Executor. The provided param `rows` must be a slice of struct or pointer to struct, and the slice must have at least one element, or it returns error.
func MakeBatchInsertSQL ¶
MakeBatchInsertSQL generates SQL and returns the arguments to execute on database connection. The provided param `rows` must be a slice of struct or pointer to struct, and the slice must have at least one element, or it panics.
The returned query uses `?` as parameter placeholder, if you are using this function with database which don't use `?` as placeholder, you may check the `Rebind` function from package `github.com/jmoiron/sqlx` to replace placeholders.
Types ¶
type Bitmap ¶ added in v0.5.0
type Bitmap int
Bitmap represents a bitmap value, it implements sql/driver.Valuer and sql.Scanner. Bitmap provides Get, Set and Clear methods to manipulate the bitmap value.
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
Condition represents a query filter to work with SQL query.
func And ¶
And returns a new *Condition which is combination of given conditions using the "AND" operator.
func Or ¶
Or returns a new *Condition which is combination of given conditions using the "OR" operator.
func (*Condition) AndCond ¶ added in v0.15.3
AndCond combines the given Condition using "AND" operator.
func (*Condition) IfAnd ¶
IfAnd checks cond, if cond is true, it combines the query filter to Condition using "AND" operator.
func (*Condition) IfAndCond ¶ added in v0.15.3
IfAndCond checks cond, if cond is true, it combines the given Condition using "AND" operator.
func (*Condition) IfOr ¶
IfOr checks cond, it cond is true, it combines the query filter to Condition using "OR" operator.
func (*Condition) IfOrCond ¶ added in v0.15.3
IfOrCond checks cond, if cond is true, it combines the given Condition using "OR" operator.
type ContextExecutor ¶
type ContextExecutor interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
ContextExecutor is an optional interface to support context execution. If `BatchInsert` function is called with `WithContext` option, and the provided Executor implements this interface, then the method `ExecContext` will be called instead of the method `Exec`.
type Executor ¶
Executor is the minimal interface for batch inserting requires. The interface is implemented by *sql.DB, *sql.Tx, *sqlx.DB, *sqlx.Tx.
type InsertOpt ¶
type InsertOpt func(*InsertOptions)
InsertOpt represents an inserting option to use with batch inserting operation.
func OmitColumns ¶ added in v0.5.2
OmitColumns exclude given columns from the generated query.
func OnConflict ¶
OnConflict appends the postgresql "ON CONFLICT" clause to the generated query.
func OnDuplicateKey ¶
OnDuplicateKey appends the mysql "ON DUPLICATE KEY" clause to the generated query.
func WithContext ¶
WithContext makes the query executed with `ExecContext` if available.
func WithIgnore ¶
func WithIgnore() InsertOpt
WithIgnore adds the mysql "IGNORE" adverb to the the generated query.
type InsertOptions ¶
type InsertOptions struct { Context context.Context TableName string Quote string OmitCols []string Ignore bool OnDuplicateKey string OnConflict string }
InsertOptions holds options to use with batch inserting operation.
type JSON ¶ added in v0.9.0
JSON holds a map[string]interface{} value, it implements sql/driver.Valuer and sql.Scanner. It uses JSON to do serialization.
JSON embeds a gemap.Map, thus all methods defined on gemap.Map is also available from a JSON instance.
func (JSON) MarshalJSON ¶ added in v0.16.3
func (*JSON) UnmarshalJSON ¶ added in v0.16.3
type LazyBinary ¶ added in v0.5.0
type LazyBinary struct {
// contains filtered or unexported fields
}
LazyBinary is a lazy wrapper around a binary value, where the underlying object will be unmarshalled the first time it is needed and cached. It implements sql/driver.Valuer and sql.Scanner.
LazyBinary provides same concurrency safety as []byte, it's safe for concurrent read, but not safe for concurrent write or read/write.
See types_test.go for example usage.
func NewLazyBinary ¶ added in v0.5.0
func NewLazyBinary(raw []byte) LazyBinary
NewLazyBinary creates a new lazy binary wrapper, delaying the unmarshalling work until it is first needed.
func (*LazyBinary) Get ¶ added in v0.5.0
func (p *LazyBinary) Get(unmarshalFunc Unmarshaler) (interface{}, error)
Get returns the underlying data wrapped by the LazyBinary wrapper, if the data has not been unmarshalled, it will be unmarshalled using the provided unmarshalFunc. The unmarshalling work will do only once, the result data and error will be cached and reused for further calling.
func (*LazyBinary) GetBytes ¶ added in v0.5.0
func (p *LazyBinary) GetBytes() []byte
GetBytes returns the underlying byte slice.
func (*LazyBinary) Scan ¶ added in v0.5.0
func (p *LazyBinary) Scan(src interface{}) error
Scan implements sql.Scanner interface.
func (*LazyBinary) Set ¶ added in v0.5.0
func (p *LazyBinary) Set(b []byte, data interface{})
Set sets the data and marshaled bytes to the LazyBinary wrapper. If the param data is nil, the underlying cache will be removed.
type Unmarshaler ¶ added in v0.5.0
Unmarshaler is a function which unmarshalls data from a byte slice.