-
Notifications
You must be signed in to change notification settings - Fork 0
QueryGeneratorBase
class QueryGeneratorBase 📜
The base query generator class.
A "query generator" is an interface that will take
parameters (usually a QueryEngine or a
Model) and generate database query statements
from the input. For SQL type databases this would mean
generating SELECT, INSERT, UPDATE, and DELETE
statements, as well as generators for creating and altering
tables, among other things.
The methods of this class are generally many, with the design pattern for most generators being that nearly all methods are split apart and added to the class, allowing by deliberate design much finer control when using overloaded methods, to modify or replace any parts of the generator.
Any connection can be provided a custom query generator
interface via the queryGenerator option that can be
used when instantiating a connection. Most connections
will supply their own by default.
A connection should always be bound to a query generator instance. If not when first created, then at least when provided to a connection. The connection is a required part of the generator interface, and will do things, such as for example, escaping values and ids using the connection itself. The connection may be used for other operations as well.
Notes:
- Some database drivers may not have a generator at all. Though database drivers commonly do have a database statement generator, a connection isn't required to have one.
method QueryGeneratorBase::_averageLiteralToString(
literal: AverageLiteral,
options?: object,
): string 📜
Convert an AverageLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: AverageLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_countLiteralToString(
literal: CountLiteral,
options?: object,
): string 📜
Convert an CountLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: CountLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_distinctLiteralToString(
literal: DistinctLiteral,
options?: object,
): string 📜
Convert an DistinctLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: DistinctLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_fieldLiteralToString(
literal: FieldLiteral,
options?: object,
): string 📜
Convert an FieldLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: FieldLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_maxLiteralToString(
literal: MaxLiteral,
options?: object,
): string 📜
Convert an MaxLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: MaxLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_minLiteralToString(
literal: MinLiteral,
options?: object,
): string 📜
Convert an MinLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: MinLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::_sumLiteralToString(
literal: SumLiteral,
options?: object,
): string 📜
Convert an SumLiteral into a string representation for the underlying database.
It is expected that each database driver will implement this method. By default it will simply throw an "unsupported" error.
Refer to the specific documentation for your database driver for more information.
Arguments:
-
literal: SumLiteralThe literal to stringify for the underlying database.
-
options?:objectOptions for the stringify process. These are often database driver specific. However, one common option is the
asoption, which will allow you to give your literal an alias.
Return value: string
The literal, converted into the proper string for the underlying database.
method QueryGeneratorBase::constructor(
connection?: Connection,
): QueryGeneratorBase 📜
Construct a new query generator.
Arguments:
-
connection?: ConnectionThe connection that this interface is for. Sometimes the connection isn't yet available when creating the query generator, so this argument is optional. When provided to a Connection, the connection will call QueryGenerator.setConnection with itself to set the connection for the query generator.
Return value: QueryGeneratorBase
method QueryGeneratorBase::escape(
args,
) 📜
This call proxies to Connection.escape. Refer to the documentation of that method for more information.
Arguments:
args
See also: Connection.escape
method QueryGeneratorBase::escapeID(
args,
) 📜
This call proxies to Connection.escapeID. Refer to the documentation of that method for more information.
Arguments:
args
See also: Connection.escapeID
method QueryGeneratorBase::getConnection(): Connection 📜
Get the Connection bound to this query generator.
Return value: Connection
The connection bound to this query generator. A connection should always be bound before any generating methods of the class are called.
method QueryGeneratorBase::getFieldDefaultValue(
field: Field,
fieldName: string,
options?: object,
): any 📜
Get the "default value" for the given field for the underlying database. This is used primarily for "CREATE TABLE" statements.
By default, the implementation of this method is empty. It is expected that each database driver will implement their own version of this method.
Arguments:
-
field: FieldThe field instance we are getting a "default value" from.
-
fieldName:stringThe name of the field that we are getting the "default value" from. This should always be the same as
field.fieldName. -
options?:objectOptions for the operation. These will likely be connection specific. Please refer to the documentation of your specific connection for more details.
Return value: any
Though in most cases this method will return a string for most database drivers in most situations, it may return other types as well, such as literals, or other raw values. Please refer to the documentation of your specific connection for more details.
Take a Field instance, and generate
all index fields for this field.
The index property on a Field is used
to generate indexes for the field. If a true value
is encountered in the index, it means "this field".
If another field name is encountered in the index property,
then that means "combine this field with the specified field"
(to create a combined index). Take the following example:
...
firstName: {
...
index: [
true,
'lastName',
[ 'email', 'lastName' ],
]
}
...This will create three indexes for this "firstName" column in the database:
-
true= Index thefirstNamecolumn by itself (idx_users_firstName) -
lastName= CombinefirstNameandlastNameto create a combined index (idx_users_firstName_lastName) -
[ 'email', 'lastName' ]= CombinefirstNamewithemailandlastNameto create a combined index involving three columns (idx_users_firstName_email_lastName) Using the above example, this method would return the following:
[
[ 'firstName' ],
[ 'firstName', 'lastName' ],
[ 'firstName', 'email', 'lastName' ],
]Which is the list of indexes, and the fields to index for each index.
Arguments:
-
field: FieldThe field used to pull the
indexproperty from.
Return value: Array<Array<string>>
Return an array of arrays, where the top-level array lists the indexes, and each sub-array lists the fields to combine into an index.
method QueryGeneratorBase::setConnection(
connection: Connection,
): QueryGenerator 📜
Set the Connection bound to this query generator.
Arguments:
-
connection: ConnectionThe connection to bind to this query generator.
Return value: QueryGenerator
Return this to allow for chaining.
method QueryGeneratorBase::stackAssign(
obj,
args,
) 📜
This call proxies to Connection.stackAssign. Refer to the documentation of that method for more information.
Arguments:
objargs
See also: Connection.stackAssign
method QueryGeneratorBase::toConnectionString(
queryEngine: QueryEngine,
options?: object,
): string 📜
Take a QueryEngine instance and
convert it into a query. For SQL type databases
this would turn a QueryEngine into a
SELECT statement. For other types of databases,
this should return a "fetch" query--or string representation
of such a query--in the database's native query language.
Arguments:
-
queryEngine: QueryEngineThe query engine instance to stringify.
-
options?:objectConnection and operation specific options. These generally aren't needed, but are provided in case the underlying connection needs them.
Return value: string
A "fetch" query in the databases native query language,
generated from the provided queryEngine.
- Associations
- Certifications
- Connection Binding
- Home
- Models
- Queries
- TypeScript
- Types Reference
-
namespace AsyncStore
- function getContextStore
- function getContextValue
- function runInContext
- function setContextValue
-
namespace Helpers
- function checkDefaultValueFlags
- function defaultValueFlags
- function getDefaultValueFlags
- property FLAG_LITERAL
- property FLAG_ON_INITIALIZE
- property FLAG_ON_INSERT
- property FLAG_ON_STORE
- property FLAG_ON_UPDATE
- property FLAG_REMOTE
-
namespace MiscUtils
- function collect
- function valueToDateTime
-
namespace ModelUtils
- function parseQualifiedName
-
namespace QueryUtils
- function generateQueryFromFilter
- function mergeFields
- function parseFilterFieldAndOperator
-
class AverageLiteral
- method static isAggregate
- method toString
-
class BigIntType
- property Default
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class BlobType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class BooleanType
- method castToType
- method isValidValue
- method static getDisplayName
- method toString
-
class CacheKey
- method constructor
- method valueOf
-
class CharType
- method castToType
- method isValidValue
- method static getDisplayName
- method toString
-
class ConnectionBase
- property _isMythixConnection
- property DefaultQueryGenerator
- property dialect
- property Literals
- method _averageLiteralToString
- method _bigintTypeToString
- method _blobTypeToString
- method _booleanTypeToString
- method _charTypeToString
- method _countLiteralToString
- method _datetimeTypeToString
- method _dateTypeToString
- method _distinctLiteralToString
- method _escape
- method _escapeID
- method _fieldLiteralToString
- method _getFromModelCache
- method _integerTypeToString
- method _maxLiteralToString
- method _minLiteralToString
- method _numericTypeToString
- method _realTypeToString
- method _setToModelCache
- method _stringTypeToString
- method _sumLiteralToString
- method _textTypeToString
- method _uuidV1TypeToString
- method _uuidV3TypeToString
- method _uuidV4TypeToString
- method _uuidV5TypeToString
- method _xidTypeToString
- method addColumn
- method addIndex
- method aggregate
- method alterColumn
- method alterTable
- method average
- method buildConnectionContext
- method bulkModelOperation
- method constructor
- method convertDateToDBTime
- method count
- method createContext
- method createQueryGenerator
- method createTable
- method createTables
- method destroy
- method destroyModels
- method dirtyFieldHelper
- method dropColumn
- method dropIndex
- method dropTable
- method dropTables
- method ensureAllModelsAreInstances
- method escape
- method escapeID
- method exists
- method finalizeQuery
- method findModelField
- method getContextValue
- method getDefaultFieldValue
- method getDefaultOrder
- method getField
- method getLockMode
- method getModel
- method getModels
- method getOptions
- method getQueryEngineClass
- method getQueryGenerator
- method insert
- method isStarted
- method literalToString
- method max
- method min
- method parseQualifiedName
- method pluck
- method prepareAllModelsAndSubModelsForOperation
- method prepareAllModelsForOperation
- method query
- method registerModel
- method registerModels
- method runSaveHooks
- method select
- method setContextValue
- method setPersisted
- method setQueryGenerator
- method splitModelAndSubModels
- method stackAssign
- method start
- method static getLiteralClassByName
- method static isConnection
- method static isConnectionClass
- method static Literal
- method stop
- method sum
- method toQueryEngine
- method transaction
- method truncate
- method typeToString
- method update
- method updateAll
- method upsert
-
class CountLiteral
- method static isAggregate
- method static isFieldRequired
- method toString
-
class DateTimeType
- property Default
- method castToType
- method constructor
- method deserialize
- method isValidValue
- method serialize
- method static getDisplayName
- method toString
-
class DateType
- property Default
- method castToType
- method constructor
- method deserialize
- method isValidValue
- method serialize
- method static getDisplayName
- method toString
-
class DistinctLiteral
- method toString
-
class Field
- property _isMythixField
- property allowNull
- property defaultValue
- property fieldName
- property get
- property index
- property primaryKey
- property set
- property type
- property unique
- property validate
- method clone
- method constructor
- method setModel
- method static isField
- method static isFieldClass
-
class FieldLiteral
- method toString
- class FieldScope
-
class ForeignKeyType
- method castToType
- method constructor
- method getOptions
- method getTargetField
- method getTargetFieldName
- method getTargetModel
- method getTargetModelName
- method initialize
- method isValidValue
- method parseOptionsAndCheckForErrors
- method static getDisplayName
- method static isForeignKey
- method toString
-
class IntegerType
- property Default
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class Literal
- method constructor
-
class LiteralBase
- property _isMythixLiteral
- method constructor
- method definitionToField
- method fullyQualifiedNameToDefinition
- method static isAggregate
- method static isLiteral
- method static isLiteralClass
- method static isLiteralType
- method toString
- method valueOf
-
class LiteralFieldBase
- method constructor
- method getField
- method getFullyQualifiedFieldName
- method static isFieldRequired
- method valueOf
-
class MaxLiteral
- method static isAggregate
- method toString
-
class MinLiteral
- method static isAggregate
- method toString
-
class Model
- property _isMythixModel
- method _castFieldValue
- method _constructField
- method _constructFields
- method _constructor
- method _getConnection
- method _getDirtyFields
- method _getFieldValue
- method _initializeFieldData
- method _initializeModelData
- method _setFieldValue
- method clearDirty
- method constructor
- method destroy
- method getAttributes
- method getConnection
- method getDataValue
- method getDirtyFields
- method getOptions
- method hasValidPrimaryKey
- method isDirty
- method isPersisted
- method onAfterCreate
- method onAfterSave
- method onAfterUpdate
- method onBeforeCreate
- method onBeforeSave
- method onBeforeUpdate
- method onValidate
- method reload
- method save
- method setAttributes
- method setDataValue
- method static _getConnection
- method static all
- method static bindConnection
- method static count
- method static create
- method static cursor
- method static defaultScope
- method static finalizeQuery
- method static first
- method static getConcreteFieldCount
- method static getContextValue
- method static getField
- method static getFields
- method static getForeignKeyFieldsMap
- method static getForeignKeysTargetField
- method static getForeignKeysTargetFieldNames
- method static getForeignKeysTargetModelNames
- method static getForeignKeysTargetModels
- method static getModel
- method static getModelContext
- method static getModelName
- method static getPluralModelName
- method static getPrimaryKeyField
- method static getPrimaryKeyFieldName
- method static getQueryEngine
- method static getQueryEngineClass
- method static getSingularName
- method static getSortedFields
- method static getTableName
- method static getUnscopedQueryEngine
- method static getWhereWithConnection
- method static hasField
- method static hasRemoteFieldValues
- method static initializeFields
- method static isForeignKeyTargetModel
- method static isModel
- method static isModelClass
- method static iterateFields
- method static last
- method static mergeFields
- method static pluck
- method static primaryKeyHasRemoteValue
- method static setContextValue
- method static toString
- method static updateModelContext
- method toJSON
- method toString
- method updateDirtyID
-
class ModelScope
- method _getField
- method AND
- method CROSS_JOIN
- method DISTINCT
- method EXISTS
- method Field
- method FULL_JOIN
- method GROUP_BY
- method HAVING
- method INNER_JOIN
- method JOIN
- method LEFT_JOIN
- method LIMIT
- method mergeFields
- method NOT
- method OFFSET
- method OR
- method ORDER
- method PROJECT
- method RIGHT_JOIN
-
class ModelType
- method fieldNameToOperationName
- method initialize
-
class ModelsType
- method fieldNameToOperationName
- method initialize
-
class NumericType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class ProxyClass
- property APPLY
- property AUTO_CALL
- property AUTO_CALL_CALLED
- property AUTO_CALL_CALLER
- property CALLABLE
- property CONSTRUCT
- property DEFINE_PROPERTY
- property DELETE_PROPERTY
- property GET
- property GET_OWN_PROPERTY_DESCRIPTOR
- property GET_PROTOTYPEOF
- property HAS
- property IS_EXTENSIBLE
- property MISSING
- property OWN_KEYS
- property PREVENT_EXTENSIONS
- property PROXY
- property SELF
- property SET
- property SET_PROTOTYPEOF
- property shouldSkipProxy
- property TARGET
- method ___autoCall
- method ___call
- method constructor
-
class QueryEngine
- method all
- method average
- method constructor
- method count
- method cursor
- method destroy
- method exists
- method finalizeQuery
- method first
- method getFieldScopeClass
- method getModelScopeClass
- method last
- method max
- method MERGE
- method min
- method Model
- method pluck
- method sum
- method toString
- method unscoped
- method updateAll
-
class QueryEngineBase
- method _fetchScope
- method _inheritContext
- method _newFieldScope
- method _newModelScope
- method _newQueryEngineScope
- method _pushOperationOntoStack
- method clone
- method constructor
- method filter
- method getAllModelsUsedInQuery
- method getConnection
- method getFieldScopeClass
- method getModel
- method getModelScopeClass
- method getOperationContext
- method getOperationStack
- method getQueryEngineClass
- method getQueryEngineScope
- method getQueryEngineScopeClass
- method getQueryID
- method isLastOperationCondition
- method isLastOperationControl
- method isModelUsedInQuery
- method logQueryOperations
- method map
- method queryHasConditions
- method queryHasJoins
- method static generateID
- method static getQueryOperationInfo
- method static isQuery
- method static isQueryOperationContext
- method walk
-
class QueryGeneratorBase
- method _averageLiteralToString
- method _countLiteralToString
- method _distinctLiteralToString
- method _fieldLiteralToString
- method _maxLiteralToString
- method _minLiteralToString
- method _sumLiteralToString
- method constructor
- method escape
- method escapeID
- method getConnection
- method getFieldDefaultValue
- method getIndexFieldsFromFieldIndex
- method setConnection
- method stackAssign
- method toConnectionString
-
class RealType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class SerializedType
- method castToType
- method constructor
- method deserialize
- method getOptions
- method initialize
- method isDirty
- method isValidValue
- method onSetFieldValue
- method serialize
- method static getDisplayName
- method toString
-
class StringType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class SumLiteral
- method static isAggregate
- method toString
-
class TextType
- method castToType
- method constructor
- method isValidValue
- method static getDisplayName
- method toString
-
class Type
- property _isMythixFieldType
- property clone
- method castToType
- method clone
- method constructor
- method deserialize
- method exposeToModel
- method getDisplayName
- method getField
- method getModel
- method initialize
- method isDirty
- method isForeignKey
- method isRelational
- method isRemote
- method isValidValue
- method isVirtual
- method onSetFieldValue
- method serialize
- method setField
- method setModel
- method static instantiateType
- method static isSameType
- method static isType
- method static isTypeClass
- method static wrapConstructor
- method toConnectionType
-
class UUIDV1Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV3Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV4Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class UUIDV5Type
- property Default
- method castToType
- method getArgsForUUID
- method isValidValue
- method static getDisplayName
- method validateOptions
-
class XIDType
- property Default
- method castToType
- method isValidValue
- method static getDisplayName