Documentation
¶
Index ¶
- func BatchProcessingError(recordIndex int, cause error) error
- func DialectError(message string, cause error) error
- func FieldMappingError(fieldName, dbName string, cause error) error
- func InvalidInputError(message string, cause error) error
- func StructParsingError(structType reflect.Type, cause error) error
- func ValidationError(message string) error
- type AndCondition
- type BetweenCondition
- type ComparisonCondition
- type InCondition
- type LiteralCondition
- type NullCondition
- type OrCondition
- type RawCondition
- type SimpleCondition
- type SqlBuilder
- func (s *SqlBuilder) BuildSQLBatchInsert(tableName string, data []any) (string, []any, error)
- func (s *SqlBuilder) BuildSQLInsert(tableName string, data any) (string, []any, error)
- func (s *SqlBuilder) Dialect() SqlDialect
- func (s *SqlBuilder) InsertReturning(tableName string, data any, returningFields []string) (string, []any, error)
- func (s *SqlBuilder) Update(tableName string, record any) *UpdateBuilder
- type SqlDialect
- type SqlError
- type UpdateBuilder
- func (b *UpdateBuilder) AddReturning(fields ...string) *UpdateBuilder
- func (b *UpdateBuilder) Build() (string, []any, error)
- func (b *UpdateBuilder) ByID(id any) *UpdateBuilder
- func (b *UpdateBuilder) ExcludeFields(fields ...string) *UpdateBuilder
- func (b *UpdateBuilder) FieldsValues(fieldValues map[string]any) *UpdateBuilder
- func (b *UpdateBuilder) HasReturnFields() bool
- func (b *UpdateBuilder) IncludeFields(fields ...string) *UpdateBuilder
- func (b *UpdateBuilder) IncludeZeroValues(include bool) *UpdateBuilder
- func (b *UpdateBuilder) Returning(fields ...string) *UpdateBuilder
- func (b *UpdateBuilder) ReturningAll() *UpdateBuilder
- func (b *UpdateBuilder) Set(where WhereClause, options *UpdateOptions) *UpdateBuilder
- func (b *UpdateBuilder) UpdateAutoFields(update bool) *UpdateBuilder
- func (b *UpdateBuilder) Where(clause WhereClause) *UpdateBuilder
- func (b *UpdateBuilder) WhereAnd(conditions ...WhereClause) *UpdateBuilder
- func (b *UpdateBuilder) WhereAndBuild(conditions ...WhereClause) (string, []any, error)
- func (b *UpdateBuilder) WhereBetween(field string, start, end any) *UpdateBuilder
- func (b *UpdateBuilder) WhereEq(field string, value any) *UpdateBuilder
- func (b *UpdateBuilder) WhereIn(field string, values ...any) *UpdateBuilder
- func (b *UpdateBuilder) WhereLiteral(sql string, values ...any) *UpdateBuilder
- func (b *UpdateBuilder) WhereNotNull(field string) *UpdateBuilder
- func (b *UpdateBuilder) WhereNull(field string) *UpdateBuilder
- func (b *UpdateBuilder) WhereOr(conditions ...WhereClause) *UpdateBuilder
- func (b *UpdateBuilder) WhereRaw(sql string) *UpdateBuilder
- func (b *UpdateBuilder) WithOptions(options *UpdateOptions) *UpdateBuilder
- type UpdateOptions
- type WhereClause
- func And(conditions ...WhereClause) WhereClause
- func Between(field string, start, end any) WhereClause
- func Compare(leftField, operator, rightField string) WhereClause
- func Cond(field, operator string, value any) WhereClause
- func Eq(field string, value any) WhereClause
- func Gt(field string, value any) WhereClause
- func Gte(field string, value any) WhereClause
- func In(field string, values ...any) WhereClause
- func IsNotNull(field string) WhereClause
- func IsNull(field string) WhereClause
- func Like(field string, pattern string) WhereClause
- func Literal(sql string, values ...any) WhereClause
- func Lt(field string, value any) WhereClause
- func Lte(field string, value any) WhereClause
- func NotEq(field string, value any) WhereClause
- func NotLike(field string, pattern string) WhereClause
- func Or(conditions ...WhereClause) WhereClause
- func Raw(sql string) WhereClause
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchProcessingError ¶
func DialectError ¶
func FieldMappingError ¶
func InvalidInputError ¶
Common error constructors
func ValidationError ¶
Types ¶
type AndCondition ¶
type AndCondition struct {
Conditions []WhereClause
}
AndCondition represents multiple conditions joined by AND
type BetweenCondition ¶
BetweenCondition for BETWEEN operator
type ComparisonCondition ¶
ComparisonCondition for field-to-field comparisons
type InCondition ¶
InCondition for IN operator
type LiteralCondition ¶
LiteralCondition represents a raw SQL fragment with placeholders
type NullCondition ¶
NullCondition for IS NULL / IS NOT NULL
type OrCondition ¶
type OrCondition struct {
Conditions []WhereClause
}
OrCondition represents multiple conditions joined by OR
type RawCondition ¶
type RawCondition struct {
SQL string
}
RawCondition for completely raw SQL (no placeholder processing)
type SimpleCondition ¶
SimpleCondition represents a single WHERE condition (replaces WhereCondition)
type SqlBuilder ¶
type SqlBuilder struct {
// contains filtered or unexported fields
}
func NewSqlBuilder ¶
func NewSqlBuilder(dialect SqlDialect) *SqlBuilder
func (*SqlBuilder) BuildSQLBatchInsert ¶
BuildSQLBatchInsert generates a batch INSERT SQL statement for multiple records
Important behavior notes: - All records must have the same struct type - The first record determines which columns to include based on omitnil/omitempty rules - All subsequent records must have the same columns (same omit behavior) - If any record has different columns, an error is returned - Fields with custom mappers are skipped (not supported) - Auto-generated fields are excluded from the INSERT
func (*SqlBuilder) BuildSQLInsert ¶
BuildSQLInsert generates an INSERT SQL statement and parameter list
func (*SqlBuilder) Dialect ¶
func (s *SqlBuilder) Dialect() SqlDialect
func (*SqlBuilder) InsertReturning ¶
func (s *SqlBuilder) InsertReturning(tableName string, data any, returningFields []string) (string, []any, error)
InsertReturning
func (*SqlBuilder) Update ¶
func (s *SqlBuilder) Update(tableName string, record any) *UpdateBuilder
Update creates a new UpdateBuilder instance
type SqlDialect ¶
type SqlDialect struct {
PlaceHolderFragment string
IncludePlaceholderNum bool
QuoteTable string
QuoteField string
QuoteSchema string
QuoteDatabase string
QuoteSeparator string
}
func DefaultSqlDialect ¶
func DefaultSqlDialect() SqlDialect
func PostgreSQLDialect ¶
func PostgreSQLDialect() SqlDialect
func (SqlDialect) Field ¶
func (d SqlDialect) Field(name string) string
func (SqlDialect) Placeholder ¶
func (d SqlDialect) Placeholder(count int) string
func (SqlDialect) TableSchema ¶
func (d SqlDialect) TableSchema(schema, name string) string
type SqlError ¶
Simple error wrapper that adds context
func (*SqlError) WithContext ¶
Add context to error
type UpdateBuilder ¶
type UpdateBuilder struct {
// contains filtered or unexported fields
}
UpdateBuilder provides a fluent interface for building UPDATE statements with complex WHERE clauses
func (*UpdateBuilder) AddReturning ¶
func (b *UpdateBuilder) AddReturning(fields ...string) *UpdateBuilder
AddReturning adds additional fields to the RETURNING clause
func (*UpdateBuilder) Build ¶
func (b *UpdateBuilder) Build() (string, []any, error)
Build generates the final SQL statement and arguments
func (*UpdateBuilder) ByID ¶
func (b *UpdateBuilder) ByID(id any) *UpdateBuilder
ByID sets WHERE id = value (common pattern)
func (*UpdateBuilder) ExcludeFields ¶
func (b *UpdateBuilder) ExcludeFields(fields ...string) *UpdateBuilder
ExcludeFields excludes specific fields from the update
func (*UpdateBuilder) FieldsValues ¶
func (b *UpdateBuilder) FieldsValues(fieldValues map[string]any) *UpdateBuilder
FieldsValues use only the fields/values for update
func (*UpdateBuilder) HasReturnFields ¶
func (b *UpdateBuilder) HasReturnFields() bool
HasReturnFields returns true if clause has return fields
func (*UpdateBuilder) IncludeFields ¶
func (b *UpdateBuilder) IncludeFields(fields ...string) *UpdateBuilder
IncludeFields includes only specific fields in the update
func (*UpdateBuilder) IncludeZeroValues ¶
func (b *UpdateBuilder) IncludeZeroValues(include bool) *UpdateBuilder
IncludeZeroValues includes fields with zero values
func (*UpdateBuilder) Returning ¶
func (b *UpdateBuilder) Returning(fields ...string) *UpdateBuilder
Returning sets the fields to return after the update
func (*UpdateBuilder) ReturningAll ¶
func (b *UpdateBuilder) ReturningAll() *UpdateBuilder
ReturningAll returns all fields after the update (using *)
func (*UpdateBuilder) Set ¶
func (b *UpdateBuilder) Set(where WhereClause, options *UpdateOptions) *UpdateBuilder
Set allows setting WHERE and OPTIONS in one call for simple cases
func (*UpdateBuilder) UpdateAutoFields ¶
func (b *UpdateBuilder) UpdateAutoFields(update bool) *UpdateBuilder
UpdateAutoFields includes auto fields in the update
func (*UpdateBuilder) Where ¶
func (b *UpdateBuilder) Where(clause WhereClause) *UpdateBuilder
Where sets the WHERE clause for the update
func (*UpdateBuilder) WhereAnd ¶
func (b *UpdateBuilder) WhereAnd(conditions ...WhereClause) *UpdateBuilder
WhereAnd adds an AND condition
func (*UpdateBuilder) WhereAndBuild ¶
func (b *UpdateBuilder) WhereAndBuild(conditions ...WhereClause) (string, []any, error)
Where sets a complex WHERE clause and immediately builds
func (*UpdateBuilder) WhereBetween ¶
func (b *UpdateBuilder) WhereBetween(field string, start, end any) *UpdateBuilder
WhereBetween adds a BETWEEN condition
func (*UpdateBuilder) WhereEq ¶
func (b *UpdateBuilder) WhereEq(field string, value any) *UpdateBuilder
WhereEq adds a simple equality condition
func (*UpdateBuilder) WhereIn ¶
func (b *UpdateBuilder) WhereIn(field string, values ...any) *UpdateBuilder
WhereIn adds an IN condition
func (*UpdateBuilder) WhereLiteral ¶
func (b *UpdateBuilder) WhereLiteral(sql string, values ...any) *UpdateBuilder
WhereLiteral adds a literal SQL condition with placeholders
func (*UpdateBuilder) WhereNotNull ¶
func (b *UpdateBuilder) WhereNotNull(field string) *UpdateBuilder
WhereNotNull adds an IS NOT NULL condition
func (*UpdateBuilder) WhereNull ¶
func (b *UpdateBuilder) WhereNull(field string) *UpdateBuilder
WhereNull adds an IS NULL condition
func (*UpdateBuilder) WhereOr ¶
func (b *UpdateBuilder) WhereOr(conditions ...WhereClause) *UpdateBuilder
WhereOr adds an OR condition
func (*UpdateBuilder) WhereRaw ¶
func (b *UpdateBuilder) WhereRaw(sql string) *UpdateBuilder
WhereRaw adds raw SQL without any processing
func (*UpdateBuilder) WithOptions ¶
func (b *UpdateBuilder) WithOptions(options *UpdateOptions) *UpdateBuilder
WithOptions sets the update options
type UpdateOptions ¶
type UpdateOptions struct {
// OnlyChanged when true, only includes fields that have changed from their zero values
OnlyChanged bool
// IncludeZeroValues when true, includes fields with zero values in the update
IncludeZeroValues bool
// ExcludeFields is a list of field names to exclude from the update
ExcludeFields []string
// IncludeFields is a list of field names to explicitly include (if specified, only these fields are included)
IncludeFields []string
// UpdateAutoFields when true, includes fields marked as auto:true in updates
UpdateAutoFields bool
// ReturningFields is a list of field names to return after the update
ReturningFields []string
}
UpdateOptions configures how UPDATE statements are generated
func DefaultUpdateOptions ¶
func DefaultUpdateOptions() *UpdateOptions
DefaultUpdateOptions returns sensible default options for UPDATE statements
func (*UpdateOptions) ShouldSkipField ¶
func (o *UpdateOptions) ShouldSkipField(structFieldName, dbFieldName string) bool
ShouldSkipField determines if a field should be skipped based on options Accepts both the struct field name and database column name for matching
type WhereClause ¶
type WhereClause interface {
// Build generates the SQL string and collects values
// Returns: SQL string, values array, next placeholder number
Build(dialect interface {
Field(string) string
Placeholder(int) string
}, startPlaceholder int) (sql string, values []any, nextPlaceholder int)
}
WhereClause represents a complex WHERE clause with AND/OR support
func And ¶
func And(conditions ...WhereClause) WhereClause
Helper functions for building WHERE clauses
func Between ¶
func Between(field string, start, end any) WhereClause
func Compare ¶
func Compare(leftField, operator, rightField string) WhereClause
func Cond ¶
func Cond(field, operator string, value any) WhereClause
func Gt ¶
func Gt(field string, value any) WhereClause
func Gte ¶
func Gte(field string, value any) WhereClause
func In ¶
func In(field string, values ...any) WhereClause
func IsNotNull ¶
func IsNotNull(field string) WhereClause
func IsNull ¶
func IsNull(field string) WhereClause
func Like ¶
func Like(field string, pattern string) WhereClause
func Literal ¶
func Literal(sql string, values ...any) WhereClause
func Lt ¶
func Lt(field string, value any) WhereClause
func Lte ¶
func Lte(field string, value any) WhereClause
func NotEq ¶
func NotEq(field string, value any) WhereClause
func NotLike ¶
func NotLike(field string, pattern string) WhereClause
func Or ¶
func Or(conditions ...WhereClause) WhereClause
func Raw ¶
func Raw(sql string) WhereClause