sqlbuilder

package
v0.1.26 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL