Skip to content

postgrelize / DataTypes

Variable: DataTypes ​

const DataTypes: object

Defined in: src/data-types/data-types.ts:125

Column types, API-compatible with Sequelize v6 DataTypes for PostgreSQL.

BIGINT and DECIMAL values are returned as strings (like Sequelize v6) to avoid precision loss.

Type Declaration ​

ARRAY ​

readonly ARRAY: <T>(subtype) => ArrayType & ArrayDataType<Element<T>>

type[], e.g. DataTypes.ARRAY(DataTypes.TEXT).

Type Parameters ​

T ​

T extends DataTypeInput

Parameters ​

subtype ​

T

Returns ​

ArrayType & ArrayDataType<Element<T>>

BIGINT ​

readonly BIGINT: CallableInteger<BigIntDataType>

BIGINT; values are returned as strings.

BIT ​

readonly BIT: Callable<BitType, [length?: number], BitType>

BIT(length), default length 1; values are strings of 0 and 1. PostgreSQL extension.

BLOB ​

readonly BLOB: Callable<BlobType, [size?: "tiny" | "medium" | "long"], BlobType>

BYTEA; values are Buffers.

BOOLEAN ​

readonly BOOLEAN: Callable<ScalarType, [], AbstractDataType>

BOOLEAN.

BOX ​

readonly BOX: GeometricType

BOX; values are [corner, corner] points (the server returns the upper right first). PostgreSQL extension.

CHAR ​

readonly CHAR: Callable<CharType, [length?: number], CharType>

CHAR(length), default length 255.

CIDR ​

readonly CIDR: Callable<ScalarType, [], AbstractDataType>

CIDR.

CIRCLE ​

readonly CIRCLE: GeometricType

CIRCLE; values are { x, y, radius }. PostgreSQL extension.

CITEXT ​

readonly CITEXT: Callable<ScalarType, [], AbstractDataType>

CITEXT (case-insensitive text, requires the citext extension).

COMPOSITE ​

readonly COMPOSITE: (name, fields) => CompositeType

Composite type, e.g. DataTypes.COMPOSITE('address', { street: DataTypes.TEXT, zip: DataTypes.INTEGER }); values are objects keyed by field name. Create the type first with createSql(). PostgreSQL extension.

Parameters ​

name ​

string

fields ​

Readonly<Record<string, DataTypeInput>>

Returns ​

CompositeType

DATE ​

readonly DATE: Callable<DateType, [fsp?: number], DateType>

TIMESTAMP WITH TIME ZONE; values are Date objects.

DATEONLY ​

readonly DATEONLY: Callable<ScalarType, [], AbstractDataType>

DATE; values are 'YYYY-MM-DD' strings.

DECIMAL ​

readonly DECIMAL: Callable<DecimalType, [digits?: number, scale?: number], DecimalType>

DECIMAL(precision, scale); values are returned as strings.

DOUBLE ​

readonly DOUBLE: Callable<ScalarType, [length?: number, decimals?: number], DoubleDataType>

DOUBLE PRECISION.

DOUBLE PRECISION ​

readonly DOUBLE PRECISION: Callable<ScalarType, [length?: number, decimals?: number], DoubleDataType>

DOUBLE PRECISION (v6 alias of DOUBLE).

ENUM ​

readonly ENUM: <T>(...args) => EnumType & EnumDataType<T>

Enumerated values: DataTypes.ENUM('a', 'b') or DataTypes.ENUM({ values: ['a', 'b'] }).

Type Parameters ​

T ​

T extends string = string

Parameters ​

args ​

...readonly (T | readonly T[] | Readonly<{ values: readonly T[]; }>)[]

Returns ​

EnumType & EnumDataType<T>

FLOAT ​

readonly FLOAT: Callable<FloatType, [digits?: number], FloatType>

FLOAT(precision).

GEOGRAPHY ​

readonly GEOGRAPHY: Callable<SpatialType, [geographyType?: string, srid?: number], SpatialType>

PostGIS GEOGRAPHY(type, srid).

GEOMETRY ​

readonly GEOMETRY: Callable<SpatialType, [geometryType?: string, srid?: number], SpatialType>

PostGIS GEOMETRY(type, srid).

HSTORE ​

readonly HSTORE: Callable<HstoreType, [], AbstractDataType>

HSTORE (requires the hstore extension); values are objects of string (or null) values, like Sequelize v6.

INET ​

readonly INET: Callable<ScalarType, [], AbstractDataType>

INET.

INTEGER ​

readonly INTEGER: CallableInteger<IntegerDataType>

INTEGER.

INTERVAL ​

readonly INTERVAL: ScalarType

INTERVAL; values are PostgreSQL interval strings (e.g. '1 day 02:00:00'). PostgreSQL extension.

JSON ​

readonly JSON: Callable<JsonType, [], AbstractDataType>

JSON.

JSONB ​

readonly JSONB: Callable<JsonType, [], AbstractDataType>

JSONB.

LINE ​

readonly LINE: GeometricType

LINE (a·x + b·y + c = 0); values are { a, b, c }. PostgreSQL extension.

LSEG ​

readonly LSEG: GeometricType

LSEG line segment; values are [start, end] points. PostgreSQL extension.

LTREE ​

readonly LTREE: ScalarType

LTREE label path (requires the ltree extension); values are strings like 'Top.Science'. PostgreSQL extension.

MACADDR ​

readonly MACADDR: Callable<ScalarType, [], AbstractDataType>

MACADDR.

MACADDR8 ​

readonly MACADDR8: ScalarType

MACADDR8 (EUI-64 address). PostgreSQL extension.

MEDIUMINT ​

readonly MEDIUMINT: CallableInteger<MediumIntegerDataType>

Mapped to INTEGER (PostgreSQL has no MEDIUMINT).

MONEY ​

readonly MONEY: ScalarType

MONEY; values are strings formatted by the server's lc_monetary (e.g. '$12.50'); numbers are accepted on write. PostgreSQL extension.

MULTIRANGE ​

readonly MULTIRANGE: Callable<MultirangeType, [subtype: DataTypeInput], MultirangeType>

Multirange type (PostgreSQL 14+), e.g. DataTypes.MULTIRANGE(DataTypes.INTEGER) → INT4MULTIRANGE; values are arrays of [lower, upper] ranges. PostgreSQL extension.

NOW ​

readonly NOW: DefaultValueGenerator

Default value: current timestamp.

NUMBER ​

readonly NUMBER: Callable<DecimalType, [digits?: number, scale?: number], DecimalType>

Alias of DECIMAL.

NUMERIC ​

readonly NUMERIC: Callable<DecimalType, [digits?: number, scale?: number], DecimalType>

Alias of DECIMAL (v6 NUMERIC).

PATH ​

readonly PATH: GeometricType

PATH; values are { points, closed }. PostgreSQL extension.

POINT ​

readonly POINT: GeometricType

POINT; values are { x, y }. PostgreSQL extension.

POLYGON ​

readonly POLYGON: GeometricType

POLYGON; values are arrays of { x, y } points. PostgreSQL extension.

RANGE ​

readonly RANGE: RangeFactory

Range type, e.g. DataTypes.RANGE(DataTypes.INTEGER) → INT4RANGE.

REAL ​

readonly REAL: Callable<ScalarType, [length?: number, decimals?: number], RealDataType>

REAL.

SMALLINT ​

readonly SMALLINT: CallableInteger<SmallIntegerDataType>

SMALLINT.

STRING ​

readonly STRING: Callable<StringType, [length?: number], StringType>

VARCHAR(length), default length 255.

TEXT ​

readonly TEXT: Callable<TextType, [size?: "tiny" | "medium" | "long"], TextType>

TEXT. The size argument is accepted for compatibility and ignored.

TIME ​

readonly TIME: Callable<ScalarType, [], AbstractDataType>

TIME.

TIMESTAMP ​

readonly TIMESTAMP: Callable<TimestampType, [fsp?: number], TimestampType>

TIMESTAMP WITHOUT TIME ZONE; values are Date objects whose local wall-clock time is the stored time. PostgreSQL extension.

TINYINT ​

readonly TINYINT: CallableInteger<TinyIntegerDataType>

Mapped to SMALLINT (PostgreSQL has no TINYINT).

TSQUERY ​

readonly TSQUERY: ScalarType

TSQUERY; values are full-text query strings. PostgreSQL extension.

TSVECTOR ​

readonly TSVECTOR: Callable<ScalarType, [], AbstractDataType>

TSVECTOR.

UUID ​

readonly UUID: Callable<ScalarType, [], AbstractDataType>

UUID.

UUIDV4 ​

readonly UUIDV4: DefaultValueGenerator

Default value: random UUID v4 generated on the client.

VARBIT ​

readonly VARBIT: Callable<BitType, [length?: number], BitType>

BIT VARYING(length), unlimited without a length; values are strings of 0 and 1. PostgreSQL extension.

VIRTUAL ​

readonly VIRTUAL: VirtualFactory

Attribute that is not stored in the database (computed by getters/setters).

XML ​

readonly XML: ScalarType

XML; values are XML text. PostgreSQL extension.

Example ​

ts
User.init({ id: { type: DataTypes.BIGINT, primaryKey: true }, name: DataTypes.STRING(64) }, { sequelize });

Released under the MIT License.