Skip to content

Columns & Data Types

PropertyDescription
NameColumn name (use camelCase, e.g., firstName)
TypeData type (see Column Types below)
Column ValueValues for ENUM, JSON type hints, or DECIMAL precision
LengthCharacter length for VARCHAR/CHAR types
Auto IncrementEnable auto-increment (numeric types only)
PrimaryMark as primary key column
UniqueCreates a unique constraint on this column
NullableWhether NULL values are allowed
DefaultDefault value expression (e.g., now(), 'active', 0)
CommentDocumentation comment stored in the database
RolesUser roles that can access this column
ScopesOAuth-style scopes for column-level access control

TypeSizeDescriptionTypeScript
SMALLINT2 bytes-32,768 to 32,767number
INTEGER4 bytes-2,147,483,648 to 2,147,483,647number
BIGINT8 bytesLarge integers (use for IDs and foreign keys)number
BIGSERIAL8 bytesAuto-incrementing big integernumber
SERIAL4 bytesAuto-incrementing integernumber
DECIMAL/NUMERICVariableExact numeric with user-specified precisionstring
REAL4 bytes6 decimal digits precision (single precision)number
DOUBLE PRECISION8 bytes15 decimal digits precision (double precision)number
BOOLEAN1 byteTrue/false valuesboolean

BIGINT / BIGSERIAL:

  • Primary keys (id) – safe for auto-incrementing IDs up to ~9 quadrillion
  • Foreign keys (userId, companyId)
  • Large counters or identifiers

⚠️ Note: Values exceeding ±2^53-1 may lose precision when mapped to JavaScript number. For most applications this is not a concern.

INTEGER:

  • Quantities, counts
  • Age, year values
  • Status codes

DECIMAL:

  • Money amounts
  • Percentages requiring precision
  • Any value where rounding errors are unacceptable

REAL / DOUBLE PRECISION:

  • Scientific measurements
  • Coordinates (latitude/longitude)
  • Statistical calculations where small rounding is acceptable

BOOLEAN:

  • Flags (isActive, hasAccess)
  • Yes/no questions
  • Binary states

For DECIMAL columns, specify precision in the Column Value field using the format precision-scale:

  • 10-2 → 10 total digits, 2 after decimal (e.g., 12345678.90)
  • 5-3 → 5 total digits, 3 after decimal (e.g., 12.345)
  • 19-4 → 19 total digits, 4 after decimal (e.g., 123456789012345.1234)

Example for currency:

Column: price
Type: DECIMAL
Column Value: 10-2

This allows values from -99999999.99 to 99999999.99.


TypeDescriptionTypeScript
CHARFixed-length, blank-padded (set length required)string
VARCHARVariable-length with limit (set length required)string
TEXTVariable-length without limitstring
BYTEABinary datastring

VARCHAR:

  • Names, emails, usernames (with appropriate length)
  • Short descriptions
  • Status values (though ENUM is often better)

TEXT:

  • Long descriptions, comments
  • Article content
  • Any text without a known maximum length

CHAR:

  • Fixed-length codes (country codes, state abbreviations)
  • Rarely used in modern applications
firstName, lastName: VARCHAR(30)
email: VARCHAR(255)
username: VARCHAR(50)
phone: VARCHAR(20)
zipCode: VARCHAR(10)
TypeMax SizeDescription
TINYTEXT255 BSmall text
TEXT64 KBStandard text
MEDIUMTEXT16 MBMedium text
LONGTEXT~2 GBLarge text
TINYBLOB255 BSmall binary data
BLOB64 KBStandard binary data
MEDIUMBLOB16 MBMedium binary data
LONGBLOB~2 GBLarge binary data

TypeDescriptionTypeScript
DATECalendar date (year, month, day)string
TIMETime of day (without time zone)string
TIMESTAMPDate and time (without time zone)string
TIMESTAMPTZDate and time (with time zone) - recommendedstring
INTERVALTime spanstring
DATETIMEDate and time (MariaDB, mapped to TIMESTAMPTZ)string

TIMESTAMPTZ:

  • Created/modified timestamps
  • Event times
  • Any datetime that needs timezone awareness
  • This should be your default choice

DATE:

  • Birth dates
  • Due dates
  • Any date without a specific time

TIME:

  • Business hours (opening/closing times)
  • Duration without date context

INTERVAL:

  • Duration between two times
  • Elapsed time calculations
createdOn: TIMESTAMPTZ, default: now()
modifiedOn: TIMESTAMPTZ, default: now()
deletedOn: TIMESTAMPTZ, nullable
birthDate: DATE
scheduledTime: TIMESTAMPTZ

TypeDescriptionTypeScript
JSONStores JSON data as raw textobject or custom
JSONBBinary JSON format, optimized for query performanceobject or custom
  • User preferences/settings
  • Flexible metadata
  • API response caching
  • Semi-structured data

JSONB vs JSON:

  • JSONB is faster for queries and indexing
  • JSON preserves exact formatting and key order
  • Use JSONB unless you have a specific reason not to

For JSON/JSONB columns, you can specify TypeScript type hints in the Column Value field:

MyCustomType, AnotherType

This generates: MyCustomType | AnotherType in the TypeScript definitions.

Example:

Column: preferences
Type: JSONB
Column Value: UserPreferences, AdminPreferences

TypeScript will type this as: preferences: UserPreferences | AdminPreferences


TypeDescriptionTypeScript
ENUMEnumerated values (PostgreSQL uses CHECK constraint)String union
  • Status fields with fixed values
  • Categories or types
  • Role names
  • Any field with a small, fixed set of options

Define ENUM options in the Column Value field:

'PENDING','ACTIVE','COMPLETED'

This generates:

  • Database: CHECK ("status" IN ('PENDING','ACTIVE','COMPLETED'))
  • TypeScript: 'PENDING' | 'ACTIVE' | 'COMPLETED'

Order status:

Column: status
Type: ENUM
Column Value: 'PENDING','PROCESSING','SHIPPED','DELIVERED','CANCELLED'

User role:

Column: role
Type: ENUM
Column Value: 'ADMIN','MANAGER','USER','GUEST'

Priority:

Column: priority
Type: ENUM
Column Value: 'LOW','MEDIUM','HIGH','URGENT'

Restura automatically maps database types to TypeScript types:

Database TypeTypeScript TypeNotes
BOOLEAN, TINYINT(1)boolean
SMALLINT, INTEGERnumber
BIGINT, BIGSERIALnumber⚠️ Precision loss possible beyond ±2^53-1
SERIALnumber
REAL, DOUBLE PRECISION, FLOATnumber
DECIMAL, NUMERICstring (for precision)
CHAR, VARCHAR, TEXTstring
DATE, TIME, TIMESTAMPstring
JSON, JSONBobject (or custom type if specified)
ENUMString union type
BYTEA, BLOBstring

id: BIGSERIAL, primary key, auto-increment
firstName: VARCHAR(30), not nullable
lastName: VARCHAR(30), not nullable
email: VARCHAR(255), unique, not nullable
passwordHash: TEXT, not nullable
role: ENUM('ADMIN','USER'), default: 'USER'
isActive: BOOLEAN, default: true
lastLoginOn: TIMESTAMPTZ, nullable
createdOn: TIMESTAMPTZ, default: now()
modifiedOn: TIMESTAMPTZ, default: now()
id: BIGSERIAL, primary key, auto-increment
userId: BIGINT, not nullable, foreign key to user.id
status: ENUM('PENDING','PROCESSING','COMPLETED','CANCELLED')
subtotal: DECIMAL(10,2), not nullable
tax: DECIMAL(10,2), not nullable
shipping: DECIMAL(10,2), not nullable
total: DECIMAL(10,2), not nullable
notes: TEXT, nullable
metadata: JSONB, nullable
createdOn: TIMESTAMPTZ, default: now()
modifiedOn: TIMESTAMPTZ, default: now()
id: BIGSERIAL, primary key, auto-increment
sku: VARCHAR(50), unique, not nullable
name: VARCHAR(100), not nullable
description: TEXT, nullable
price: DECIMAL(10,2), not nullable
compareAtPrice: DECIMAL(10,2), nullable
inventory: INTEGER, default: 0
isActive: BOOLEAN, default: true
tags: JSONB, nullable
images: JSONB, nullable
createdOn: TIMESTAMPTZ, default: now()
modifiedOn: TIMESTAMPTZ, default: now()

  1. Use the smallest type that fits your data – Saves storage and improves performance
  2. Use BIGINT for IDs – Prevents overflow on large tables (safe up to ~9 quadrillion for auto-incrementing IDs)
  3. Use DECIMAL for money – Avoids rounding errors
  4. Use TIMESTAMPTZ for dates – Handles timezones correctly
  5. Use ENUM for fixed sets – Enforces valid values at the database level
  • Make columns NOT NULL when the value is required
  • Use NULL for truly optional values
  • Consider using default values instead of allowing NULL
  • Document the meaning of NULL in your schema
  • Use now() for timestamp fields
  • Use true or false for boolean fields
  • Use 0 for numeric counters
  • Use 'PENDING' or similar for status fields
  • Avoid complex expressions in defaults

Use roles and scopes to control access to sensitive columns:

Column: socialSecurityNumber
Roles: ['ADMIN', 'HR']
Scopes: []

Learn more about permissions.