Skip to main content

Data model

The DataModel is the paradigm-neutral schema produced by a scan. It is the aggregate of every Entity discovered, with relationships in both directions attached.

Entity

Each table or collection becomes an Entity:

interface Entity {
namespace: string; // schema (Postgres) or database (MySQL)
name: string; // table name
fields: readonly Field[]; // columns in declaration order
identifier: readonly string[]; // primary key columns
relationships: readonly Relationship[];
constraints: readonly Constraint[];
indexes: readonly Index[];
description: string | null; // table comment
}

Field

Each column becomes a Field with a normalized type category:

interface Field {
name: string;
type: FieldType;
nullable: boolean;
isIdentifier: boolean;
defaultValue: string | null;
description: string | null;
}

interface FieldType {
category: FieldTypeCategory;
nativeType: string; // original type from the database
length?: number;
precision?: number;
scale?: number;
enumValues?: readonly string[];
elementType?: FieldType; // for array types
}

Type categories

CategoryPostgres typesMySQL types
stringtext, varchar, char, citextvarchar, char, text, tinytext, mediumtext, longtext
integerint2, int4, int8, serialtinyint, smallint, mediumint, int, bigint
decimalnumeric, float4, float8, moneydecimal, float, double
booleanbooltinyint(1)
datedatedate, year
timestamptimestamp, timestamptzdatetime, timestamp
timetime, timetztime
jsonjson, jsonbjson
uuiduuid--
binarybyteabinary, varbinary, blob, bit
enumcustom enum typesenum, set
arrayany[]--
unknowneverything elseeverything else

Constraints

interface Constraint {
name: string;
kind: 'unique' | 'check' | 'exclusion' | 'custom';
fields: readonly string[];
expression: string | null;
}

Indexes

interface Index {
name: string;
fields: readonly string[];
unique: boolean;
kind: 'btree' | 'hash' | 'gin' | 'gist' | 'brin' | 'spgist' | 'unknown';
partial: boolean; // Postgres only
definition: string | null;
}