Documentation
¶
Index ¶
- Variables
- func ValidateOperator(op string) (string, error)
- type AggregateClause
- type Dialect
- type JoinClause
- type MySQLDialect
- func (d *MySQLDialect) AutoIncrementSQL() string
- func (d *MySQLDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
- func (d *MySQLDialect) CompileInsert(table string, columns []string, values [][]any) (string, []any)
- func (d *MySQLDialect) CompileSelect(query SelectQuery) (string, []any)
- func (d *MySQLDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
- func (d *MySQLDialect) CompileUpsert(table string, columns []string, values [][]any, conflictCols []string, ...) (string, []any)
- func (d *MySQLDialect) Placeholder(index int) string
- func (d *MySQLDialect) QuoteIdentifier(name string) string
- type OrderByClause
- type PostgresDialect
- func (d *PostgresDialect) AutoIncrementSQL() string
- func (d *PostgresDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
- func (d *PostgresDialect) CompileInsert(table string, columns []string, values [][]any) (string, []any)
- func (d *PostgresDialect) CompileSelect(query SelectQuery) (string, []any)
- func (d *PostgresDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
- func (d *PostgresDialect) CompileUpsert(table string, columns []string, values [][]any, conflictCols []string, ...) (string, []any)
- func (d *PostgresDialect) Placeholder(index int) string
- func (d *PostgresDialect) QuoteIdentifier(name string) string
- type SQLiteDialect
- func (d *SQLiteDialect) AutoIncrementSQL() string
- func (d *SQLiteDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
- func (d *SQLiteDialect) CompileInsert(table string, columns []string, values [][]any) (string, []any)
- func (d *SQLiteDialect) CompileSelect(query SelectQuery) (string, []any)
- func (d *SQLiteDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
- func (d *SQLiteDialect) CompileUpsert(table string, columns []string, values [][]any, conflictCols []string, ...) (string, []any)
- func (d *SQLiteDialect) Placeholder(index int) string
- func (d *SQLiteDialect) QuoteIdentifier(name string) string
- type SelectQuery
- type WhereClause
Constants ¶
This section is empty.
Variables ¶
var ValidOperators = map[string]bool{ "=": true, "==": true, "!=": true, "<>": true, ">": true, "<": true, ">=": true, "<=": true, "LIKE": true, "NOT LIKE": true, "ILIKE": true, "IN": true, "NOT IN": true, "IS": true, "IS NOT": true, "BETWEEN": true, "NOT BETWEEN": true, }
ValidOperators is the whitelist of allowed SQL comparison operators.
Functions ¶
func ValidateOperator ¶
ValidateOperator checks if an operator is in the whitelist. Returns the operator if valid, or an error message if not.
Types ¶
type AggregateClause ¶
type AggregateClause struct {
Function string // COUNT, MAX, MIN, SUM, AVG
Column string // usually * or a column name
}
AggregateClause represents an aggregate function to apply instead of selecting columns.
type Dialect ¶
type Dialect interface {
// QuoteIdentifier quotes a table or column name (e.g. `col` for MySQL, "col" for Postgres)
QuoteIdentifier(name string) string
// Placeholder returns the bind parameter placeholder for a given index (1-based).
// e.g. $1 for Postgres, ? for MySQL/SQLite
Placeholder(index int) string
// CompileSelect compiles a SELECT statement
CompileSelect(query SelectQuery) (string, []any)
// CompileInsert compiles an INSERT statement
CompileInsert(table string, columns []string, values [][]any) (string, []any)
// CompileUpdate compiles an UPDATE statement
CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
// CompileDelete compiles a DELETE statement
CompileDelete(table string, wheres []WhereClause) (string, []any)
// CompileUpsert compiles an INSERT ... ON CONFLICT (or equivalent) statement.
CompileUpsert(table string, columns []string, values [][]any, conflictCols []string, updateCols []string) (string, []any)
// AutoIncrementSQL returns the SQL fragment for an auto-increment primary key column.
AutoIncrementSQL() string
}
QuoteIdentifier quotes a table or column name (e.g. `col` for MySQL, "col" for Postgres)
type JoinClause ¶
type JoinClause struct {
Type string // INNER, LEFT, RIGHT, CROSS
Table string
First string
Operator string
Second string
}
JoinClause represents a table JOIN condition.
type MySQLDialect ¶
type MySQLDialect struct{}
MySQLDialect implements the Dialect interface for MySQL.
func (*MySQLDialect) AutoIncrementSQL ¶
func (d *MySQLDialect) AutoIncrementSQL() string
func (*MySQLDialect) CompileDelete ¶
func (d *MySQLDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
func (*MySQLDialect) CompileInsert ¶
func (*MySQLDialect) CompileSelect ¶
func (d *MySQLDialect) CompileSelect(query SelectQuery) (string, []any)
func (*MySQLDialect) CompileUpdate ¶
func (d *MySQLDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
func (*MySQLDialect) CompileUpsert ¶
func (*MySQLDialect) Placeholder ¶
func (d *MySQLDialect) Placeholder(index int) string
func (*MySQLDialect) QuoteIdentifier ¶
func (d *MySQLDialect) QuoteIdentifier(name string) string
type OrderByClause ¶
OrderByClause represents an ORDER BY condition.
type PostgresDialect ¶
type PostgresDialect struct{}
PostgresDialect implements the Dialect interface for PostgreSQL.
func (*PostgresDialect) AutoIncrementSQL ¶
func (d *PostgresDialect) AutoIncrementSQL() string
func (*PostgresDialect) CompileDelete ¶
func (d *PostgresDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
func (*PostgresDialect) CompileInsert ¶
func (*PostgresDialect) CompileSelect ¶
func (d *PostgresDialect) CompileSelect(query SelectQuery) (string, []any)
func (*PostgresDialect) CompileUpdate ¶
func (d *PostgresDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
func (*PostgresDialect) CompileUpsert ¶
func (*PostgresDialect) Placeholder ¶
func (d *PostgresDialect) Placeholder(index int) string
func (*PostgresDialect) QuoteIdentifier ¶
func (d *PostgresDialect) QuoteIdentifier(name string) string
type SQLiteDialect ¶
type SQLiteDialect struct{}
SQLiteDialect implements the Dialect interface for SQLite.
func (*SQLiteDialect) AutoIncrementSQL ¶
func (d *SQLiteDialect) AutoIncrementSQL() string
func (*SQLiteDialect) CompileDelete ¶
func (d *SQLiteDialect) CompileDelete(table string, wheres []WhereClause) (string, []any)
func (*SQLiteDialect) CompileInsert ¶
func (*SQLiteDialect) CompileSelect ¶
func (d *SQLiteDialect) CompileSelect(query SelectQuery) (string, []any)
func (*SQLiteDialect) CompileUpdate ¶
func (d *SQLiteDialect) CompileUpdate(table string, values map[string]any, wheres []WhereClause) (string, []any)
func (*SQLiteDialect) CompileUpsert ¶
func (*SQLiteDialect) Placeholder ¶
func (d *SQLiteDialect) Placeholder(index int) string
func (*SQLiteDialect) QuoteIdentifier ¶
func (d *SQLiteDialect) QuoteIdentifier(name string) string
type SelectQuery ¶
type SelectQuery struct {
Table string
Columns []string
RawColumns []string // Raw SQL expressions (e.g. "COUNT(*) as total") — not quoted
Wheres []WhereClause
OrderBys []OrderByClause
Joins []JoinClause
Aggregate *AggregateClause
Limit *int
Offset *int
GroupBys []string
Havings []WhereClause
Lock string // e.g. "FOR UPDATE", "FOR SHARE" for pessimistic locking
Distinct bool // SELECT DISTINCT
}
SelectQuery represents the components of a SELECT query for compilation.