Documentation ¶
Index ¶
- Constants
- func ContextOrBackground(ctx context.Context) context.Context
- func ErrConvert(field string, index int, value interface{}, to string) error
- func ParseBool(s []byte) bool
- func ParseFloat(s []byte) float64
- func ParseInt(s []byte) int64
- func ParseTime(b []byte, precision int) time.Time
- func ParseUInt(s []byte) uint64
- func RelationTables(gr *graph.Graph) map[string]Table
- func Values(r sql.Rows) []driver.Value
- type API
- type Assignment
- type Assignments
- type Column
- type CreateParams
- type DeleteParams
- type Dialect
- type DropParams
- type ForeignKey
- type Group
- type Groups
- type InsertParams
- type JoinParams
- type Order
- type Orders
- type Page
- type Pairing
- type SelectParams
- type Table
- type TableNamer
- type UpdateParams
- type Where
Constants ¶
const ( Mysql = "mysql" Postgres = "postgres" Sqlite3 = "sqlite3" )
Constants that are names of the different supported dialects
Variables ¶
This section is empty.
Functions ¶
func ContextOrBackground ¶
ContextOrBackground returns background context if the given context is nil, otherwise it returns the context itself.
func ErrConvert ¶
ErrConvert returns a conversion error when processing sql values
func ParseTime ¶
ParseTime parses time from mysql database zero time is a special case, since it's month is 00, which causes month out of range error.
func RelationTables ¶
RelationTables returns all the relation tables that belong to a type.
Relation tables are tables that hold relations between one table and another table, that could not be expressed as a column in one of the tables.
Types ¶
type API ¶
type API interface { // Name returns the name of the dialect Name() string // Create returns the SQL CREATE statement and arguments according to the given parameters Create(orm.Conn, *CreateParams) ([]string, error) // Insert returns the SQL INSERT statement and arguments according to the given parameters Insert(*InsertParams) (string, []interface{}) // Select returns the SQL SELECT statement and arguments according to the given parameters Select(*SelectParams) (string, []interface{}) // Delete returns the SQL DELETE statement and arguments according to the given parameters Delete(*DeleteParams) (string, []interface{}) // Update returns the SQL UPDATE statement and arguments according to the given parameters Update(*UpdateParams) (string, []interface{}) // Drop returns the SQL DROP statement and arguments according to the given parameters Drop(*DropParams) (string, []interface{}) }
API is an interface to represent an SQL dialect Objects that implement this interface, can convert query params, such as SelectParams or UpdateParams, and convert them to an SQL statement and a list of arguments, which can be used to invoke SQL Exec or Query functions.
type Assignment ¶
type Assignment struct { Column string ColumnValue interface{} OriginalValue interface{} }
Assignment is a struct that is used for INSERT and UPDATE/SET operations It holds column name and the value to assign.
type Assignments ¶
type Assignments []Assignment
Assignments is a list of Assignment
func (*Assignments) Add ¶
func (a *Assignments) Add(name string, columnValue interface{}, originalValue interface{})
Add adds an assignment to the list
func (Assignments) Args ¶
func (a Assignments) Args() []interface{}
Args are the list of values of the Assignment list
type CreateParams ¶
type CreateParams struct { Table string // MarshaledTable is a json string representing a table // The representation is of type Table, and created by the function Marshal // of that type. // It is given from the auto generated code. MarshaledTable string // MarshaledRelationTables is a map between a relation table name and // a json string representing a type Table, generated with the function Table.Marshal. // It is given from the auto generated code. MarshaledRelationTables map[string]string // IfNotExists determines to create the table only if it does not exists IfNotExists bool // AutoMigrate perform auto-migration of table scheme AutoMigrate bool // Relations makes the create operation create relation tables and not // the type actual table Relations bool // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
CreateParams holds parameters for an SQL CREATE statement
type DeleteParams ¶
type DeleteParams struct { Table string Where Where // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
DeleteParams holds parameters for an SQL DELETE statement
type Dialect ¶
type Dialect interface { // Name returns the name of the dialect Name() string // GoTypeToColumnType gets a string that represents a go basic type // and returns an SQL type for a createColumn for a field of that type. GoTypeToColumnType(goType string, autoIncrement bool) *sqltypes.Type // Translate gets a MySQL statement and returns a corresponding statement // in a specific dialect Translate(string) string // ConvertValueCode returns code for converting a value for a field with // a given SQL type. ConvertValueCode(*load.Field) string // Quote returns the quoted form of an SQL variable Quote(string) string // ReplaceVars replaces question marks from sql query to the right variable of the dialect Var(int) string }
Dialect is an interface for a dialect for generating ORM code
type DropParams ¶
type DropParams struct { Table string IfExists bool // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
DropParams holds parameters for an SQL DROP statement
type ForeignKey ¶
ForeignKey describes an SQL foreign key
type Group ¶
type Group struct {
Column string
}
Group is a struct that is used for GROUP BY operations
type InsertParams ¶
type InsertParams struct { Table string // Assignments are values to store in the new row Assignments Assignments // RetColumns are columns to return // used in postgres dialect RetColumns []string // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
InsertParams holds parameters for an SQL INSERT statement
type JoinParams ¶
type JoinParams struct { SelectParams Pairings []Pairing }
JoinParams are parameters to perform a join operation Name SelectParams is used to perform select operations on the join struct's field. Pairings describe the relation between the join's fields
func (*JoinParams) TableName ¶
func (j *JoinParams) TableName(parentTable string) string
TableName creates a table name for a join operation this is useful in case several fields referencing the same table
type Order ¶
Order is a struct that is used for ORDER BY operations. It holds the column name and the order direction.
type Pairing ¶
type Pairing struct { // Column is the column in the current table for the JOIN statement Column string // JoinedColumn is the column in the referenced table for the JOIN statement JoinedColumn string }
Pairing describe a join relation
type SelectParams ¶
type SelectParams struct { Table string // Columns are the selected columns for the query Columns map[string]bool // Joins are recursive join arguments for the query Joins []JoinParams // Count indicates weather a COUNT(*) column should be added to the query Count bool // Where is the WHERE part of the query Where Where // Groups are is the GROUP BY conditions for the query Groups Groups // Orders are the ORDER BY conditions for the query Orders Orders // Page is for query pagination Page Page // OrderedColumns store all the columns of a table // they are defined in a specific order so the parsing of returned values from // the SQL query will be easy. OrderedColumns []string // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
SelectParams holds parameters for an SQL SELECT statement
func (*SelectParams) SelectAll ¶
func (p *SelectParams) SelectAll() bool
SelectAll indicates if the SelectParams should select all columns in the query string
func (*SelectParams) SelectedColumns ¶
func (p *SelectParams) SelectedColumns() []string
SelectedColumns returns a list of selected columns for a query
type Table ¶
type Table struct { Columns []Column PrimaryKeys []string ForeignKeys []ForeignKey }
Table represents an SQL table for marshaling to go code
type TableNamer ¶
type TableNamer interface {
TableName() string
}
TableNamer is an interface for a model to change it's table name a struct that implements this interface will set it's SQL table name by the return value from TableName function.
type UpdateParams ¶
type UpdateParams struct { Table string Assignments Assignments Where Where // Ctx is a context parameter for the query // even though it is not recommended to store context in a struct, here the struct // actually represents an arguments list, passed to a function. Ctx context.Context }
UpdateParams holds parameters for an SQL UPDATE statement
type Where ¶
type Where interface { Build(table string, b *builder.Builder) // Or applies OR condition with another Where statement Or(Where) Where // And applies AND condition with another Where statement And(Where) Where }
Where is an API for creating WHERE statements
func NewWhereBetween ¶
NewWhereBetween returns a new 'WHERE variable BETWEEN low AND high' statement
func NewWhereIn ¶
NewWhereIn returns a new 'WHERE variable IN (...)' statement