Skip to content

BooleanType

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

class BooleanType extends Type 📜

BOOLEAN type.

This represents a "boolean" type for the underlying database.

Example:

  • class Booleans extends Model {
      static fields = {
        boolean1: Types.BOOLEAN,
        boolean2: new Types.BooleanType(),
      };
    }

See also: Type

method BooleanType::castToType(
    context: CastToTypeContext,
): boolean | null | undefined
📜

Cast provided value to underlying type.

This will cast the incoming value to the underlying type of this field, a boolean primitive. It has some special edge-cases to be aware of. If a string value matching 'true' or 'TRUE' is given, then this will result in true. If a value matching 'false' or 'FALSE' is provided, then the result will be false. Otherwise, the result of !!value is returned.

See Type.castToType for a more detailed description.

Arguments:

Return value: boolean | null | undefined

Return the incoming value, cast to this type. null and undefined are simply returned without casting.


method BooleanType::isValidValue(
    value: any,
): boolean
📜

Check if the provided value is valid.

This will check if the provided value is either true or false exactly, as a primitive. If typeof value === 'boolean' then this method will return true, otherwise it will return false.

Arguments:

  • value: any

    The value to check.

Return value: boolean


static method BooleanType::getDisplayName(): string 📜

Get the "display" name for this type.

This method is called from Model.toString when stringifying the model for representation.

Notes:

  • This is also an instance method that can be called from an instance of the type.

Return value: string

Return the string value 'BOOLEAN'


method BooleanType::toString(
    connection?: Connection,
): string
📜

Stringify the type itself.

If a connection argument is provided, then this will go through the connection to generate the type for the underlying database. If no connection is provided, then a "standard" SQL type will be returned for this type instead. The "standard" type returned when no connection is provided is 'BOOLEAN'.

Arguments:

  • connection?: Connection

    An optional connection. If provided, send this type through Type.toConnectionType to have the connection itself generate the underlying type for the database. If connection is not provided, then this will simply return a "standard" generic matching SQL type.

Return value: string



Clone this wiki locally