@absolutejs/dbml 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@absolutejs/dbml`.
4
+
5
+ This file is generated by `absolute-changelog` from the entries in
6
+ `changelog/`. Edit an entry, not this file — and add new ones under
7
+ `changelog/unreleased/`.
8
+
9
+ ## 0.1.0 — 2026-11-19
10
+
11
+ ### Added
12
+
13
+ - **Turn a Drizzle schema, or a live Postgres database, into DBML**
14
+ fromDrizzle reads a Drizzle 1.0 schema in any of its dialects (PostgreSQL, MySQL, SQLite, SingleStore, SQL Server, CockroachDB): tables, enums (named and inline), every column type and array, identity, serial and generated columns, defaults, composite and named keys, unique constraints, indexes with their order, method, expressions and predicates, checks, foreign keys with their actions, row-level security and policies, views and materialized views with lineage, sequences and roles, and both styles of relations, with app-only relations as inactive refs and many-to-many ones as <> refs. fromPostgres reads the same from a live database's catalogs, whatever made it, with comments as notes and optionally its first rows as Records. printDbml writes either as DBML, and every construct is tested against the official DBML parser. The absolute-dbml command does both from a terminal.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alex Kahn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,73 @@
1
- # Temporary Holding Version
1
+ # @absolutejs/dbml
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Turn any Drizzle schema, or a live Postgres database, into
4
+ [DBML](https://dbml.dbdiagram.io/docs/), so it can be drawn as a diagram,
5
+ read in a review, or kept next to the code.
6
+
7
+ ```ts
8
+ import { printDbml } from '@absolutejs/dbml';
9
+ import { fromDrizzle } from '@absolutejs/dbml/drizzle';
10
+ import * as schema from './db/schema';
11
+
12
+ const dbml = printDbml(fromDrizzle(schema));
13
+ ```
14
+
15
+ ```ts
16
+ import { fromPostgres } from '@absolutejs/dbml/postgres';
17
+
18
+ // Any driver: give it a function that runs one query with $1-style parameters.
19
+ const model = await fromPostgres((text, params) => client.query(text, params).then((result) => result.rows));
20
+ ```
21
+
22
+ Or from a terminal:
23
+
24
+ ```sh
25
+ bunx @absolutejs/dbml src/db/schema.ts -o schema.dbml
26
+ bunx @absolutejs/dbml --postgres "$DATABASE_URL" --records 5
27
+ ```
28
+
29
+ ## What it covers
30
+
31
+ **From a Drizzle schema** (Drizzle 1.0, every dialect: PostgreSQL, MySQL,
32
+ SQLite, SingleStore, SQL Server, CockroachDB):
33
+
34
+ - tables in their schemas, every column type, arrays of any depth;
35
+ - enums, named (`pgEnum`, `pgSchema.enum`) and inline (MySQL's `enum(...)`,
36
+ SQLite text limited to some values, which become named enums);
37
+ - primary keys, composite and named; unique columns and constraints;
38
+ - identity, serial and auto-increment columns, generated columns;
39
+ - defaults, literal and SQL, and values the app sets (`$defaultFn`,
40
+ `$onUpdate`, `onUpdateNow`);
41
+ - indexes with their order, method (`gin`, `brin`, `hash`...), expressions,
42
+ predicates and options; checks;
43
+ - foreign keys with `on delete` / `on update`, one-to-one where the columns
44
+ are unique;
45
+ - relations, both `defineRelations` and the older `relations()`: one over a
46
+ foreign key names it; one with no foreign key is an `inactive` ref (a link
47
+ the app relies on that the database doesn't enforce); a many-to-many through
48
+ a junction table is a `<>` ref;
49
+ - views and materialized views, as tables set apart with lineage (`Dep`) from
50
+ every table they read;
51
+ - row-level security and policies, sequences and roles.
52
+
53
+ **From a live Postgres database**, read from its own catalogs, so it draws
54
+ what is actually there whatever made it: all of the above that a database
55
+ holds, plus comments as notes, partitioned tables, deferrable keys, exclusion
56
+ constraints and included index columns, and optionally each table's first
57
+ rows as `Records`. It only reads, through the query function you give it, so
58
+ run it in a read-only transaction.
59
+
60
+ Anything DBML has no syntax for is said in a note rather than dropped. Every
61
+ construct is tested by printing it and reading it back with the official DBML
62
+ parser.
63
+
64
+ ## The model
65
+
66
+ `fromDrizzle` and `fromPostgres` both return a `DbmlModel`: plain data
67
+ (tables, columns, indexes, refs, enums, deps, groups, notes, records) that
68
+ `printDbml` writes as DBML. Anything that draws a diagram can read the model
69
+ directly instead of parsing the text back.
70
+
71
+ ## License
72
+
73
+ MIT
package/changelog.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "contract": 1,
3
+ "name": "@absolutejs/dbml",
4
+ "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "detail": "fromDrizzle reads a Drizzle 1.0 schema in any of its dialects (PostgreSQL, MySQL, SQLite, SingleStore, SQL Server, CockroachDB): tables, enums (named and inline), every column type and array, identity, serial and generated columns, defaults, composite and named keys, unique constraints, indexes with their order, method, expressions and predicates, checks, foreign keys with their actions, row-level security and policies, views and materialized views with lineage, sequences and roles, and both styles of relations, with app-only relations as inactive refs and many-to-many ones as <> refs. fromPostgres reads the same from a live database's catalogs, whatever made it, with comments as notes and optionally its first rows as Records. printDbml writes either as DBML, and every construct is tested against the official DBML parser. The absolute-dbml command does both from a terminal.",
9
+ "kind": "added",
10
+ "summary": "Turn a Drizzle schema, or a live Postgres database, into DBML"
11
+ }
12
+ ],
13
+ "date": "2026-11-19",
14
+ "version": "0.1.0"
15
+ }
16
+ ]
17
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export declare const USAGE = "Usage:\n absolute-dbml <schema.ts> [options] a Drizzle schema module\n absolute-dbml --postgres <url> [options] a live Postgres database\n\nOptions:\n -o, --output <file> write to a file instead of standard output\n --json print the model as JSON instead of DBML\n --name <name> the project's name\n --groups schema group tables by schema\n --relations <name> the schema module's defineRelations export\n --schema <name> a schema to read (repeatable; Postgres only)\n --records <n> each table's first n rows as Records (Postgres only)\n -h, --help show this help\n";