Skip to content

LiteralBase

Wyatt Greenway edited this page Dec 13, 2022 · 7 revisions

class LiteralBase 📜

LiteralBase is the class all other literals inherit from.

Literals are special types in Mythix ORM that are used to define "literal values" for the underlying database.

This literal--being the top most ancestor of all other literals-- defines common behavior for literals.


See also: AverageLiteral, CountLiteral, DistinctLiteral, FieldLiteral, Literal, MaxLiteral, MinLiteral, SumLiteral

static property LiteralBase::_isMythixLiteral 📜

Assist with type-checking.


method LiteralBase::constructor(
    literal: string,
    options?: object,
): LiteralBase
📜

Construct a new literal.

Arguments:

  • literal: string

    The literal value you wish to insert into the query.

  • options?: object

    Literal, connection, and operation specific options.

Return value: LiteralBase


method LiteralBase::definitionToField(
    connection,
    definition,
)
📜

Take a field definition and return the actual Field instance for it.

If a literal is provided... or a value that isn't understood (such as a string), then it is simply returned unmodified.

Notes:

Arguments:

  • connection
  • definition

See also: ModelUtils.parseQualifiedName


method LiteralBase::fullyQualifiedNameToDefinition(
    fullyQualifiedName,
)
📜

Take the value provided as either a Field instance, or a fully qualified field name, then return the field definition for it.

If a literal is provided instead, then simply return the literal without modifying it.

Notes:

Arguments:

  • fullyQualifiedName

See also: ModelUtils.parseQualifiedName


static method LiteralBase::isAggregate(): boolean 📜

Used internally in the engine to know if a literal being operated upon is an aggregating literal or not.

Notes:

  • This method is also a matching instance method.

Return value: boolean

Return true, informing the caller that this literal is used for aggregate operations.


static method LiteralBase::isLiteral(
    value: any,
): boolean
📜

Check to see if the provided value is an instance of a Mythix ORM LiteralBase. Unlike LiteralBase.static isLiteralClass, which checks if a class is a LiteralBase, this will check to see if an instance is an instance of a Mythix ORM LiteralBase. It will return true if the provided value is an instanceof LiteralBase, or if the value's constructor property has a truthy _isMythixLiteral property (value.constructor._isMythixLiteral)

Notes:

  • This method is also a matching instance method.

Arguments:

  • value: any

    Value to check.

Return value: boolean


static method LiteralBase::isLiteralClass(
    value: Function,
): boolean
📜

Use this method to check if a class is a Mythix ORM Literal. It will return true if the provided value is a class that inherits from LiteralBase, or if the provided value has an attribute named _isMythixLiteral that is truthy.

Arguments:

  • value: Function

    Value to check.

Return value: boolean


static method LiteralBase::isLiteralType(
    value: any,
): boolean
📜

Check to see if the provided value is an instance of this literal type. Unlike LiteralBase.static isLiteral, which checks if an instance is any LiteralBase type, this will check if the provided literal is exactly this type of literal. It will return true if the provided value is an instanceof this literal class, or if the value's constructor property has a name that is equal to this literal's class name. (value.constructor.name === this.name)

Example:

  • console.log(CountLiteral.isLiteralType(new AverageLiteral('User:age')))
    // false
    
    console.log(CountLiteral.isLiteralType(new CountLiteral('*')))
    // true

Notes:

  • This method is also a matching instance method.

Arguments:

  • value: any

    Value to check.

Return value: boolean


method LiteralBase::toString(
    connection?: Connection,
    options?: object,
): string
📜

Convert the literal value provided to the constructor to a string.

Arguments:

  • connection?: Connection

    The connection to use to stringify the literal. If not provided, then a "representation" of the literal (for logging/debugging) will be returned instead.

  • options?: object

    Any options needed to stringify the literal. These are often literal and/or database specific.

Return value: string

The stringified literal, ready to be used in the underlying database (if a connection was provided), or a logging/debugging representation of the literal if no connection is provided.


method LiteralBase::valueOf(): any 📜

Return the raw value provided to the constructor.

Return value: any

The raw value provided to the constructor.



Clone this wiki locally