Documentation
¶
Overview ¶
Lightweight and easy to use query builder that works with any SQL dialect.
Index ¶
- Variables
- type Dialect
- type Embedded
- type Embedder
- type Folded
- type JSONList
- type JSONMap
- type Pool
- type Query
- func (q *Query) And(text string, args ...any) *Query
- func (q *Query) Build(dialect *Dialect) (stmt string, args []any, err error)
- func (q *Query) Comma(text string, args ...any) *Query
- func (q *Query) Concat(text string, args ...any) *Query
- func (q *Query) Empty() bool
- func (q *Query) Join(sep, text string, args ...any) *Query
- func (q *Query) Or(text string, args ...any) *Query
- func (q *Query) Space(text string, args ...any) *Query
- func (q *Query) ToPgSQL() (stmt string, args []any, err error)
- func (q *Query) ToSQL() (stmt string, args []any, err error)
- func (q *Query) ToSQLite() (stmt string, args []any, err error)
- type Unfolded
Constants ¶
This section is empty.
Variables ¶
var ( // SQL is the default dialect. // Uses '?' placeholders, expands arrays. SQL = &Dialect{ Placeholder: func(w *bytes.Buffer, i int) { w.WriteByte('?') }, ExpandArrays: true, } // SQLite is the dialect for SQLite. // Uses '?NNN' placeholders, expands arrays. SQLite = &Dialect{ Placeholder: func(w *bytes.Buffer, i int) { w.WriteByte('?') w.WriteString(strconv.Itoa(i)) }, ExpandArrays: true, } // PostgreSQL is the dialect for PostgreSQL. // Uses '$NNN' placeholders, doesn't expand arrays. // Transforms [InValues] into "= ANY" and "!= ALL". PostgreSQL = &Dialect{ Placeholder: func(w *bytes.Buffer, i int) { w.WriteByte('$') w.WriteString(strconv.Itoa(i)) }, ExpandArrays: false, } )
Functions ¶
This section is empty.
Types ¶
type Embedded ¶
type Embedded string
Embedded is a string type that is directly embedded into the query. Note: Like Embedder, this is not to be used for untrusted input.
type Embedder ¶
type Embedder interface {
RawValue() string
}
Embedder embeds a value directly into a query string. Note: Since this is embedded and not bound, attention must be paid to sanitizing this input.
type Folded ¶ added in v0.3.0
type Folded[E any] []E
Folded is a type that tells bqb NOT to expand an array into individual parameters. The array won't be expanded regardless of the ExpandArray setting in a Dialect.
type JSONList ¶
type JSONList []any
JSONList is a type that tells bqb to convert the parameter to a JSON list without requiring reflection.
type JSONMap ¶
JSONMap is a type that tells bqb to convert the parameter to a JSON object without requiring reflection.
type Pool ¶ added in v0.5.0
type Pool struct {
// contains filtered or unexported fields
}
Pool provides a pool of queries that may help reduce memory allocations and GC overhead. Queries creates by the pool will be automatically put into the pool after Query.Build is called and must not be used after the call.
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query is an SQL query builder.
func Optional ¶
Optional returns a new Query that has a conditional prefix which only resolves when at least something is subsequently added to the query.
func (*Query) And ¶
And appends SQL text and params to the query, joining with " AND " if the query already contains something.
func (*Query) Build ¶
Build builds the query into an SQL string and bound args using the given dialect.
func (*Query) Comma ¶
Comma appends SQL text and params to the query, joining with comma if the query already contains something.
func (*Query) Join ¶
Join appends SQL text and params to the query, joining with sep if the query already contains something.
func (*Query) Or ¶
Or appends SQL text and params to the query, joining with " OR " if the query already contains something.
func (*Query) Space ¶
Space appends SQL text and params to the query, joining with space if the query already contains something.
func (*Query) ToPgSQL ¶
ToPgSQL builds the query into an SQL string and bound args using PostgreSQL dialect.