Documentation
¶
Index ¶
- type Dialector
- type SQLBuilder
- func (b *SQLBuilder) BuildCountSQL(tableName string, whereClause string) string
- func (b *SQLBuilder) BuildDeleteSQL(tableName, pkName string) string
- func (b *SQLBuilder) BuildInsertSQL(tableName string, columns []string) string
- func (b *SQLBuilder) BuildSelectIDsSQL(tableName string, pkName string, where string, args []interface{}, ...) (string, []interface{})
- func (b *SQLBuilder) BuildSelectSQL(tableName string, columns []string) string
- func (b *SQLBuilder) BuildUpdateSQL(tableName string, setClauses []string, pkName string) string
- func (b *SQLBuilder) Rebind(query string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialector ¶
type Dialector interface {
Quote(identifier string) string // Quote a SQL identifier (table/column name)
Placeholder(index int) string // Bind variable placeholder (e.g. ?, $1)
}
Dialector defines how to quote identifiers and bind variables for a specific SQL dialect.
type SQLBuilder ¶
type SQLBuilder struct {
Dialect Dialector
}
SQLBuilder provides SQL generation with dialect-specific identifier quoting.
func NewSQLBuilder ¶
func NewSQLBuilder(dialect Dialector) *SQLBuilder
NewSQLBuilder creates a new SQLBuilder with the given Dialector.
func (*SQLBuilder) BuildCountSQL ¶
func (b *SQLBuilder) BuildCountSQL(tableName string, whereClause string) string
BuildCountSQL constructs a SELECT COUNT(*) statement for the given table and optional WHERE clause.
func (*SQLBuilder) BuildDeleteSQL ¶
func (b *SQLBuilder) BuildDeleteSQL(tableName, pkName string) string
BuildDeleteSQL constructs a DELETE statement for the given table and primary key.
func (*SQLBuilder) BuildInsertSQL ¶
func (b *SQLBuilder) BuildInsertSQL(tableName string, columns []string) string
BuildInsertSQL constructs an INSERT statement for the given table and columns.
func (*SQLBuilder) BuildSelectIDsSQL ¶
func (b *SQLBuilder) BuildSelectIDsSQL(tableName string, pkName string, where string, args []interface{}, order string) (string, []interface{})
BuildSelectIDsSQL constructs a SELECT statement to fetch only primary key IDs. The where argument should already include all conditions (including soft delete if needed).
func (*SQLBuilder) BuildSelectSQL ¶
func (b *SQLBuilder) BuildSelectSQL(tableName string, columns []string) string
BuildSelectSQL constructs a basic SELECT statement for all columns defined in ModelInfo.
func (*SQLBuilder) BuildUpdateSQL ¶
func (b *SQLBuilder) BuildUpdateSQL(tableName string, setClauses []string, pkName string) string
BuildUpdateSQL constructs an UPDATE statement for the given table, set clauses, and primary key.
func (*SQLBuilder) Rebind ¶
func (b *SQLBuilder) Rebind(query string) string
Rebind transforms SQL prepared statements using ? placeholders to the dialect's specific placeholders. For example: PostgreSQL uses $1, $2, etc.