-
Notifications
You must be signed in to change notification settings - Fork 0
Type
class Type 📜
Base type class for all other field types.
static property Type::_isMythixFieldType 📜
static property Type::clone 📜
method Type::castToType(context: CastToTypeContext): any 📜
Cast a value to the underlying field type.
This method is implemented differently for
every field type. Its job is to cast any
value provided to the type. For many types,
if a null or undefined value is provided,
then that value will simply be returned.
Interface:
interface CastToTypeContext { connection: Connection; // The connection of the model. field: Field; // The field descriptor that has this type. Model: class Model; // The parent Model class of the field. self: Model; // The model instance. value: any; // The value that should be cast. };Arguments:
context:CastToTypeContextThe "context" passed to
castToType. This contains all that any type should need to cast a value.Return value:
any
method Type::clone(): Type 📜
Clone this field type.
Return value:
TypeThis field type, cloned to a new instance.
method Type::constructor(...args: Array<any>): Type 📜
Instantiate a new field Type.
Arguments:
...args:Array<any>All field types "record" their constructor arguments, always. Mythix ORM requires that all field types, when calling
superin their constructor, provide the baseTypeclass all arguments provided to their constructor. This is so that the field type can later be cloned or serialized.Return value:
Type
method Type::deserialize(value: any, connection?: Connection): any 📜
Deserialize the field's value. This is the opposite of Type.serialize.
The job of this method to serialize the field's value for any serialize operation,
generally to JSON. If a connection is provided as the second argument,
then it is assumed by the field type that it is being serialized for the
database. In this case the connection generally assists with the serializing
of the value. This is used for example with DateType
and DateTimeType types, when they need to be serialized to or from
a database operation.
Arguments:
value:anyThe field's value to deserialize.
connection?: ConnectionAn optional connection, which if provided will likely change how the value is deserialized.
Return value:
anyThe deserialized value for the field.
See also: Type.serialize
method Type::exposeToModel(): boolean 📜
Used to decide if a field should be exposed on the model or not.
Some fields, such as types like ModelType and
ModelsType do not expose themselves on the model
as model fields. Instead they only expose themselves via the
relationship methods they inject onto the model instance.
Most fields do expose themselves on the model, but any
field that overrides this method and returns false will
not be exposed on the model instance.
Notes:
- This method is also a static method on the type class.
Return value:
booleanIf
trueis returned, then the field owning this type will be added to the model instance, and accessible by the user. Iffalseis returned, then the field will be "hidden", and not exposed to the user on model instances.
method Type::getDisplayName(): string 📜
Get the "display name" for this type instance.
This will return a "human friendly" name for the type,
generally used for logging or debugging. It will change
based on the type it is called upon. For example, a
BooleanType will return the string value 'BOOLEAN'.
Notes:
- This method is also a static method on the type class.
Return value:
stringA string representing the type. This is not the same as the database equivalent type. Rather, it is simply used to represent the type for logging or debugging.
method Type::getField() 📜
Get the field that owns this type.
method Type::getModel() 📜
Get the model class that owns this field type.
method Type::initialize(connection: Connection, self: Model): undefined 📜
Initialize a model instance against this type.
Initialize is called whenever a model instance is
created. Note that the type instance is shared
across all model instances. initialize is still
called for every model instance that is created however,
because the type class can modify the model it
exists on. For example, the ModelType and ModelsType types
inject custom relational methods onto each model instance.
Arguments:
connection: ConnectionThe database connection of the calling model instance.
self:ModelThe actual model instance that is calling this method.
Return value:
undefined
method Type::isDirty(context: CheckDirtyContext): boolean 📜
Check if the field value is dirty.
This is only used by some field types, such as SerializedType.
It will respond with true if the field is dirty, or false if it isn't.
Interface:
interface CheckDirtyContext { value: any; // The field's current value field: Field; // The field that is being checked fieldName: string; // The fieldName of the field that is being checked self: Model; // The model instance the field is from connection: ConnectionBase; // The current connection }Arguments:
context:CheckDirtyContextThe context provided to the call.
Return value:
booleanReturns
trueif the field is dirty, orfalseotherwise.
method Type::isForeignKey(): boolean 📜
Check if this field type is a foreign key type.
Notes:
- This method is also a static method on the type class.
Return value:
booleanReturn
trueif this field type defines a foreign key, orfalseotherwise.
method Type::isRelational(): boolean 📜
Check if this field type is a relational field type.
Notes:
- This method is also a static method on the type class.
Return value:
booleanReturn
trueif this field type defines a relation, instead of a direct value. Field types such as ModelType and ModelsType are examples of relational field types. ForeignKeyType is not a relational type, but is instead considered a "concrete" type. Even though it does technically define a relationship, it is also a direct field, that actually has a concrete value, backed by database storage.
method Type::isRemote(): boolean 📜
Check if this field's value is driven by the database.
For example, given an AUTOINCREMENTING id field, this
would return true, because the value of the field is
provided by the database itself. This can be true for
nearly any field type, but is generally only true for
auto-incrementing ids, and date/time types.
Return value:
booleanReturn
truefor any field type that has a value provided directly by the underlying database, orfalseotherwise.
method Type::isValidValue(value: any): boolean 📜
Check if the value provided is a valid value for this field type.
This is used to check if any value would be a valid value for
this type. For example, if this type happens to be a BooleanType,
then isValidValue would only return true if the provided value
was either true or false. All field types have their own custom
isValidValue implementation, to verify values against their type.
Arguments:
value:anyAny value to check.
Return value:
booleanReturn
trueif the providedvalueis a valid value for the field type this was called upon, orfalseotherwise.
method Type::isVirtual(): boolean 📜
Check if this field type is a virtual field type.
Notes:
- This method is also a static method on the type class.
Return value:
booleanReturn
trueif this field type is a virtual field type. Virtual fields are fields that don't directly store a concrete value themselves. They often pull and combine values from other fields, or other models. Currently the only virtual fields in Mythix ORM are ModelType and ModelsType.
method Type::onSetFieldValue(): undefined 📜
This method is called any time a field's value is set on a model.
It is only used by the SerializedType to update its internal "dirty" cache. It can be used by any field type however to detect when a model's field's value changes.
Interface:
interface SetFieldValueContext { value: any; field: Field; fieldName: string; self: Model; }Return value:
undefinedThis method returns nothing.
method Type::serialize(value: any, connection?: Connection): any | string 📜
Serialize the field's value. This is the opposite of Type.deserialize.
This is used mostly by the Model.toJSON method to serialize values for JSON format. However, it is also used in some other cases, such as formatting for DateType and DateTimeType, and for checking dirtiness in the SerializedType.
The job of this method is to serialize the field's value for any serialize operation,
generally to JSON. If a connection is provided as the second argument,
then it is assumed by the field type that it is being serialized for the
database. In this case the connection generally assists with the serializing
of the value. This is used for example with DateType
and DateTimeType types, when they need to be serialized to or from
a database operation.
Arguments:
value:anyThe field's value to serialize.
connection?: ConnectionAn optional connection, which if provided will likely change how the value is serialized.
Return value:
any|stringThough the return value will generally be a string, it isn't required to be.
See also: Type.deserialize
Set the field that owns this type.
Arguments:
field: FieldThe field that owns this type.
Set the model class that this type belongs to.
Arguments:
Model: class ModelThe model class that owns this field type.
Instantiate this field type.
This method will instantiate the type class it
is called from. It won't instantiate the type if
it is already instantiated, and it will call the
type wrapper if one was provided (see Type.static wrapConstructor).
It may not need to instantiate the type if the user already
did so (for example type: new Types.StringType(),
or type: Types.STRING()). It may need to instantiate
however if the user didn't do so, for example type: Types.StringType,
or type: Types.STRING.
Notes:
- If the type is already instantiated, then it will be cloned instead using Type.clone.
Arguments:
_typeReturn value: Type
The instantiated type instance.
Check to see if the provided type is the same as this type.
This checks if the two types are the same type by comparing
the type names. For example, a Types.BooleanType.isSameType(new BooleanType())
would return true.
Arguments:
value: TypeA type instance to check. This must be a type instance, not a type class.
Return value:
booleanReturn
trueif the providedvalueis the same type instance as this type class. Returnfalseotherwise. Similarity is based on the name of the types. If the class names between the two match, then the types are considered the same type.
static method Type::isType(value: any): boolean 📜
Check to see if the provided value is
an instance of a Mythix ORM Type.
Unlike Type.static isTypeClass, which
checks if a class is a Type, this will check
to see if an instance is an instance of a
Mythix ORM Type. It will return
true if the provided value is an instanceof
Type, or if the value's constructor
property has a truthy _isMythixFieldType property
(value.constructor._isMythixFieldType)
Arguments:
value:anyValue to check.
Return value:
boolean
static method Type::isTypeClass(value: Function): boolean 📜
Use this method to check if a class
is a Mythix ORM field type. It will return
true if the provided value is a class
that inherits from Type, or
if the provided value has an attribute
named _isMythixFieldType that is truthy.
Arguments:
value:FunctionValue to check.
Return value:
boolean
This method is used to create the "shortcut" types
for Mythix ORM. For example, a "string" type can be
created either via new Types.StringType(), or via Types.STRING().
Both are equivalent. Types.STRING was created by calling
Types.STRING = Type.wrapConstructor(Types.StringType).
This method "wraps" a type constructor, providing a more
convenient way to create and use field types. It works
by wrapping the provided class's constructor in a callable
method. If the method is not called (i.e. type: Types.STRING)
then the type system still knows what to do, because the wrapping
method will be called by Mythix ORM to instantiate the type
when the model's fields are first fetched.
Arguments:
TypeKlass: class TypeA
Typeclass to wrap.Return value:
FunctionA callable function to instantiate the type class. If not called by the user, then Mythix ORM will call the method when the type is being created to fetch the type instance.
method Type::toConnectionType(connection: Connection, options?: object): string 📜
Convert this type to the underlying type of the database driver.
This is generally called by a QueryGenerator
instance to convert the field's type to the
underlying type of the database. If a connection
argument is provided, then it will proxy the
call to Connection.typeToString.
If no connection argument is provided, then
it will simply return the "common" SQL string
representation for this type.
Arguments:
connection: ConnectionThe database driver connection this type is being converted to.
options?:objectAny options to pass through with the type conversion. This options object will be passed to the Connection.typeToString call.
Return value:
stringA string type representing the underlying database driver type, or the "common" SQL type if not
connectionis provided.
- 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