Documentation
¶
Overview ¶
Lightweight and easy to use query builder that works with any SQL dialect.
Index ¶
- Variables
- type Dialect
- type Embedded
- type Embedder
- type JSONList
- type JSONMap
- 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) Len() int
- 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 QueryPart
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. 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 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 custom type which tells bqb to convert the parameter to a JSON object without requiring reflection.
type Query ¶
Query contains all the QueryParts for the query and is the primary struct of the bqb package.
func Optional ¶
Optional returns a query object that has a conditional prefix which only resolves when at least one QueryPart has been added.
func (*Query) Build ¶
Build builds the query into a SQL string and bound args using the given dialect.
func (*Query) Concat ¶
Concat concatenates the current QueryPart to the previous QueryPart with a zero space string.
func (*Query) ToPgSQL ¶
ToPgSQL builds the query into a SQL string and bound args using PostgreSQL dialect.