PostgreSQL exporter documentation
Overview
PostgreSQLExporter Convert the JSON Schema generated by schema-dsl into PostgreSQL DDL statements, supporting rich PostgreSQL features.
Core functions
- ✅ Generate
CREATE TABLEDDL statement - ✅ Automatic type mapping (supports JSONB, UUID, etc.)
- ✅ Automatically generate CHECK constraints
- ✅ Supports COMMENT of tables and columns
- ✅ Supports multiple index types (btree, hash, gin, gist)
- ✅ Support PostgreSQL schema namespace
quick start
Output:
API reference
Constructor
Parameters:
method
export(tableName, jsonSchema)
Generates a PostgreSQL CREATE TABLE statement.
Parameters:
tableName(string): table namejsonSchema(Object): JSON Schema object (must be of object type)
Return Value:
string: PostgreSQL DDL statements (including COMMENT statements)
generateIndex(tableName, columnName, options)
Generate index creation statements.
Parameters:
tableName(string): table namecolumnName(string): column nameoptions.name(string): index name (optional)options.unique(boolean): Is it a unique index?options.method(string): Index method (btree/hash/gin/gist)
PostgreSQLExporter.export(tableName, jsonSchema) (static method)
Fast export without instantiation.
Configuration options
Schema namespace
Complete example
User table DDL generation
Output:
type mapping
CHECK constraints
PostgreSQLExporter automatically generates CHECK statements for the following constraints:
String length constraints
Numeric range constraints
enumeration constraints
Index type
Export restrictions
⚠️ IMPORTANT NOTE: Although PostgreSQL supports CHECK constraints, some features cannot be exported.
Features not supported by PostgreSQL:
- ❌ Regular expression constraints (
pattern) - ❌ Nested object constraints (exported as
JSONB, internal constraints are lost) - ❌ Conditional validation logic (
s.match(),s.if())
Detailed instructions: Please read Export restrictions document
Related documents
Corresponding sample file
Example entry: postgresql-exporter.ts
Description: Covers PostgreSQL DDL export, CHECK constraint expression, and generateIndex() generates gin index.