Represents a variable length string type.

Fallback policy:

  • If the 'length' option is not supported by the dialect, a CHECK constraint will be added to ensure the value remains within the specified length.
  • If the 'binary' option is not supported by the dialect, a suitable binary type will be used instead. If none is available, an error will be raised instead.
DataTypes.STRING(255)

Hierarchy (View Summary)

Constructors

Properties

usageContext: undefined | DataTypeUseContext

Where this DataType is being used.

Accessors

Methods

  • Escapes a value for the purposes of inlining it in a SQL query. The resulting value will be inlined as-is with no further escaping.

    Parameters

    • value: string | Buffer<ArrayBufferLike>

      The value to escape.

    Returns string

  • This method is called when AbstractQueryGenerator needs to add a bind parameter to a query it is building. This method allows for customizing both the SQL to add to the query, and convert the bind parameter value to a DB-compatible value.

    If you only need to prepare the bind param value, implement toBindableValue instead.

    This method must return the SQL to add to the query. You can obtain a bind parameter ID by calling BindParamOptions#bindParam with the value associated to that bind parameter.

    An example of a data type that requires customizing the SQL is the GEOMETRY data type.

    Parameters

    • value: string | Buffer<ArrayBufferLike>

      The value to bind.

    • options: BindParamOptions

      Options.

    Returns string

  • Called when a value is retrieved from the Database, and its DataType is specified. Used to normalize values from the database.

    Note: It is also possible to do an initial parsing of a Database value using AbstractDialect#registerDataTypeParser. That normalization uses the type ID from the database instead of a Sequelize Data Type to determine which parser to use, and is called before this method.

    Parameters

    • value: unknown

      The value to parse.

    Returns unknown

  • Converts a JS value to a value compatible with the connector library for this Data Type. Unlike escape, this value does not need to be escaped. It is passed separately to the database, which will handle escaping.

    Parameters

    • value: string | Buffer<ArrayBufferLike>

      The value to convert.

    Returns unknown

  • Checks whether the JS value is compatible with (or can be converted to) the SQL data type. Throws if that is not the case.

    Parameters

    • value: any

    Returns asserts value is string | Buffer<ArrayBufferLike>