runtime

package
v0.0.0-...-6123c3f Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2017 License: MIT Imports: 11 Imported by: 0

README

package runtime

This package contains runtime structs and functions used by the autogenerated code

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextOrBackground

func ContextOrBackground(ctx context.Context) context.Context

func ErrConvert

func ErrConvert(field string, index int, value interface{}, to string) error

func ParseBool

func ParseBool(s []byte) bool

func ParseFloat

func ParseFloat(s []byte) float64

func ParseInt

func ParseInt(s []byte) int64

func ParseTime

func ParseTime(b []byte, precision int) time.Time

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 ParseUInt

func ParseUInt(s []byte) uint64

func QMarks

func QMarks(n int) string

QMarks is a helper function for concatenating question mark for an SQL statement

func Values

func Values(r sql.Rows) []driver.Value

Values is a hack to the sql.Rows struct since the rows struct does not expose it's lastcols values, or a way to give a custom scanner to the Scan method. See issue https://github.com/golang/go/issues/22544

Types

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 string
	// IfNotExists determines to create the table only if it does not exists
	IfNotExists bool
	// AutoMigrate perform auto-migration of table scheme
	AutoMigrate 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 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 Group

type Group struct {
	Column string
}

Group is a struct that is used for GROUP BY operations

type Groups

type Groups []Group

Groups is a list of Group

func (*Groups) Add

func (g *Groups) Add(name string)

Add adds a column to a group

type InsertParams

type InsertParams struct {
	Table string
	// Assignments are values to store in the new row
	Assignments Assignments
	// 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 Field 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

type Order struct {
	Column string
	Dir    orm.OrderDir
}

Order is a struct that is used for ORDER BY operations. It holds the column name and the order direction.

type Orders

type Orders []Order

Orders is a list of Order

func (*Orders) Add

func (g *Orders) Add(name string, dir orm.OrderDir)

Add adds an order of a column and direction

type Page

type Page struct {
	Limit  int64
	Offset int64
}

Page is a struct that is used for LIMIT/OFFSET operations

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 StatementArger

type StatementArger interface {
	Statement(string) string
	Args() []interface{}
}

StatementArger is interface for queries. The statement and the args are given to the SQL query.

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 {
	StatementArger
	// 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 NewWhere

func NewWhere(op orm.Op, variable string, value interface{}) Where

NewWhere returns a new WHERE statement

func NewWhereBetween

func NewWhereBetween(variable string, low, high interface{}) Where

NewWhereBetween returns a new 'WHERE variable BETWEEN low AND high' statement

func NewWhereIn

func NewWhereIn(variable string, values ...interface{}) Where

NewWhereIn returns a new 'WHERE variable IN (...)' statement

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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