Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Placeholders ¶
Placeholders makes n-th repeats of Go's SQL placeholder(?), joining them by comma(,).
Example:
Placeholder(2) // ?,?
func QuoteColumn ¶
QuoteColumn surrounds SQL identifiers with backquote, keeping some meta-characters "*", ".", "`" intact.
Example:
QuoteColumn("users.id") // `users`.`id` QuoteColumn("users.*") // `users`.*
func QuoteColumns ¶
QuoteColumns quotes each string and joins them by comma(,).
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a dynamic SQL query builder.
func NewBuilder ¶
type Condition ¶
type KeyIterator ¶
type KeyIterator[T any] interface { Get(i int) (string, T) Keys() []string Values() []T Size() int Map() map[string]T }
func NewKeyIterator ¶
func NewKeyIterator[T any](data map[string]T) KeyIterator[T]
type Query ¶
func Cols ¶
Cols wraps given identifiers like column, and table with backquote as possible. It is used for embedding table names or columns into queries dynamically. If multiple values are given, they will be joined by a comma(,).
Example:
Cols("aaa","bbb") // `aaa`,`bbb` Cols("users.*") // `users`.*
func New ¶
New returns Query based on given query and arguments. First argument query can contain exql placeholder format (:?) with the corresponding Query in rest arguments. Given query component will be interpolated internally and embedded into the final SQL statement. Except (:?) placeholders, all static statements will be embedded barely with no assertions. You must pay attention to the input query if it is variable.
func Set ¶
Set transforms map into "key = value" assignment expression in SQL. Example:
values := map[string]any{ "name": "go", "age": 20} db.Exec("update users set :? where id = ?", query.Set(values, 1))
is the same as:
db.DB().Exec("update users set age = ?, name = ? where id = ?", 20, "go", 1)
func V ¶
V wraps one or more values for the prepared statement. It counts number of values and interpolates Go's SQL placeholder(?), holding values for later. Multiple values will be joined by comma(,).
Example:
V(1,"a") // ?,? -> query | [1,"a"] -> arguments
The code below
db.Query(query.New("select * from users where id in (:?)", query.V(1,2)))
is the same as:
db.DB().Query("select * from users where id in (?,?)", 1, 2)