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
| Category | Postgres types | MySQL types |
|---|---|---|
string | text, varchar, char, citext | varchar, char, text, tinytext, mediumtext, longtext |
integer | int2, int4, int8, serial | tinyint, smallint, mediumint, int, bigint |
decimal | numeric, float4, float8, money | decimal, float, double |
boolean | bool | tinyint(1) |
date | date | date, year |
timestamp | timestamp, timestamptz | datetime, timestamp |
time | time, timetz | time |
json | json, jsonb | json |
uuid | uuid | -- |
binary | bytea | binary, varbinary, blob, bit |
enum | custom enum types | enum, set |
array | any[] | -- |
unknown | everything else | everything 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;
}