Documentation
¶
Index ¶
- Constants
- func SnakeToUpperCamel(raw string) string
- type AliasObjValMap
- type AliasedTables
- func (self *AliasedTables) AddObjects(objects ...base.Base) error
- func (self AliasedTables) AliasForTable(tableName string) (string, bool)
- func (self AliasedTables) Aliases() []string
- func (self AliasedTables) ObjectAlias(object base.Base) (string, error)
- func (self AliasedTables) ObjectIsAliased(object base.Base) bool
- func (self AliasedTables) TableForAlias(alias string) string
- func (self AliasedTables) TypeForAlias(alias string) *reflect.Type
- func (self AliasedTables) TypeForTable(tableName string) *reflect.Type
- func (self AliasedTables) TypeTable(typ reflect.Type) string
- type AscendingQueryable
- type BaseSlicePointer
- type ColumnAlias
- type ColumnAliasField
- type ColumnQueryable
- type Combiner
- type ConditionEvaluator
- type ConstantQueryable
- type ConstantValue
- type DefaultCondition
- type DescendingQueryable
- type FunctionType
- type LimitOption
- type LiteralQueryable
- type MultiCondition
- type NotCondition
- type OffsetOption
- type OptionType
- type OrderByOption
- type QueryOption
- type QueryResult
- type QueryResults
- func (self *QueryResults) Close() error
- func (self *QueryResults) Err() error
- func (self *QueryResults) GetResult() *QueryResult
- func (self *QueryResults) Next() bool
- func (self *QueryResults) WriteAllTo(objectSlices ...BaseSlicePointer) error
- func (self *QueryResults) WriteN(count int, objectSlices ...BaseSlicePointer) (retErr error)
- type Queryable
- func InterfaceToQueryable(in interface{}) Queryable
- func NewDefaultCondition(LHValues, RHValues Queryable, combiner Combiner) Queryable
- func NewMultiAndCondition(values ...Queryable) Queryable
- func NewMultiListCondition(values ...Queryable) Queryable
- func NewMultiOrCondition(values ...Queryable) Queryable
- func ObjectColumn(obj base.Base, column string) (Queryable, error)
- type SelectCount
- type SelectExpression
- type SelectFunction
- type Selectable
- type TableColumnQueryable
- type ValueModifier
Constants ¶
const ( UnsetFunctionType = iota CountFunctionType )
Variables ¶
This section is empty.
Functions ¶
func SnakeToUpperCamel ¶
SnakeToUpperCamel converts a string in snake_case to a string in UpperCamelCase.
Types ¶
type AliasObjValMap ¶
AliasObjValMap maps an alias to a value of an object corresponding to that alias.
type AliasedTables ¶
type AliasedTables struct {
// contains filtered or unexported fields
}
AliasedTables is a representation that makes dealing with table, object, and alias mappings easier.
func NewAliasedTables ¶
func NewAliasedTables(objects ...base.Base) (*AliasedTables, error)
NewAliasedTables creates a new AliasedTables mapping containing the provided objects.
func (*AliasedTables) AddObjects ¶
func (self *AliasedTables) AddObjects(objects ...base.Base) error
AddObjects adds the provided objects to the AliasedTables creating new aliases and creating type and table mappings.
func (AliasedTables) AliasForTable ¶
func (self AliasedTables) AliasForTable(tableName string) (string, bool)
AliasForTable retrieves the alias associated with the provided table name.
func (AliasedTables) Aliases ¶
func (self AliasedTables) Aliases() []string
Aliases returns all the aliases that this AliasedTables knows.
func (AliasedTables) ObjectAlias ¶
func (self AliasedTables) ObjectAlias(object base.Base) (string, error)
ObjectAlias returns the alias asociated with this object's type.
func (AliasedTables) ObjectIsAliased ¶
func (self AliasedTables) ObjectIsAliased(object base.Base) bool
ObjectIsAliased checks if the provided object's type has been aliased in this AliasedTables.
func (AliasedTables) TableForAlias ¶
func (self AliasedTables) TableForAlias(alias string) string
TableForAlias retrieves the table associated with the provided table alias.
func (AliasedTables) TypeForAlias ¶
func (self AliasedTables) TypeForAlias(alias string) *reflect.Type
TypeForAlias retrieves the type associated with the provided table alias.
func (AliasedTables) TypeForTable ¶
func (self AliasedTables) TypeForTable(tableName string) *reflect.Type
TypeForTable retrieves the type associated with the provided table name.
type AscendingQueryable ¶ added in v0.2.1
type AscendingQueryable struct {
Statement Queryable
}
AscendingQueryable takes a statement and assigns an ascending direction to it.
func (AscendingQueryable) QueryValue ¶ added in v0.2.1
func (self AscendingQueryable) QueryValue( at *AliasedTables, ) (string, []interface{})
func (AscendingQueryable) String ¶ added in v0.2.1
func (self AscendingQueryable) String() string
type BaseSlicePointer ¶ added in v0.2.1
type BaseSlicePointer interface{}
BaseSlicePointer is a pointer to a slice of pointers to bases like:
`*[]*MyObject`
It is represented by an interface so that it can take in a slice of any custom object you've implemented in your project.
type ColumnAlias ¶
type ColumnAlias struct { TableAlias, ColumnName string }
ColumnAlias is a table's alias paired with a column in a standardized format.
func ColumnAliasFromString ¶
func ColumnAliasFromString(rawColumn string) (*ColumnAlias, bool)
ColumnAliasForString splits a string in the format of alias_column into a ColumnAlias type.
func (ColumnAlias) String ¶
func (self ColumnAlias) String() string
type ColumnAliasField ¶
type ColumnAliasField struct { ColumnAlias FieldName string }
type ColumnQueryable ¶
type ColumnQueryable struct {
ColumnName string
}
ColumnQueryable is a raw column with no table attached. It may result in ambiguousness when multiple queried tables have the same columns. Use with discretion.
func (ColumnQueryable) QueryValue ¶
func (self ColumnQueryable) QueryValue( *AliasedTables, ) (string, []interface{})
func (ColumnQueryable) String ¶
func (self ColumnQueryable) String() string
type Combiner ¶
type Combiner int
Combiner is some symbol that combines multiple items in SQL.
type ConditionEvaluator ¶
ConditionEvaluator is a function that takes two queryables and runs a transformation function (queryableValuer) on them to return their string representation and any values associated.
func NewDefaultEvaluator ¶
func NewDefaultEvaluator( combiner Combiner, valueModifiers ...ValueModifier, ) ConditionEvaluator
NewDefaultEvaluator returns the standard evaluator.
type ConstantQueryable ¶
type ConstantQueryable struct {
Values []interface{}
}
ConstantQueryable is a value or series of values such as numbers or strings that will be used in a statement.
func (ConstantQueryable) QueryValue ¶
func (self ConstantQueryable) QueryValue( *AliasedTables, ) (string, []interface{})
func (ConstantQueryable) String ¶
func (self ConstantQueryable) String() string
type DefaultCondition ¶
type DefaultCondition struct { LHValues, RHValues Queryable Evaluator ConditionEvaluator }
DefaultCondition represents a standard condition that just combines on lefthand set of values with a righthand set of values.
func (DefaultCondition) QueryValue ¶
func (self DefaultCondition) QueryValue( at *AliasedTables, ) (string, []interface{})
func (DefaultCondition) String ¶
func (self DefaultCondition) String() string
type DescendingQueryable ¶ added in v0.2.1
type DescendingQueryable struct {
Statement Queryable
}
DescendingQueryable takes a statement and assigns an descending direction to it.
func (DescendingQueryable) QueryValue ¶ added in v0.2.1
func (self DescendingQueryable) QueryValue( at *AliasedTables, ) (string, []interface{})
func (DescendingQueryable) String ¶ added in v0.2.1
func (self DescendingQueryable) String() string
type FunctionType ¶ added in v0.2.1
type FunctionType int
FunctionType represents the SQL function type.
type LimitOption ¶
type LimitOption struct {
Limit int
}
LimitOption is sets a limit to the query.
func (LimitOption) OptionType ¶
func (LimitOption) OptionType() OptionType
func (LimitOption) QueryValue ¶
func (self LimitOption) QueryValue(at *AliasedTables) (string, []interface{})
func (LimitOption) String ¶
func (self LimitOption) String() string
type LiteralQueryable ¶ added in v0.2.1
type LiteralQueryable struct {
Value string
}
LiteralQueryable uses exactly the string provided. Use with extreme caution as SQL injection is very possible.
func (LiteralQueryable) QueryValue ¶ added in v0.2.1
func (self LiteralQueryable) QueryValue( *AliasedTables, ) (string, []interface{})
func (LiteralQueryable) String ¶ added in v0.2.1
func (self LiteralQueryable) String() string
type MultiCondition ¶
MultiCondition combines multiple values in a serial fashion using the provided Combiner.
func (MultiCondition) QueryValue ¶
func (self MultiCondition) QueryValue( at *AliasedTables, ) (string, []interface{})
func (MultiCondition) String ¶
func (self MultiCondition) String() string
type NotCondition ¶
type NotCondition struct {
Value Queryable
}
NotCondition creates a sql NOT on the provided statment.
func (NotCondition) QueryValue ¶
func (self NotCondition) QueryValue( at *AliasedTables, ) (string, []interface{})
func (NotCondition) String ¶
func (self NotCondition) String() string
type OffsetOption ¶
type OffsetOption struct {
Offset int
}
OffsetOption sets an offset to the query.
func (OffsetOption) OptionType ¶
func (OffsetOption) OptionType() OptionType
func (OffsetOption) QueryValue ¶
func (self OffsetOption) QueryValue( at *AliasedTables, ) (string, []interface{})
func (OffsetOption) String ¶
func (self OffsetOption) String() string
type OptionType ¶
type OptionType int
OptionType defines query option types.
const ( UnsetOptionType OptionType = iota OrderByOptionType LimitOptionType OffsetOptionType )
type OrderByOption ¶
type OrderByOption struct {
Order Queryable
}
OrderByOption defines an option that orders the query by
func (*OrderByOption) AddStatements ¶ added in v0.2.1
func (self *OrderByOption) AddStatements(statements ...Queryable)
AddStatements appends to an OrderByOption.
func (OrderByOption) OptionType ¶
func (OrderByOption) OptionType() OptionType
func (OrderByOption) QueryValue ¶
func (self OrderByOption) QueryValue( at *AliasedTables, ) (string, []interface{})
func (OrderByOption) String ¶
func (self OrderByOption) String() string
type QueryOption ¶
type QueryOption interface { Queryable OptionType() OptionType }
QueryOption defines a special type of queryable to be used for option on a query such as limit.
type QueryResult ¶
type QueryResult struct {
// contains filtered or unexported fields
}
QueryResult is a set of all the results from a query in objects.
func NewQueryResult ¶
func NewQueryResult( rows *sqlx.Rows, aliasedTables *AliasedTables, columnAliasFields []ColumnAliasField, ) (*QueryResult, error)
NewQueryResult creates a new QueryResult.
func (QueryResult) Close ¶
func (self QueryResult) Close() error
Close closes this QueryResult's rows.
type QueryResults ¶
type QueryResults struct {
// contains filtered or unexported fields
}
QueryResults represents a set of results which generate QueryResult per row and have convinience functions for batch reading.
func NewQueryResults ¶
func NewQueryResults( tx *sqlx.Tx, rows *sqlx.Rows, aliasedTables *AliasedTables, typeBSFieldMap map[reflect.Type]*refl.GroupedFieldsWithBS, ) *QueryResults
NewQueryResults returns a new QueryResults from a finished query with pending rows.
func (*QueryResults) Close ¶ added in v0.2.1
func (self *QueryResults) Close() error
Close closes this QueryResults' rows and commits/rollsback the transaction it wraps. This can be safely called multiple times.
func (*QueryResults) Err ¶
func (self *QueryResults) Err() error
Err returns any errors if they have occured.
func (*QueryResults) GetResult ¶
func (self *QueryResults) GetResult() *QueryResult
GetResult returns the current result if it has been prepped with Next().
func (*QueryResults) Next ¶
func (self *QueryResults) Next() bool
Next retrieves the next result from the result set and indicates if there are more. This mimics the sql.Rows pattern and sets errors which can be accessed via the Err() function.
func (*QueryResults) WriteAllTo ¶
func (self *QueryResults) WriteAllTo(objectSlices ...BaseSlicePointer) error
WriteAllTo writes all results to the provided slices, automatically determining which match which. This operation closes the transaction.
func (*QueryResults) WriteN ¶
func (self *QueryResults) WriteN( count int, objectSlices ...BaseSlicePointer, ) (retErr error)
WriteN writes `count` items to the provided slices automatically determining what data to write to which slices. This operation does not close the transaction.
type Queryable ¶
type Queryable interface { fmt.Stringer QueryValue(*AliasedTables) (string, []interface{}) }
Queryable is an interface that represents something that can be turned into a string and a special context-aware string via QueryValue.
func InterfaceToQueryable ¶
func InterfaceToQueryable(in interface{}) Queryable
InterfaceToQueryable takes a generic interface and creates a ConstantQueryable from it.
func NewDefaultCondition ¶
NewDefaultCondition creates a new default condition combining the values provided via the combiner provided.
func NewMultiAndCondition ¶
NewMultiAndCondition takes the provided values and combines them in the fashion of `a=5 AND c=1`
func NewMultiListCondition ¶
NewMultiListCondition takes the provided values and combines them in the fashion of `a=5, c=1`
func NewMultiOrCondition ¶
NewMultiOrCondition takes the provided values and combines them in the fashion of `a=5 OR c=1`
type SelectCount ¶ added in v0.2.1
type SelectCount struct {
Expression Queryable
}
SelectCount uses the SQL COUNT function with the provided Expression.
func (SelectCount) FunctionType ¶ added in v0.2.1
func (SelectCount) FunctionType() FunctionType
func (SelectCount) QueryValue ¶ added in v0.2.1
func (self SelectCount) QueryValue( at *AliasedTables, ) (string, []interface{})
func (SelectCount) String ¶ added in v0.2.1
func (self SelectCount) String() string
type SelectExpression ¶
type SelectExpression struct {
// contains filtered or unexported fields
}
SelectExpression represents a column/table pairing for use in a select statement.
func NewSelectExpression ¶
func NewSelectExpression(exp string) SelectExpression
NewSelectExpression takes an expression in the format `a.b` and turns it into a SelectExpression.
func (SelectExpression) Column ¶
func (self SelectExpression) Column() string
func (SelectExpression) Table ¶
func (self SelectExpression) Table() (string, bool)
type SelectFunction ¶ added in v0.2.1
type SelectFunction interface { Queryable FunctionType() FunctionType }
SelectFunction is a special type of Queryable that invokes a SQL function.
type Selectable ¶
type Selectable func() (SelectExpression, error)
Selectable is a thing which provides a SelectExpression (and maybe an error)
func BaseSelectable ¶
func BaseSelectable(obj base.Base) Selectable
BaseSelectable takes a base an provides a Selectable from it.
func LiteralSelectable ¶
func LiteralSelectable(exp string) Selectable
LiteralSelectable takes the exact string and creates a select expression from it.
type TableColumnQueryable ¶
type TableColumnQueryable struct { TableName, ColumnName string }
TableColumnQueryable is a table/column pairing that will be used in a query. It will automatically be aliased as appropriate by the caller.
func (TableColumnQueryable) QueryValue ¶
func (self TableColumnQueryable) QueryValue( at *AliasedTables, ) (string, []interface{})
func (TableColumnQueryable) String ¶
func (self TableColumnQueryable) String() string