@absolutejs/dbml 0.1.0 → 0.3.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 +20 -0
- package/README.md +45 -7
- package/changelog.json +59 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1313 -129
- package/dist/drizzle/index.js +96 -8
- package/dist/drizzle/relations.d.ts +1 -0
- package/dist/index.js +105 -10
- package/dist/model.d.ts +16 -0
- package/dist/mysql/index.d.ts +20 -0
- package/dist/mysql/index.js +452 -0
- package/dist/postgres/details.d.ts +40 -0
- package/dist/postgres/index.d.ts +8 -0
- package/dist/postgres/index.js +413 -34
- package/dist/postgres/queries.d.ts +13 -4
- package/dist/postgres/rows.d.ts +66 -0
- package/dist/sqlite/index.d.ts +14 -0
- package/dist/sqlite/index.js +420 -0
- package/dist/sqlite/text.d.ts +22 -0
- package/package.json +16 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,26 @@ This file is generated by `absolute-changelog` from the entries in
|
|
|
6
6
|
`changelog/`. Edit an entry, not this file — and add new ones under
|
|
7
7
|
`changelog/unreleased/`.
|
|
8
8
|
|
|
9
|
+
## 0.3.0 — 2026-11-19
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- **Drizzle: filtered relations, and many relations with their own keys**
|
|
14
|
+
A Drizzle 1.0 relation with a `where` filter says its filter in the reference’s note, and a many declared with its own from and to becomes a link from the key to the one side, as a foreign key would be.
|
|
15
|
+
- **Metadata blocks for tables and columns** (`DbmlColumn`, `DbmlTable`, `DbmlMetadata`, `groupBySchema`, `isUniqueSet`)
|
|
16
|
+
Tables and columns take `metadata`, a record of string, number and boolean facts, printed as DBML `Metadata Table` and `Metadata Column` blocks. A view dependency over several columns prints as one edge per column. groupBySchema and isUniqueSet are shared by every reader.
|
|
17
|
+
- **Live MySQL, MariaDB and SQLite databases** (`fromMysql`, `FromMysqlOptions`, `MysqlQuery`, `fromSqlite`, `FromSqliteOptions`, `SqliteQuery`)
|
|
18
|
+
`@absolutejs/dbml/mysql` reads a live MySQL or MariaDB database from information_schema: exact column types, enums and sets, defaults, generated and invisible columns, prefix, expression and invisible indexes, checks, foreign keys, partitions, triggers, views with the tables they read, routines, scheduled events, and each table’s engine, collation and grants. `@absolutejs/dbml/sqlite` reads a SQLite database from its pragmas and CREATE statements: the row id key and AUTOINCREMENT, collations, generated columns, checks, expression and partial indexes, strict and WITHOUT ROWID tables, views and triggers. The CLI takes `--mysql <url>`, `--sqlite <file>` and `--statistics`, and only reads.
|
|
19
|
+
- **Postgres: triggers, rules, functions, domains, extensions, partitions, grants and more** (`FromPostgresOptions`)
|
|
20
|
+
fromPostgres now reads what a database holds beyond tables, keys and indexes. On tables: owner, grants, unlogged, storage options, a foreign table’s server and options, and inheritance as metadata; triggers, rules and each partition with its bounds as lines of the note. On columns: collation, compression, the domain a column is of, and an identity sequence that doesn’t start at one. On indexes: nulls ordering, operator classes, collations and NULLS NOT DISTINCT. Functions and procedures, domains, composite types, extensions and event triggers come as sticky notes, a view’s lineage names the columns it reads, and anything an extension installed stays out. `statistics: true` adds estimated rows and size; `groups: 'schema'` groups tables by schema.
|
|
21
|
+
|
|
22
|
+
## 0.2.0 — 2026-11-19
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
- **Name the app’s own schema without qualifying every table** (`FromPostgresOptions`, `withDefaultSchema`)
|
|
27
|
+
fromPostgres takes a `defaultSchema`: the schema whose tables, enums and references are named without it, the way a query run there names them (`public` by default). An app whose tables live in their own schema now reads `"orders"` rather than `"app_schema"."orders"` on every table, while tables in any other schema, `public` included, keep their schema so two schemas never look alike. withDefaultSchema(model, schema) does the same to any model.
|
|
28
|
+
|
|
9
29
|
## 0.1.0 — 2026-11-19
|
|
10
30
|
|
|
11
31
|
### Added
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @absolutejs/dbml
|
|
2
2
|
|
|
3
|
-
Turn any Drizzle schema, or a live Postgres
|
|
3
|
+
Turn any Drizzle schema, or a live Postgres, MySQL, MariaDB or SQLite
|
|
4
|
+
database, into
|
|
4
5
|
[DBML](https://dbml.dbdiagram.io/docs/), so it can be drawn as a diagram,
|
|
5
6
|
read in a review, or kept next to the code.
|
|
6
7
|
|
|
@@ -16,7 +17,22 @@ const dbml = printDbml(fromDrizzle(schema));
|
|
|
16
17
|
import { fromPostgres } from '@absolutejs/dbml/postgres';
|
|
17
18
|
|
|
18
19
|
// Any driver: give it a function that runs one query with $1-style parameters.
|
|
19
|
-
const model = await fromPostgres((text, params) =>
|
|
20
|
+
const model = await fromPostgres((text, params) =>
|
|
21
|
+
client.query(text, params).then((result) => result.rows)
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { fromMysql } from '@absolutejs/dbml/mysql';
|
|
27
|
+
import { fromSqlite } from '@absolutejs/dbml/sqlite';
|
|
28
|
+
|
|
29
|
+
// ? placeholders for MySQL and MariaDB; bun:sqlite for SQLite.
|
|
30
|
+
const fromServer = await fromMysql((text, params) =>
|
|
31
|
+
connection.unsafe(text, params)
|
|
32
|
+
);
|
|
33
|
+
const fromFile = await fromSqlite((text, params) =>
|
|
34
|
+
database.query(text).all(...params)
|
|
35
|
+
);
|
|
20
36
|
```
|
|
21
37
|
|
|
22
38
|
Or from a terminal:
|
|
@@ -24,6 +40,8 @@ Or from a terminal:
|
|
|
24
40
|
```sh
|
|
25
41
|
bunx @absolutejs/dbml src/db/schema.ts -o schema.dbml
|
|
26
42
|
bunx @absolutejs/dbml --postgres "$DATABASE_URL" --records 5
|
|
43
|
+
bunx @absolutejs/dbml --mysql "$MYSQL_URL" --statistics
|
|
44
|
+
bunx @absolutejs/dbml --sqlite app.db
|
|
27
45
|
```
|
|
28
46
|
|
|
29
47
|
## What it covers
|
|
@@ -52,10 +70,30 @@ SQLite, SingleStore, SQL Server, CockroachDB):
|
|
|
52
70
|
|
|
53
71
|
**From a live Postgres database**, read from its own catalogs, so it draws
|
|
54
72
|
what is actually there whatever made it: all of the above that a database
|
|
55
|
-
holds, plus comments as notes, partitioned tables
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
73
|
+
holds, plus comments as notes, partitioned tables with each partition's
|
|
74
|
+
bounds, inheritance, deferrable keys, exclusion constraints and included
|
|
75
|
+
index columns; triggers and rules; owners, grants, storage options and
|
|
76
|
+
foreign tables; collations, compression, domains and identity sequences on
|
|
77
|
+
columns; nulls ordering, operator classes and NULLS NOT DISTINCT on indexes;
|
|
78
|
+
functions, procedures, domains, composite types, extensions and event
|
|
79
|
+
triggers as sticky notes; column-level view lineage; and optionally row
|
|
80
|
+
estimates and sizes (`statistics`) and each table's first rows as `Records`.
|
|
81
|
+
What an extension installed is left out.
|
|
82
|
+
|
|
83
|
+
**From a live MySQL or MariaDB database**, read from `information_schema`:
|
|
84
|
+
exact column types, enums and sets, defaults, generated and invisible
|
|
85
|
+
columns, prefix, expression and invisible indexes, checks, foreign keys,
|
|
86
|
+
partitions, triggers, views with the tables they read, routines, scheduled
|
|
87
|
+
events, and each table's engine, collation and grants.
|
|
88
|
+
|
|
89
|
+
**From a SQLite database**, read from its pragmas and each table's own
|
|
90
|
+
`CREATE` statement: the row id key and `AUTOINCREMENT`, collations,
|
|
91
|
+
generated columns, checks, expression and partial indexes, strict and
|
|
92
|
+
`WITHOUT ROWID` tables, views and triggers.
|
|
93
|
+
|
|
94
|
+
Every reader only reads, through the query function you give it, so run it
|
|
95
|
+
in a read-only transaction; the CLI does that for you. Facts DBML holds as
|
|
96
|
+
data (an owner, a collation, an engine) are written as `Metadata` blocks.
|
|
59
97
|
|
|
60
98
|
Anything DBML has no syntax for is said in a note rather than dropped. Every
|
|
61
99
|
construct is tested by printing it and reading it back with the official DBML
|
|
@@ -63,7 +101,7 @@ parser.
|
|
|
63
101
|
|
|
64
102
|
## The model
|
|
65
103
|
|
|
66
|
-
|
|
104
|
+
Every reader returns a `DbmlModel`: plain data
|
|
67
105
|
(tables, columns, indexes, refs, enums, deps, groups, notes, records) that
|
|
68
106
|
`printDbml` writes as DBML. Anything that draws a diagram can read the model
|
|
69
107
|
directly instead of parsing the text back.
|
package/changelog.json
CHANGED
|
@@ -2,6 +2,65 @@
|
|
|
2
2
|
"contract": 1,
|
|
3
3
|
"name": "@absolutejs/dbml",
|
|
4
4
|
"releases": [
|
|
5
|
+
{
|
|
6
|
+
"changes": [
|
|
7
|
+
{
|
|
8
|
+
"detail": "A Drizzle 1.0 relation with a `where` filter says its filter in the reference’s note, and a many declared with its own from and to becomes a link from the key to the one side, as a foreign key would be.",
|
|
9
|
+
"kind": "added",
|
|
10
|
+
"summary": "Drizzle: filtered relations, and many relations with their own keys"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"detail": "Tables and columns take `metadata`, a record of string, number and boolean facts, printed as DBML `Metadata Table` and `Metadata Column` blocks. A view dependency over several columns prints as one edge per column. groupBySchema and isUniqueSet are shared by every reader.",
|
|
14
|
+
"kind": "added",
|
|
15
|
+
"summary": "Metadata blocks for tables and columns",
|
|
16
|
+
"symbols": [
|
|
17
|
+
"DbmlColumn",
|
|
18
|
+
"DbmlTable",
|
|
19
|
+
"DbmlMetadata",
|
|
20
|
+
"groupBySchema",
|
|
21
|
+
"isUniqueSet"
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"detail": "`@absolutejs/dbml/mysql` reads a live MySQL or MariaDB database from information_schema: exact column types, enums and sets, defaults, generated and invisible columns, prefix, expression and invisible indexes, checks, foreign keys, partitions, triggers, views with the tables they read, routines, scheduled events, and each table’s engine, collation and grants. `@absolutejs/dbml/sqlite` reads a SQLite database from its pragmas and CREATE statements: the row id key and AUTOINCREMENT, collations, generated columns, checks, expression and partial indexes, strict and WITHOUT ROWID tables, views and triggers. The CLI takes `--mysql <url>`, `--sqlite <file>` and `--statistics`, and only reads.",
|
|
26
|
+
"kind": "added",
|
|
27
|
+
"summary": "Live MySQL, MariaDB and SQLite databases",
|
|
28
|
+
"symbols": [
|
|
29
|
+
"fromMysql",
|
|
30
|
+
"FromMysqlOptions",
|
|
31
|
+
"MysqlQuery",
|
|
32
|
+
"fromSqlite",
|
|
33
|
+
"FromSqliteOptions",
|
|
34
|
+
"SqliteQuery"
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"detail": "fromPostgres now reads what a database holds beyond tables, keys and indexes. On tables: owner, grants, unlogged, storage options, a foreign table’s server and options, and inheritance as metadata; triggers, rules and each partition with its bounds as lines of the note. On columns: collation, compression, the domain a column is of, and an identity sequence that doesn’t start at one. On indexes: nulls ordering, operator classes, collations and NULLS NOT DISTINCT. Functions and procedures, domains, composite types, extensions and event triggers come as sticky notes, a view’s lineage names the columns it reads, and anything an extension installed stays out. `statistics: true` adds estimated rows and size; `groups: 'schema'` groups tables by schema.",
|
|
39
|
+
"kind": "added",
|
|
40
|
+
"summary": "Postgres: triggers, rules, functions, domains, extensions, partitions, grants and more",
|
|
41
|
+
"symbols": [
|
|
42
|
+
"FromPostgresOptions"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"date": "2026-11-19",
|
|
47
|
+
"version": "0.3.0"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"changes": [
|
|
51
|
+
{
|
|
52
|
+
"detail": "fromPostgres takes a `defaultSchema`: the schema whose tables, enums and references are named without it, the way a query run there names them (`public` by default). An app whose tables live in their own schema now reads `\"orders\"` rather than `\"app_schema\".\"orders\"` on every table, while tables in any other schema, `public` included, keep their schema so two schemas never look alike. withDefaultSchema(model, schema) does the same to any model.",
|
|
53
|
+
"kind": "added",
|
|
54
|
+
"summary": "Name the app’s own schema without qualifying every table",
|
|
55
|
+
"symbols": [
|
|
56
|
+
"FromPostgresOptions",
|
|
57
|
+
"withDefaultSchema"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"date": "2026-11-19",
|
|
62
|
+
"version": "0.2.0"
|
|
63
|
+
},
|
|
5
64
|
{
|
|
6
65
|
"changes": [
|
|
7
66
|
{
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
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
|
|
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 absolute-dbml --mysql <url> [options] a live MySQL or MariaDB database\n absolute-dbml --sqlite <file> [options] a SQLite database file\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 (or MySQL database) to read (repeatable)\n --records <n> each table's first n rows as Records (Postgres only)\n --statistics each table's row count and size, as metadata\n -h, --help show this help\n";
|