Documentation
¶
Index ¶
Constants ¶
const ( // DialectMySQLName defines the MySQL dialect name DialectMySQLName = "mysql" // DialectPostgreSQLName defines the PostgreSQL dialect name DialectPostgreSQLName = "postgres" )
Variables ¶
var ( // DialectMySQL predefines the MySQL dialect DialectMySQL = &mysqlDialect{} // DialectPostgreSQL predefines the PostgreSQL dialect DialectPostgreSQL = &postgresqlDialect{} )
var ( // DefaultConfig is the default configuration of the planner DefaultConfig = Config{ Separator: "__", Dialect: DialectPostgreSQL, ColumnAliases: make(map[string]string), } )
var Utils = utilsCollection{}
Utils list of predefined functions to make our life easier
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// The separator between field and operation. Default to "__" which requires the condition format as: field__operator
Separator string
// Collections of methods to build correct SQL clause for specific dialect. Only support MySQL and PostgreSQL (default) for the moment
Dialect Dialect
// Whether to report error or silently skip anomalies in the conditions schema. Default to false
Strict bool
// Table name to add before the columns in SQL clause, i.e: table_name.column_name. Default to empty which will keep the column unchanged
Table string
// The map of column aliases to be replaced when build the SQL clause. Use cases:
// Example: {"name": "foo.name", "bname": "bar.name"}
ColumnAliases map[string]string
// contains filtered or unexported fields
}
Config defines the config for planner
type CustomBuildFn ¶
CustomBuildFn represents the function to build SQL string for the operator
type InvalidCond ¶
type InvalidCond struct {
// contains filtered or unexported fields
}
InvalidCond represents the error when invalid condition is given
func (*InvalidCond) Error ¶
func (e *InvalidCond) Error() string
type ModValueFn ¶
type ModValueFn func(value interface{}) interface{}
ModValueFn represents the function to modify only the value before actually build the SQL
type Operator ¶
type Operator struct {
// Reference to an existing operator
AliasOf string
// The actual SQL operator. Default to "=" if empty
Operator string
// The SQL template. Default to "%s %s ?"
// Note: This must contains 2 "%s" placeholders for the column & operator, and 1 "?" for the value
Template string
// The function to build the SQL condition in your own way. Ignored if AliasOf is provided, ignores Operator & Template.
CustomBuild CustomBuildFn
// Instead of customize the whole build func, you probably only want to modify the value a litle bit
ModValue ModValueFn
}
Operator represents an alias for the SQL operator
type Plan ¶
type Plan struct {
Error error
// contains filtered or unexported fields
}
Plan contains information to build WHERE clause
func Where ¶
func Where(cond interface{}, vars ...interface{}) *Plan
Where is shortcut to create new plan with default configurations
func WhereMySQL ¶
func WhereMySQL(cond interface{}, vars ...interface{}) *Plan
WhereMySQL returns a plan with given conditions for MySQL, using default configurations
func WherePostgreSQL ¶
func WherePostgreSQL(cond interface{}, vars ...interface{}) *Plan
WherePostgreSQL returns a plan with given conditions for PostgreSQL, using default configurations
func WithConfig ¶
WithConfig returns an empty plan using the given configs. Zero value will be replaced by default config.