Skip to content

BigIntType

Wyatt Greenway edited this page Nov 23, 2022 · 20 revisions

class BigIntType extends Type

BIGINT type.

This represents a "big integer", or a 64+ bit integer in any underlying database.

By default, BIGINT will use the number primitive to store values in JavaScript client-side. This choice was made because the number primitive is more commonly dealt with, and its max storage capacity is the number 9,007,199,254,740,991, which is generally far above and beyond what most databases will ever reach. However, you can pass the { strict: true } argument to the constructor when defining the type, and in this case it will instead use JavaScript's BigInt type to store this value client-side. 📜

Example:

  • class Numbers extends Model {
      static fields = {
        number1: Types.BIGINT(8, { strict: true }),
        number2: new Types.BigIntType(8, { strict: true }),
        autoIncrementing: {
          type: Types.BIGINT,
          defaultValue: Types.BIGINT.Default.AUTO_INCREMENT,
        },
      };
    }

Notes:

  • SQLite currently doesn't support 64bit auto-incrementing IDs (except on the primary key itself). For this reason, Mythix ORM supports emulation of BIGINT auto-incrementing IDs in its mythix-orm-sqlite driver. You can read more about it in the documentation. See also: Type

property BigIntType::Default: object = { AUTO_INCREMENT }

AUTO_INCREMENT is a method that can be used as the defaultValue of a Field to have this field auto-increment in the underlying database.


method BigIntType::castToType(context: CastToTypeContext): number | BigInt | null | undefined 📜

Cast provided value to underlying type.

This will cast the incoming value to the underlying type of this field, either a number primitive, or a BigInt if in "strict" mode. A null or undefined value will simply be returned.

See Type.castToType for a more detailed description.

Arguments:

Return value: number | BigInt | null | undefined

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


method BigIntType::constructor(length?: number = 8, options?: object): BigIntType 📜

Construct a new BIGINT type.

The length argument--as on all integer types in Mythix ORM--specifies the number of bytes to use for this type in the database. Each underlying database driver will interpret this value in a way that makes sense to the database.

The "options" argument can be used to specify if this BIGINT type should be in "strict" mode. "strict" mode simply means that the client-side storage for the field's value (in JavaScript) will actually be a BigInt type. By default, the underlying field value is stored as a number primitive.

Arguments:

  • length?: number (Default: 8)

    How many bytes to use in the underlying database to store the value.

  • options?: object

    Only possible option is { strict: true }, which will change the underlying field to use BigInt for value storage.

Return value: BigIntType


method BigIntType::isValidValue(value: any): boolean 📜

Check if the provided value is valid.

This will check if the provided value is a number or a BigInt instance, and if it is finite. If both conditions are true, then it will return true.

Arguments:

  • value: any

    The value to check.

Return value: boolean


static method BigIntType::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 'BIGINT'


method BigIntType::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 'BIGINT' or 'BIGINT(${this.length})' if a length is provided to the type.

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