Skip to content

CharType

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

class CharType extends Type 📜

CHAR type.

This represents a "char" type for the underlying database, which is a single character.

Example:

  • class Booleans extends Model {
      static fields = {
        char1: Types.CHAR,
        char2: new Types.CharType(),
      };
    }

See also: Type

method CharType::castToType(
    context: CastToTypeContext,
): string | null | undefined
📜

Cast provided value to underlying type.

This will cast the incoming value to the underlying type of this field, a string primitive with a length of one character. If the provided value is not a string or a String, or if the string provided has a character length greater than one, then an exception will be thrown.

See Type.castToType for a more detailed description.

Arguments:

Return value: string | null | undefined

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


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

Check if the provided value is valid.

This will check if the provided value is a string or a String with a length of one character. If it is, then this will return true, otherwise it will return false.

Arguments:

  • value: any

    The value to check.

Return value: boolean


static method CharType::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 'CHAR'


method CharType::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 'CHAR'.

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