Documentation
¶
Index ¶
- func SetDialect(d Dialect)
- type Builder
- func (b *Builder) Build() (string, []any)
- func (b *Builder) FullJoin(table, on string) *Builder
- func (b *Builder) Join(table, on string) *Builder
- func (b *Builder) LeftJoin(table, on string) *Builder
- func (b *Builder) Limit(limit int) *Builder
- func (b *Builder) Offset(offset int) *Builder
- func (b *Builder) OrderBy(order string) *Builder
- func (b *Builder) RightJoin(table, on string) *Builder
- func (b *Builder) Select(cols ...string) *Builder
- func (b *Builder) Where(conds ...Condition) *Builder
- type Column
- func (c Column) Between(start, end any) Condition
- func (c Column) Eq(val any) Condition
- func (c Column) Gt(val any) Condition
- func (c Column) Gte(val any) Condition
- func (c Column) In(vals ...any) Condition
- func (c Column) IsNotNull() Condition
- func (c Column) IsNull() Condition
- func (c Column) Like(pattern string) Condition
- func (c Column) Lt(val any) Condition
- func (c Column) Lte(val any) Condition
- func (c Column) Neq(val any) Condition
- func (c Column) NotBetween(start, end any) Condition
- func (c Column) NotIn(vals ...any) Condition
- func (c Column) NotLike(pattern string) Condition
- type Condition
- type DeleteBuilder
- type Dialect
- type InsertBuilder
- func (b *InsertBuilder) Columns(cols ...string) *InsertBuilder
- func (b *InsertBuilder) Returning(cols ...string) *InsertBuilder
- func (b *InsertBuilder) ReturningID() *InsertBuilder
- func (b *InsertBuilder) ToSQL() (string, []interface{})
- func (b *InsertBuilder) Values(vals ...interface{}) *InsertBuilder
- type MariaDBDialect
- type MySQLDialect
- type PostgresDialect
- type RawSQL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDialect ¶
func SetDialect(d Dialect)
SetDialect sets the global SQL dialect for all queries. Example: query.SetDialect(query.PostgresDialect{})
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds SQL SELECT queries in a fluent DSL style. It supports SELECT, WHERE, ORDER BY, LIMIT, OFFSET.
type Column ¶
type Column struct {
// contains filtered or unexported fields
}
Column wraps a SQL column name and provides methods for building conditions.
func C ¶
C creates a new column reference that can be used to build conditions. Example: query.C("age").Gt(18)
func (Column) Like ¶
Like creates a condition: "column LIKE ?". Example: query.C("name").Like("%john%")
func (Column) NotBetween ¶
NotBetween creates a condition: "column NOT BETWEEN ? AND ?".
type Condition ¶
type Condition struct {
Expr string // SQL expression with placeholders (e.g., "age > ?")
Args []any // Values to bind into placeholders
}
Condition represents a SQL WHERE condition expression and its bound arguments. Example: Condition{Expr: "age > ?", Args: []any{18}}
type DeleteBuilder ¶
type DeleteBuilder struct {
// contains filtered or unexported fields
}
DeleteBuilder builds SQL DELETE queries with dialect support.
func Delete ¶
func Delete(table string) *DeleteBuilder
Delete creates a new DeleteBuilder for the given table.
Example:
q := query.Delete("users").
Where("id = ?", 42)
sql, args := q.Build()
MySQL: "DELETE FROM users WHERE id = ?"
Postgres: "DELETE FROM users WHERE id = $1"
args: [42]
func (*DeleteBuilder) Build ¶
func (b *DeleteBuilder) Build() (string, []any)
Build assembles the SQL DELETE query string and returns it with args. It rewrites placeholders depending on the active dialect.
func (*DeleteBuilder) Where ¶
func (b *DeleteBuilder) Where(conds ...Condition) *DeleteBuilder
Where adds a WHERE clause to the DELETE query. Multiple calls are joined with AND.
type Dialect ¶
type Dialect interface {
// Placeholder returns the placeholder string for the given index.
// Example: $1 for PostgreSQL, ? for MySQL/MariaDB.
Placeholder(index int) string
// Name returns the name of the dialect (for debugging/logging).
Name() string
}
Dialect defines the behavior that differs across SQL databases. For example, how parameter placeholders are represented.
type InsertBuilder ¶
type InsertBuilder struct {
// contains filtered or unexported fields
}
InsertBuilder builds SQL INSERT statements.
func InsertInto ¶
func InsertInto(table string) *InsertBuilder
InsertInto creates a new InsertBuilder for the given table. Example: query.InsertInto("users")
func (*InsertBuilder) Columns ¶
func (b *InsertBuilder) Columns(cols ...string) *InsertBuilder
Columns sets the columns for the INSERT statement. Example: .Columns("id", "name")
func (*InsertBuilder) Returning ¶
func (b *InsertBuilder) Returning(cols ...string) *InsertBuilder
Returning specifies columns to return (Postgres style). Example: .Returning("id", "created_at")
func (*InsertBuilder) ReturningID ¶
func (b *InsertBuilder) ReturningID() *InsertBuilder
ReturningID is a convenience method for "RETURNING id".
func (*InsertBuilder) ToSQL ¶
func (b *InsertBuilder) ToSQL() (string, []interface{})
ToSQL builds the final INSERT query and returns the SQL string and arguments. Example output: "INSERT INTO users (id, name) VALUES (?, ?) RETURNING id", [1, "John"]
func (*InsertBuilder) Values ¶
func (b *InsertBuilder) Values(vals ...interface{}) *InsertBuilder
Values adds a row of values to insert. Supports RawSQL for literals. Example: .Values(1, "John", query.Raw("NOW()"))
type MariaDBDialect ¶
type MariaDBDialect struct{}
MariaDBDialect behaves the same as MySQL for placeholders.
func (MariaDBDialect) Placeholder ¶
func (d MariaDBDialect) Placeholder(_ int) string
Placeholder returns "?" for all indexes.
type MySQLDialect ¶
type MySQLDialect struct{}
MySQLDialect uses "?" placeholders.
func (MySQLDialect) Placeholder ¶
func (d MySQLDialect) Placeholder(_ int) string
Placeholder returns "?" for all indexes.
type PostgresDialect ¶
type PostgresDialect struct{}
PostgresDialect uses "$1, $2, ..." placeholders.
func (PostgresDialect) Placeholder ¶
func (d PostgresDialect) Placeholder(i int) string
Placeholder returns "$n".
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mariadb registers the PostgreSQL dialect for the OCA query builder.
|
Package mariadb registers the PostgreSQL dialect for the OCA query builder. |
|
Package mysql registers the PostgreSQL dialect for the OCA query builder.
|
Package mysql registers the PostgreSQL dialect for the OCA query builder. |
|
Package pgsql registers the PostgreSQL dialect for the OCA query builder.
|
Package pgsql registers the PostgreSQL dialect for the OCA query builder. |