ontolosql is a Rust CLI that generates TypeScript ontology definition files for @osdk/maker from PostgreSQL schema files.
Current scope is intentionally narrow: it reads PostgreSQL DDL, extracts tables, columns, primary keys, and foreign keys, then emits:
defineObject(...)blocks for tablesdefineLink(...)blocks for one-to-many foreign key relationships- CSV files from
COPY ... FROM stdinblocks in dump files
Allows the generation of ontologies from existing database sources and/or generated SQL from existing tools like DBSchema or DBDesigner. Currently only supports PostGreSQL DDL's.
For each supported table, ontolosql maps:
- table name -> object
apiName,displayName,pluralDisplayName - primary key column ->
primaryKeyPropertyApiName - a best-effort human-readable column ->
titlePropertyApiName - columns ->
properties - foreign keys ->
defineLink(...)
If a table does not declare a primary key, ontolosql will try to infer one from a not-null identifier column such as id or show_id and print a warning to stderr.
Generated output targets @osdk/maker imports like:
import { defineLink, defineObject } from "@osdk/maker";For pg_dump-style COPY blocks it can also write one CSV per table for use as Foundry backing datasets.
Build and run:
cargo run -- generate --input schema.sql --output index.mts
cargo run -- extract-copy --input dump.sql --output-dir datasetsCLI help:
cargo run -- --help
cargo run -- generate --helpThe generator currently handles these schema elements:
CREATE TABLE- inline column definitions
- single-column primary keys
- foreign keys declared inline on columns
- foreign keys declared with table constraints
ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY ...
It also tolerates unrelated PostgreSQL statements in the same file and skips them when they are not relevant to ontology generation, including:
CREATE EXTENSIONCREATE TYPE ... AS ENUMCREATE INDEXCREATE FUNCTIONCREATE TRIGGER
This is important for real schema dumps that contain operational SQL in addition to table definitions.
For dump extraction, ontolosql also supports:
COPY ... FROM stdin;- tab-delimited PostgreSQL text rows
\Nnull markers- common PostgreSQL backslash escapes in field values
Current PostgreSQL to OSDK type mapping:
uuid,text,varchar,char,citext->stringsmallint,integer,int,serial,smallserial->integerbigint,bigserial->longnumeric,decimal,real,double precision->doubleboolean->booleandate->datetimestamp,timestamptz->timestamp
Unknown or unsupported SQL types currently fall back to string.
The generator normalizes SQL names into OSDK-friendly TypeScript identifiers:
software_part_numbers->softwarePartNumbersstock_size_bytes->stockSizeBytes- quoted SQL identifiers are unwrapped before mapping
For display names it also applies a light singular/plural heuristic:
software_part_numbers->Software Part Number/Software Part Numberscompanies->Company/Companiesmap_datastaysMap Data
This is still an MVP. Known limits:
- composite primary keys are not supported
- composite foreign keys are not supported
- inferred primary keys are best-effort heuristics, not guaranteed relational keys
- enum definitions are ignored and enum-backed columns are emitted as
string - no action types, interfaces, or shared property types are generated
- no special handling yet for multiple foreign keys that would collide on link naming
- no schema-aware namespace or repository integration yet
COPYextraction currently writes plain CSV files only; it does not generate Foundry dataset metadata or schemas yet
Run tests:
cargo testFormat:
cargo fmt- src/main.rs: CLI entrypoint
- src/generator.rs: file orchestration
- src/copy_extract.rs: pg_dump
COPYto CSV extraction - src/parser.rs: PostgreSQL parsing
- src/schema.rs: internal schema IR
- src/mapper.rs: SQL IR -> ontology IR
- src/ontology.rs: internal ontology IR
- src/renderer.rs:
.mtsrendering
The next meaningful improvements are:
- Generate enum-aware property definitions instead of flattening enum types to
string. - Make link naming collision-safe when several foreign keys point between the same tables.
- Add configuration for title-property selection and naming conventions.
- Generate Foundry-ready dataset metadata alongside extracted CSVs.