Documentation
¶
Overview ¶
Package query contains code used by the code generated ORM. Developers will not normally need to refer to code here.
Index ¶
- Constants
- func ColumnNodeQueryName(n Node) string
- func NodeHasAggregate(n Node) bool
- func NodeIsArray(n Node) bool
- func NodeIsDescending(n Node) bool
- func NodeQueryKey(n Node) string
- func NodeSetParent(n Node, parent Node)
- func NodesMatch(node1, node2 Node) bool
- func OperationNodeDistinct(n *OperationNode) bool
- func OperationNodeFunction(n *OperationNode) string
- func ParseTime(s string) (t time.Time)
- func ValueNodeGetValue(n *ValueNode) interface{}
- type AliasNode
- type AliasNodeI
- type AliasValue
- type AutoPrimaryKey
- func (a AutoPrimaryKey) Equal(v AutoPrimaryKey) bool
- func (a AutoPrimaryKey) IsTemp() bool
- func (a AutoPrimaryKey) IsZero() bool
- func (a AutoPrimaryKey) MarshalBinary() ([]byte, error)
- func (a AutoPrimaryKey) MarshalJSON() ([]byte, error)
- func (a AutoPrimaryKey) String() string
- func (a *AutoPrimaryKey) UnmarshalBinary(b []byte) error
- func (a AutoPrimaryKey) Val() any
- func (a AutoPrimaryKey) Value() (driver.Value, error)
- type Builder
- func (b *Builder) Calculation(base TableNodeI, alias string, operation OperationNodeI)
- func (b *Builder) Distinct()
- func (b *Builder) GroupBy(nodes ...Node)
- func (b *Builder) HasAggregate() bool
- func (b *Builder) Having(node Node)
- func (b *Builder) Limit(maxRowCount int, offset int)
- func (b *Builder) Nodes() (nodes []Node)
- func (b *Builder) OrderBy(nodes ...Sorter)
- func (b *Builder) Select(nodes ...Node)
- func (b *Builder) Subquery() *SubqueryNode
- func (b *Builder) Where(condition Node)
- type BuilderCommand
- type BuilderI
- type ColumnNode
- func (n *ColumnNode) Ascending() Sorter
- func (n *ColumnNode) DatabaseKey_() string
- func (n *ColumnNode) Descending() Sorter
- func (n *ColumnNode) GobDecode(data []byte) (err error)
- func (n *ColumnNode) GobEncode() (data []byte, err error)
- func (n *ColumnNode) IsDescending() bool
- func (n *ColumnNode) NodeType_() NodeType
- func (n *ColumnNode) TableName_() string
- type ColumnNodeI
- type CursorI
- type LimitParams
- type ManyManyNode
- type ManyManyNodeI
- type Node
- type NodeType
- type OperationNode
- func (n *OperationNode) DatabaseKey_() string
- func (n *OperationNode) Distinct() *OperationNode
- func (n *OperationNode) GobDecode(data []byte) (err error)
- func (n *OperationNode) GobEncode() (data []byte, err error)
- func (n *OperationNode) NodeType_() NodeType
- func (n *OperationNode) TableName_() string
- type OperationNodeI
- type Operator
- type OrmObj
- type PrimaryKeyer
- type ReceiverType
- type ReferenceNode
- type ReferenceNodeI
- type ReverseNode
- type ReverseNodeI
- type Sorter
- type SubqueryCommand
- type SubqueryNode
- func (n *SubqueryNode) Count() *SubqueryNode
- func (n *SubqueryNode) DatabaseKey_() string
- func (n *SubqueryNode) Get() *SubqueryNode
- func (n *SubqueryNode) GobDecode(data []byte) (err error)
- func (n *SubqueryNode) GobEncode() (data []byte, err error)
- func (n *SubqueryNode) Load() *SubqueryNode
- func (n *SubqueryNode) NodeType_() NodeType
- func (n *SubqueryNode) TableName_() string
- type TableNodeI
- type ULID
- type UUID
- type ValueNode
Constants ¶
const ( BuilderCommandLoad = iota BuilderCommandCount BuilderCommandLoadCursor )
const AliasResults = "aliases_"
AliasResults is the index name that will be used for all calculations and other aliased results in the result set.
Variables ¶
This section is empty.
Functions ¶
func ColumnNodeQueryName ¶
ColumnNodeQueryName returns the name used in the database of the column that corresponds to the node.
func NodeHasAggregate ¶
NodeHasAggregate is used by the orm to detect if this node or its subnodes has an aggregate function.
func NodeIsArray ¶
NodeIsArray returns true if the node is an array connection, like a ManyMany relationship or one-to-many Reverse node.
func NodeIsDescending ¶
NodeIsDescending is used by the ORM to get the sort state of the node. Returns false if the node is not a sorter or is sorted ascending.
func NodeQueryKey ¶
NodeQueryKey is used by the ORM as the key used in query result sets to refer to the data corresponding to the node.
func NodeSetParent ¶
NodeSetParent sets the parent of the node.
func NodesMatch ¶
NodesMatch is used internally by the ORM to indicate whether two nodes point to the same database item.
func OperationNodeDistinct ¶
func OperationNodeDistinct(n *OperationNode) bool
OperationNodeDistinct is used internally by the framework to get the distinct value.
func OperationNodeFunction ¶
func OperationNodeFunction(n *OperationNode) string
OperationNodeFunction is used internally by the framework to get the function.
func ParseTime ¶
ParseTime will convert a SQL Date, Time, DateTime, Timestamp or RFC3339 string to a time.Time. Various databases express their times differently, and this tries to interpret what is attempting to be expressed. It can handle unix time strings that are +- from the 1970 epoch, including fractional times up to the microsecond level.
If the SQL date time string does not have timezone information, the resulting value will be in UTC time. If an error occurs, the returned value will be the zero time.
func ValueNodeGetValue ¶
func ValueNodeGetValue(n *ValueNode) interface{}
ValueNodeGetValue is used internally by the framework to get the node's internal value.
Types ¶
type AliasNode ¶
type AliasNode struct {
// contains filtered or unexported fields
}
An AliasNode is a reference to a prior aliased operation later in a query. An alias is a name given to a calculated value.
func (*AliasNode) DatabaseKey_ ¶
func (*AliasNode) TableName_ ¶
type AliasNodeI ¶
func NewAliasNode ¶
func NewAliasNode(alias string) AliasNodeI
type AliasValue ¶
type AliasValue struct {
// contains filtered or unexported fields
}
An AliasValue is returned by the Alias function that is generated for each type. You then convert the alias to a particular type to use it.
func NewAliasValue ¶
func NewAliasValue(a interface{}) AliasValue
NewAliasValue is used by the ORM to wrap an aliased operation or computed value that was returned by a query. You would not normally call this function.
func (AliasValue) Bytes ¶
func (a AliasValue) Bytes() []byte
Bytes returns the value as a byte array.
func (AliasValue) IsNil ¶
func (a AliasValue) IsNil() bool
IsNil returns true if the value returned was a NULL value from the database.
func (AliasValue) IsNull ¶
func (a AliasValue) IsNull() bool
IsNull is the same as IsNil, and returns true if the operation return a NULL value from the database.
func (AliasValue) String ¶
func (a AliasValue) String() string
String returns the value as a string. A NULL value will be an empty string.
func (AliasValue) Time ¶
func (a AliasValue) Time() time.Time
Time returns the value as a time.Time value.
type AutoPrimaryKey ¶
type AutoPrimaryKey struct {
// contains filtered or unexported fields
}
AutoPrimaryKey is a custom database type that expresses that the database will be generating the primary key for a record. This type can be used as a primary key, or as a reference to an AutoPrimaryKey column in another table.
Databases generally either increment a numeric value (most SQL databases), generate a pseudo random byte array (MongoDB), or generate a random string. Some databases do not have this capability (DynamoDB for one), and database drivers for these databases will need to generate a primary key during insert.
This type will store whatever is given it in its native form. Therefore, moving to another database with a different primary key generator will require some conversions and transformations. If you expect to be changing database engine types, consider using a UUID or ULID as a primary key instead. String conversion will follow the same rules as json conversion.
func NewAutoPrimaryKey ¶
func NewAutoPrimaryKey(v any) AutoPrimaryKey
NewAutoPrimaryKey wraps the given value with the AutoPrimaryKey type, specifying that it is a generated value.
func TempAutoPrimaryKey ¶
func TempAutoPrimaryKey() AutoPrimaryKey
TempAutoPrimaryKey returns an auto primary key that is preset to a temporary unique value and is marked to be generated when the record is saved. You can use the temporary value as a key to refer to a collection of rows that have not yet been saved.
func ZeroAutoPrimaryKey ¶
func ZeroAutoPrimaryKey() AutoPrimaryKey
func (AutoPrimaryKey) Equal ¶
func (a AutoPrimaryKey) Equal(v AutoPrimaryKey) bool
Equal returns true if the AutoPrimaryKey is equal to the given AutoPrimaryKey.
func (AutoPrimaryKey) IsTemp ¶
func (a AutoPrimaryKey) IsTemp() bool
IsTemp returns true if the auto primary key is a temporary value, indicating that it is a primary key that is to be generated by the database or driver, but has not yet been generated.
func (AutoPrimaryKey) IsZero ¶
func (a AutoPrimaryKey) IsZero() bool
IsZero returns true if this is a zero value, which indicates its a reference to an AutoPrimaryKey that has not been set.
func (AutoPrimaryKey) MarshalBinary ¶
func (a AutoPrimaryKey) MarshalBinary() ([]byte, error)
func (AutoPrimaryKey) MarshalJSON ¶
func (a AutoPrimaryKey) MarshalJSON() ([]byte, error)
MarshalJSON exports the underlying value as JSON. There is no matching UnmarshalJSON since some database implementations will need to do a special conversion from what gets marshalled.
func (AutoPrimaryKey) String ¶
func (a AutoPrimaryKey) String() string
func (*AutoPrimaryKey) UnmarshalBinary ¶
func (a *AutoPrimaryKey) UnmarshalBinary(b []byte) error
func (AutoPrimaryKey) Val ¶
func (a AutoPrimaryKey) Val() any
func (AutoPrimaryKey) Value ¶
func (a AutoPrimaryKey) Value() (driver.Value, error)
Value returns the value of the content as a primitive value suitable for use in a SQL clause. This satisfies the Valuer interface found in the standard Go SQL driver base, making it possible to use an AutoPrimaryKey as an argument in any SQL statement.
type Builder ¶
type Builder struct {
Command BuilderCommand
Root TableNodeI
//Joins []Node
OrderBys []Sorter
Conditions []Node
IsDistinct bool
Calculations map[string]calc
// Adds a COUNT(*) to the select list
GroupBys []Node
Selects []Node
Limits LimitParams
HavingNode Node
IsSubquery bool
}
Builder is a mix-in to implement the BuilderI interface in various builder classes. It gathers the builder instructions as the query is built, then the final build process processes the query into a join tree that can be used by database drivers to generate the database specific query.
func NewBuilder ¶
func NewBuilder(rootNode TableNodeI) *Builder
func (*Builder) Calculation ¶
func (b *Builder) Calculation(base TableNodeI, alias string, operation OperationNodeI)
Calculation adds the aliased calculation node operation onto base.
func (*Builder) Distinct ¶
func (b *Builder) Distinct()
Distinct sets the distinct bit, causing the query to not return duplicates.
func (*Builder) GroupBy ¶
GroupBy sets the nodes that are grouped. GroupBy only makes sense if only those same columns are selected. Most SQL databases enforce this.
func (*Builder) HasAggregate ¶
HasAggregate returns true if the builder has an aggregate function in it somwhere.
func (*Builder) Having ¶
Having adds a HAVING condition, which is a filter that acts on the results of a query. In particular, it is useful for filtering after aggregate functions have done their work.
func (*Builder) Limit ¶
Limit limits the query to returning maxRowCount rows at most, starting at row offset. In SQL queries, this limits the rows BEFORE assembling many type relationships, which usually is not what is wanted. Therefore, you cannot put limits on queries that have reverse or many-many relationships. Also note that SQL at least will perform the entire query before finding the offset, which could have performance issues. If paging through a large dataset, consider getting a list of just primary keys of the records you want, saving that list, and then lazy-loading the rest of the information with a separate query.
Warning: Setting maxRowCount to zero will turn off the limit. Setting it to less than zero will panic. If you really want to return no information, do not call the query.
func (*Builder) OrderBy ¶
OrderBy adds the order by nodes. If these are table type nodes, the primary key of the table will be used. These nodes can be modified using Ascending and Descending calls.
func (*Builder) Select ¶
Select will add columns to the group of columns that will appear in the result. Multiple calls to Select will add to the selected columns. By default, all the columns of the root table will be queried and loaded. If columns from the root table are selected, that will limit the columns queried and loaded to only those columns. If related tables are specified, then all the columns from those tables are queried, selected and joined to the root. If columns in related tables are specified, then only those columns will be queried and loaded. Depending on the query, additional columns may automatically be added to the query. In particular, primary key columns will be added in most situations. The exception to this would be in distinct queries, group by queries, or subqueries.
func (*Builder) Subquery ¶
func (b *Builder) Subquery() *SubqueryNode
Subquery adds a subquery node, which is like a mini query builder that should result in a single value.
type BuilderCommand ¶
type BuilderCommand int
type BuilderI ¶
type BuilderI interface {
Where(c Node)
Having(c Node)
OrderBy(nodes ...Sorter)
GroupBy(nodes ...Node)
Limit(maxRowCount int, offset int)
Select(nodes ...Node)
Distinct()
Calculation(base TableNodeI, alias string, n OperationNodeI)
}
BuilderI is the interface to the builder structure. Since the builder is directly interacted with by the developer, passing this interface instead of the Builder object makes it more clear what the developer should use to build queries.
func SubqueryBuilder ¶
func SubqueryBuilder(n *SubqueryNode) BuilderI
SubqueryBuilder is used internally by the framework to return the internal query builder of the subquery
type ColumnNode ¶
type ColumnNode struct {
// The query name of the column in the database.
QueryName string
// The identifier of the data in the corresponding object.
// Pass this to Get() to retrieve a value.
Field string
// The receiver type for the column
ReceiverType ReceiverType
// The schema type for the node
SchemaType schema.ColumnType
// The schema subtype for the node
SchemaSubType schema.ColumnSubType
// True if this is the single primary key of its parent table
IsPrimaryKey bool
// contains filtered or unexported fields
}
ColumnNode represents a table or field in a database structure, and is the leaf of a node tree or chain.
You would not normally create a column node directly. Use the code generated node functions to create column nodes.
func NewColumnNode ¶
func NewColumnNode( queryName string, field string, receiverType ReceiverType, schemaType schema.ColumnType, schemaSubType schema.ColumnSubType, isPrimaryKey bool, parent Node, ) *ColumnNode
NewColumnNode is used by the code generated framework to create a new column node that refers to a specific column in a table. You would not normally call this function directly.
func (*ColumnNode) Ascending ¶
func (n *ColumnNode) Ascending() Sorter
Ascending sets the column to sort ascending when used in an OrderBy statement.
func (*ColumnNode) DatabaseKey_ ¶
func (n *ColumnNode) DatabaseKey_() string
func (*ColumnNode) Descending ¶
func (n *ColumnNode) Descending() Sorter
Descending sets the column to sort descending when used in an OrderBy statement.
func (*ColumnNode) GobDecode ¶
func (n *ColumnNode) GobDecode(data []byte) (err error)
func (*ColumnNode) GobEncode ¶
func (n *ColumnNode) GobEncode() (data []byte, err error)
func (*ColumnNode) IsDescending ¶
func (n *ColumnNode) IsDescending() bool
IsDescending returns true if the node is sorted in descending order.
func (*ColumnNode) NodeType_ ¶
func (n *ColumnNode) NodeType_() NodeType
NodeType_ is used by the framework to return the type of node this is.
func (*ColumnNode) TableName_ ¶
func (n *ColumnNode) TableName_() string
type ColumnNodeI ¶
type LimitParams ¶
LimitParams is the information needed to limit the rows being requested.
func (LimitParams) AreSet ¶
func (l LimitParams) AreSet() bool
AreSet returns true if the limit paramter values are not zero.
type ManyManyNode ¶
type ManyManyNode struct {
// The association table
AssnTableQueryName string
// The column in the association table pointing toward the parent node.
ParentForeignKey string
// The primary key column in the parent table that matches the ParentForeignKey.
ParentPrimaryKey string
// Identifier used to refer to the collection of objects. This is a plural name.
Field string
// Column in the association table pointing forwards to the embedding node
RefForeignKey string
// Primary key column in the child table that matches the RefForeignKey
RefPrimaryKey string
// contains filtered or unexported fields
}
A ManyManyNode is a mixin for an association node that links one table to another table with a many-to-many relationship.
func (*ManyManyNode) AssnTableName ¶
func (n *ManyManyNode) AssnTableName() string
func (*ManyManyNode) GobDecode ¶
func (n *ManyManyNode) GobDecode(data []byte) (err error)
func (*ManyManyNode) GobEncode ¶
func (n *ManyManyNode) GobEncode() (data []byte, err error)
func (*ManyManyNode) ParentColumnNames ¶
func (n *ManyManyNode) ParentColumnNames() (string, string)
func (*ManyManyNode) RefColumnNames ¶
func (n *ManyManyNode) RefColumnNames() (string, string)
type ManyManyNodeI ¶
type Node ¶
type Node interface {
// NodeType_ returns the type of the node
NodeType_() NodeType
// TableName_ returns the query name of the table the node is associated with.
// Nodes that are not table specific will return an empty string.
TableName_() string
// DatabaseKey_ is the key of the database the node is associated with.
DatabaseKey_() string
}
Node is a representation of an object or a relationship between objects in a database.
The ORM will create Node types during code generation. The develpoper chains these Nodes to indicate a specific table or column in a query. A developer typically would not create a Node directly.
For example, a developer might use node.Project().TeamMembers().FirstName() to get the node pointing to the first name of a team member in a project.
func ContainedNodes ¶
ContainedNodes is used internally by the ORM to return the contained nodes.
func NewValueNode ¶
func NewValueNode(i interface{}) Node
NewValueNode returns a new ValueNode that wraps the given value.
func NodeParent ¶
NodeParent returns the parent of the node, or nil if the node has no parent.
func NodePrimaryKeys ¶
NodePrimaryKeys returns the primary key nodes of a table type node.
func OperationNodeOperands ¶
func OperationNodeOperands(n *OperationNode) []Node
OperationNodeOperands is used internally by the framework to get the operands.
type NodeType ¶
type NodeType int
NodeType indicates the type of node, which saves us from having to use reflection to determine this
type OperationNode ¶
type OperationNode struct {
// contains filtered or unexported fields
}
An OperationNode is a general purpose structure that specifies an operation on a node or group of nodes. The operation could be arithmetic, boolean, or a function.
func NewAggregateFunctionNode ¶
func NewAggregateFunctionNode(functionName string, operands ...interface{}) *OperationNode
NewAggregateFunctionNode returns an operation node that executes an aggregate function.
func NewCountNode ¶
func NewCountNode(operands ...Node) *OperationNode
NewCountNode creates a Count function node. If no operands are given, it will use * as the parameter to the function which means it will count nulls. To NOT count nulls, a node needs to be specified. Only up to one node can be specified.
func NewFunctionNode ¶
func NewFunctionNode(functionName string, operands ...interface{}) *OperationNode
NewFunctionNode returns an operation node that executes a database function.
func NewOperationNode ¶
func NewOperationNode(op Operator, operands ...interface{}) *OperationNode
NewOperationNode returns a new operation node.
func (*OperationNode) DatabaseKey_ ¶
func (n *OperationNode) DatabaseKey_() string
func (*OperationNode) Distinct ¶
func (n *OperationNode) Distinct() *OperationNode
Distinct sets the operation to return distinct results
func (*OperationNode) GobDecode ¶
func (n *OperationNode) GobDecode(data []byte) (err error)
func (*OperationNode) GobEncode ¶
func (n *OperationNode) GobEncode() (data []byte, err error)
func (*OperationNode) NodeType_ ¶
func (n *OperationNode) NodeType_() NodeType
func (*OperationNode) TableName_ ¶
func (n *OperationNode) TableName_() string
type OperationNodeI ¶
type OperationNodeI interface {
Node
// contains filtered or unexported methods
}
type Operator ¶
type Operator string
Operator is used internally by the framework to specify an operation to be performed by the database. Not all databases can perform all the operations. It will be up to the database driver to sort this out.
const ( OpEqual Operator = "=" OpNotEqual Operator = "<>" OpAnd Operator = "AND" OpOr Operator = "OR" OpXor Operator = "XOR" OpGreater Operator = ">" OpGreaterEqual Operator = ">=" OpLess Operator = "<" OpLessEqual Operator = "<=" // Unary logical OpNot Operator = "NOT" OpAll Operator = "1=1" OpNone Operator = "1=0" // Math operators OpAdd Operator = "+" OpSubtract Operator = "-" OpMultiply Operator = "*" OpDivide Operator = "/" OpModulo Operator = "%" // Unary math OpNegate Operator = " -" // Bit operators OpBitAnd Operator = "&" OpBitOr Operator = "|" OpBitXor Operator = "^" OpShiftLeft Operator = "<<" OpShiftRight Operator = ">>" // Unary bit OpBitInvert Operator = "~" // Function operator // The function name is followed by the operators in parenthesis OpFunc Operator = "func" // SQL functions that act like operators in that the operator is put in between the operands OpLike Operator = "LIKE" // This is very SQL specific and may not be supported in NoSql OpIn Operator = "IN" OpNotIn Operator = "NOT IN" // Special NULL tests OpNull Operator = "NULL" OpNotNull Operator = "NOT NULL" // Our own custom operators for universal support OpStartsWith Operator = "StartsWith" OpEndsWith Operator = "EndsWith" OpContains Operator = "Contains" OpDateAddSeconds Operator = "AddSeconds" // Adds the given number of seconds to a datetime )
func OperationNodeOperator ¶
func OperationNodeOperator(n *OperationNode) Operator
OperationNodeOperator is used internally by the framework to get the operator.
type OrmObj ¶
type OrmObj interface {
String() string
Key() string
Label() string
Initialize()
Get(string) any
MarshalBinary() ([]byte, error)
UnmarshalBinary(data []byte) (err error)
MarshalJSON() (data []byte, err error)
MarshalStringMap() map[string]any
UnmarshalJSON(data []byte) (err error)
UnmarshalStringMap(m map[string]any) (err error)
}
OrmObj is the interface describing the functions common to every record type that is returned by queries.
type PrimaryKeyer ¶
type PrimaryKeyer interface {
PrimaryKeys() []*ColumnNode
}
type ReceiverType ¶
type ReceiverType int
ReceiverType represents the Go type that a query will be received as.
const ( ColTypeUnknown ReceiverType = iota ColTypeBytes ColTypeString ColTypeInteger ColTypeUnsigned ColTypeInteger64 ColTypeUnsigned64 ColTypeTime ColTypeFloat32 ColTypeFloat64 ColTypeBool ColTypeAutoPrimaryKey ColTypeUUID ColTypeULID )
func ReceiverTypeFromSchema ¶
func ReceiverTypeFromSchema(columnType schema.ColumnType, maxLength uint64) ReceiverType
ReceiverTypeFromSchema converts a schema column type to a Go language type. If maxLength is zero, the default will be chosen. If the column is a ReferenceType, columnType should instead be the type of the primary key in the referenced table.
func (ReceiverType) DefaultValue ¶
func (g ReceiverType) DefaultValue() any
DefaultValue returns a zero Go value for the type
func (ReceiverType) DefaultValueString ¶
func (g ReceiverType) DefaultValueString() string
DefaultValueString returns a string that represents the GO default value for the corresponding type
func (ReceiverType) GoType ¶
func (g ReceiverType) GoType() string
GoType returns the actual GO type as go code
func (ReceiverType) String ¶
func (g ReceiverType) String() string
String returns the constant type name as a string
type ReferenceNode ¶
type ReferenceNode struct {
// The query name of the column that is the foreign key
ForeignKey string
// The name of the matching primary key column in the referenced table
PrimaryKey string
// The field that can be used in Get() calls to get the corresponding value from the table.
Field string
// contains filtered or unexported fields
}
A ReferenceNode is a mixin for a forward-pointing foreign key relationship.
func (*ReferenceNode) ColumnNames ¶
func (n *ReferenceNode) ColumnNames() (string, string)
ColumnNames returns the foreign key column name in this table, and the name of the primary key column that it mirrors in the referenced table.
func (*ReferenceNode) GobDecode ¶
func (n *ReferenceNode) GobDecode(data []byte) (err error)
func (*ReferenceNode) GobEncode ¶
func (n *ReferenceNode) GobEncode() (data []byte, err error)
GobEncode encodes the reference in a binary form.
type ReferenceNodeI ¶
type ReferenceNodeI interface {
ColumnNames() (string, string)
TableNodeI
// contains filtered or unexported methods
}
type ReverseNode ¶
type ReverseNode struct {
// The query name of the column that is the foreign key pointing to the parent's primary key.
ForeignKey string
// The name of the matching primary key column in the parent.
PrimaryKey string
// The identifier that will be used to identify this object in source code.
// Equals the key for the Get() function on an object. Should be plural.
Field string
// IsUnique is true if there is a unique relationship between this node and its parent,
// which would create a one-to-one relationship rather than a one-to-many relationship.
IsUnique bool
// contains filtered or unexported fields
}
ReverseNode is a mixin for a reverse reference representing a one-to-many relationship or one-to-one relationship, depending on whether the foreign key is unique. The other side of the relationship will have a matching forward ReferenceNode.
func (*ReverseNode) ColumnNames ¶
func (n *ReverseNode) ColumnNames() (string, string)
func (*ReverseNode) GobDecode ¶
func (n *ReverseNode) GobDecode(data []byte) (err error)
func (*ReverseNode) GobEncode ¶
func (n *ReverseNode) GobEncode() (data []byte, err error)
func (*ReverseNode) IsArray ¶
func (n *ReverseNode) IsArray() bool
IsArray returns true if this node creates a one-to-many relationship with its parent. Otherwise, it is a one-to-one relationship.
type ReverseNodeI ¶
type ReverseNodeI interface {
ColumnNames() (string, string)
IsArray() bool
TableNodeI
// contains filtered or unexported methods
}
ReverseNodeI is the interface to objects that have embedded ReverseNode objects.
type Sorter ¶
type Sorter interface {
Node
// Ascending specifies that the node should be sorted in ascending order.
Ascending() Sorter
// Descending specifies that the node should be sorted in descending order.
Descending() Sorter
// IsDescending returns true if the node is sorted in descending order.
IsDescending() bool
}
Sorter is the interface a node must satisfy to be able to be used in an OrderBy statement.
type SubqueryCommand ¶
type SubqueryCommand int
const ( SubqueryCommandDefault SubqueryCommand = iota SubqueryCommandLoad SubqueryCommandGet SubqueryCommandCount )
func SubqueryCmd ¶
func SubqueryCmd(n *SubqueryNode) SubqueryCommand
type SubqueryNode ¶
type SubqueryNode struct {
// contains filtered or unexported fields
}
A SubqueryNode represents a "select" subquery. Subqueries are not always portable to other databases, and are not easily checked for syntax errors, since a subquery can return a scalar, vector, or even an entire table. You generally do not create a subquery node directly, but rather you use the codegenerated models to start a query on a table, and then end the query with "Subquery()" which will turn the query into a usable subquery node that you can embed in other queries.
func NewSubqueryNode ¶
func NewSubqueryNode(b BuilderI) *SubqueryNode
NewSubqueryNode creates a new subquery
func (*SubqueryNode) Count ¶
func (n *SubqueryNode) Count() *SubqueryNode
func (*SubqueryNode) DatabaseKey_ ¶
func (n *SubqueryNode) DatabaseKey_() string
func (*SubqueryNode) Get ¶
func (n *SubqueryNode) Get() *SubqueryNode
func (*SubqueryNode) GobDecode ¶
func (n *SubqueryNode) GobDecode(data []byte) (err error)
func (*SubqueryNode) GobEncode ¶
func (n *SubqueryNode) GobEncode() (data []byte, err error)
func (*SubqueryNode) Load ¶
func (n *SubqueryNode) Load() *SubqueryNode
func (*SubqueryNode) NodeType_ ¶
func (n *SubqueryNode) NodeType_() NodeType
func (*SubqueryNode) TableName_ ¶
func (n *SubqueryNode) TableName_() string
type TableNodeI ¶
type TableNodeI interface {
Node
PrimaryKeyer
ColumnNodes_() []Node
}
TableNodeI is the interface that all table-like nodes must satisfy
type ULID ¶
type ULID [16]byte
func NewULID ¶
func NewULID() ULID
NewULID generates a ULID using standard ULID rules of 48-bit timestamp plus 80-bits of randomness
func RULID ¶
func RULID() ULID
RULID returns a randomized ULID that has no timestamp information, suitable for use as an exposed ULID.
func ULIDFromBytes ¶
ULIDFromBytes returns a ULID copied from the upper 16 bytes of the given byte slice. Will panic if the byte slice is too small.
func ULIDFromString ¶
func (ULID) MarshalBinary ¶
func (ULID) MarshalText ¶
func (*ULID) UnmarshalBinary ¶
func (*ULID) UnmarshalText ¶
type UUID ¶
type UUID [16]byte
func NewV7UUID ¶
func NewV7UUID() UUID
NewV7UUID generates a UUID using v7 rules of 48-bit timestamp plus 74-bits of randomness, plus version info
func UUIDFromBytes ¶
UUIDFromBytes returns a UUID copied from the upper 16 bytes of the given byte slice. Will panic if the byte slice is too small.
func UUIDFromString ¶
func (UUID) MarshalBinary ¶
func (UUID) MarshalText ¶
func (*UUID) UnmarshalBinary ¶
func (*UUID) UnmarshalText ¶
type ValueNode ¶
type ValueNode struct {
// contains filtered or unexported fields
}
ValueNode represents a value for a built-in type that is to be used in a query.