Skip to content

BlobType

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

class BlobType extends Type 📜

BLOB type.

This represents a "blob", or random binary data.

BlobType expects that the value you provide to the field will be a Buffer instance. If it isn't it will throw an error when castToType is called. null and undefined are also acceptable values for a BlobType field.

Example:

  • class Blobs extends Model {
      static fields = {
        blob1: Types.BLOB(1024),
        blob2: new Types.BlobType(1024),
      };
    }

See also: Type

method BlobType::castToType(
    context: CastToTypeContext,
): Buffer | null | undefined
📜

Cast provided value to underlying type.

Unlike most type casters, this doesn't do any casting. You must provide either a Buffer, null, or undefined as the value to your blob field. If any other type of value is provided then an exception will be thrown.

See Type.castToType for a more detailed description.

Arguments:

Return value: Buffer | null | undefined

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


method BlobType::constructor(
    length?: number,
): BlobType
📜

Construct a new BLOB type.

The length argument is the number of bytes to use in the database to store the data.

Arguments:

  • length?: number

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

Return value: BlobType


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

Check if the provided value is valid.

This will check if the provided value is a Buffer. If it is, it will return true, otherwise it will return false.

Arguments:

  • value: any

    The value to check.

Return value: boolean


static method BlobType::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 'BLOB'


method BlobType::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 'BLOB'.

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