Documentation ¶
Index ¶
- func BatchInsert(conn Executor, rows any, opts ...InsertOpt) (result sql.Result, err error)
- func MakeBatchInsertSQL(rows any, opts ...InsertOpt) (sql string, args []any)
- type Bitmap
- type Condition
- func (p *Condition) And(clause string, args ...any) *Condition
- func (p *Condition) AndCond(c *Condition) *Condition
- func (p *Condition) Build() (string, []any)
- func (p *Condition) IfAnd(cond bool, clause string, args ...any) *Condition
- func (p *Condition) IfAndCond(cond bool, c *Condition) *Condition
- func (p *Condition) IfOr(cond bool, clause string, args ...any) *Condition
- func (p *Condition) IfOrCond(cond bool, c *Condition) *Condition
- func (p *Condition) Or(clause string, args ...any) *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 ¶
type Bitmap[T constraints.Integer] struct { // contains filtered or unexported fields }
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.
func NewBitmap ¶
func NewBitmap[T constraints.Integer](val *T) Bitmap[T]
NewBitmap returns a new bitmap value.
func (Bitmap[T]) Underlying ¶
func (b Bitmap[T]) Underlying() T
Underlying returns the underlying integer 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) IfAnd ¶
IfAnd checks cond, if cond is true, it combines the query filter to Condition using "AND" operator.
func (*Condition) IfAndCond ¶
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 ¶
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 ...any) (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 ¶
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 ¶
JSON holds a map[string]any 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 ¶
func (*JSON) UnmarshalJSON ¶
type LazyBinary ¶
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 ¶
func NewLazyBinary(raw []byte) LazyBinary
NewLazyBinary creates a new lazy binary wrapper, delaying the unmarshalling work until it is first needed.
func (*LazyBinary) Get ¶
func (p *LazyBinary) Get(unmarshalFunc Unmarshaler) (any, 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 ¶
func (p *LazyBinary) GetBytes() []byte
GetBytes returns the underlying byte slice.
func (*LazyBinary) Scan ¶
func (p *LazyBinary) Scan(src any) error
Scan implements sql.Scanner interface.
func (*LazyBinary) Set ¶
func (p *LazyBinary) Set(b []byte, data any)
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 ¶
Unmarshaler is a function which unmarshalls data from a byte slice.