@absolutejs/dbml 0.1.0 → 0.2.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 CHANGED
@@ -6,6 +6,13 @@ 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.2.0 — 2026-11-19
10
+
11
+ ### Added
12
+
13
+ - **Name the app’s own schema without qualifying every table** (`FromPostgresOptions`, `withDefaultSchema`)
14
+ 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.
15
+
9
16
  ## 0.1.0 — 2026-11-19
10
17
 
11
18
  ### Added
package/changelog.json CHANGED
@@ -2,6 +2,21 @@
2
2
  "contract": 1,
3
3
  "name": "@absolutejs/dbml",
4
4
  "releases": [
5
+ {
6
+ "changes": [
7
+ {
8
+ "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.",
9
+ "kind": "added",
10
+ "summary": "Name the app’s own schema without qualifying every table",
11
+ "symbols": [
12
+ "FromPostgresOptions",
13
+ "withDefaultSchema"
14
+ ]
15
+ }
16
+ ],
17
+ "date": "2026-11-19",
18
+ "version": "0.2.0"
19
+ },
5
20
  {
6
21
  "changes": [
7
22
  {
package/dist/cli.js CHANGED
@@ -25,6 +25,43 @@ var emptyModel = (project) => ({
25
25
  tableGroups: [],
26
26
  tables: []
27
27
  });
28
+ var unqualified = (place, schema) => {
29
+ if (place.schema !== schema)
30
+ return place;
31
+ const { schema: dropped, ...rest } = place;
32
+ return rest;
33
+ };
34
+ var withDefaultSchema = (model, schema) => {
35
+ const result = {
36
+ ...model,
37
+ deps: model.deps.map((dep) => ({
38
+ ...dep,
39
+ downstream: unqualified(dep.downstream, schema),
40
+ upstream: unqualified(dep.upstream, schema)
41
+ })),
42
+ enums: model.enums.map((entry) => unqualified(entry, schema)),
43
+ records: model.records.map((records) => unqualified(records, schema)),
44
+ refs: model.refs.map((ref) => ({
45
+ ...ref,
46
+ from: unqualified(ref.from, schema),
47
+ to: unqualified(ref.to, schema)
48
+ })),
49
+ tableGroups: model.tableGroups.map((group) => ({
50
+ ...group,
51
+ tables: group.tables.map((entry) => unqualified(entry, schema))
52
+ })),
53
+ tables: model.tables.map((table) => ({
54
+ ...unqualified(table, schema),
55
+ columns: table.columns.map((column) => {
56
+ if (column.typeSchema !== schema)
57
+ return column;
58
+ const { typeSchema: dropped, ...rest } = column;
59
+ return rest;
60
+ })
61
+ }))
62
+ };
63
+ return result;
64
+ };
28
65
 
29
66
  // src/drizzle/dialects.ts
30
67
  import { is, SQL, sql } from "drizzle-orm";
@@ -1023,7 +1060,7 @@ var viewSourceRow = (row) => ({
1023
1060
 
1024
1061
  // src/postgres/index.ts
1025
1062
  var DEFAULT_SCHEMA = "public";
1026
- var inSchema2 = (schema) => schema === DEFAULT_SCHEMA ? {} : { schema };
1063
+ var inSchema2 = (schema) => ({ schema });
1027
1064
  var ACTIONS2 = {
1028
1065
  a: undefined,
1029
1066
  c: "cascade",
@@ -1107,7 +1144,7 @@ var generatedNote2 = (row) => {
1107
1144
  return `Generated always as (${row.default}), ${mode}`;
1108
1145
  };
1109
1146
  var isSerial = (row) => row.serialSequence !== undefined && row.default?.startsWith("nextval(") === true;
1110
- var enumSchema = (row) => row.enumType && row.enumSchema && row.enumSchema !== DEFAULT_SCHEMA ? { typeSchema: row.enumSchema } : {};
1147
+ var enumSchema = (row) => row.enumType && row.enumSchema ? { typeSchema: row.enumSchema } : {};
1111
1148
  var columnOf2 = (row) => {
1112
1149
  const serial = isSerial(row);
1113
1150
  const fallback = row.default !== undefined && !serial && !row.generated ? parseDefault(row.default) : undefined;
@@ -1315,9 +1352,9 @@ var applyConstraints = (rows, context) => rows.filter((row) => {
1315
1352
  });
1316
1353
  return false;
1317
1354
  });
1318
- var sequenceNote = (rows) => ({
1355
+ var sequenceNote = (rows, defaultSchema) => ({
1319
1356
  content: `Sequences
1320
- ${rows.map((row) => `${row.schema === DEFAULT_SCHEMA ? "" : `${row.schema}.`}${row.name}: start ${row.start}, increment ${row.increment}`).join(`
1357
+ ${rows.map((row) => `${row.schema === defaultSchema ? "" : `${row.schema}.`}${row.name}: start ${row.start}, increment ${row.increment}`).join(`
1321
1358
  `)}`,
1322
1359
  name: "sequences"
1323
1360
  });
@@ -1366,10 +1403,10 @@ var addDeps = (model, catalogs, relations) => catalogs.sources.forEach((row) =>
1366
1403
  upstream: { ...inSchema2(source.schema), table: source.name }
1367
1404
  });
1368
1405
  });
1369
- var addNotes2 = (model, catalogs) => {
1406
+ var addNotes2 = (model, catalogs, defaultSchema) => {
1370
1407
  if (catalogs.sequences.length > 0)
1371
- model.notes.push(sequenceNote(catalogs.sequences));
1372
- const described = catalogs.comments.filter((row) => row.comment !== undefined && row.name !== DEFAULT_SCHEMA);
1408
+ model.notes.push(sequenceNote(catalogs.sequences, defaultSchema));
1409
+ const described = catalogs.comments.filter((row) => row.comment !== undefined && row.name !== defaultSchema);
1373
1410
  if (described.length > 0)
1374
1411
  model.notes.push({
1375
1412
  content: `Schemas
@@ -1408,11 +1445,12 @@ var fromPostgres = async (query, options = {}) => {
1408
1445
  model.tables.push(...tables.values());
1409
1446
  model.refs.push(...foreign.map((row) => refOf(row, context)).filter((ref) => ref !== undefined));
1410
1447
  addDeps(model, catalogs, relations);
1411
- addNotes2(model, catalogs);
1448
+ const defaultSchema = options.defaultSchema ?? DEFAULT_SCHEMA;
1449
+ addNotes2(model, catalogs, defaultSchema);
1412
1450
  const limit = options.records?.limit ?? 0;
1413
1451
  if (limit > 0)
1414
1452
  model.records.push(...await readRecords(query, model.tables.filter((table) => !table.headerColor), limit));
1415
- return model;
1453
+ return withDefaultSchema(model, defaultSchema);
1416
1454
  };
1417
1455
 
1418
1456
  // src/print.ts
@@ -15,6 +15,43 @@ var emptyModel = (project) => ({
15
15
  tableGroups: [],
16
16
  tables: []
17
17
  });
18
+ var unqualified = (place, schema) => {
19
+ if (place.schema !== schema)
20
+ return place;
21
+ const { schema: dropped, ...rest } = place;
22
+ return rest;
23
+ };
24
+ var withDefaultSchema = (model, schema) => {
25
+ const result = {
26
+ ...model,
27
+ deps: model.deps.map((dep) => ({
28
+ ...dep,
29
+ downstream: unqualified(dep.downstream, schema),
30
+ upstream: unqualified(dep.upstream, schema)
31
+ })),
32
+ enums: model.enums.map((entry) => unqualified(entry, schema)),
33
+ records: model.records.map((records) => unqualified(records, schema)),
34
+ refs: model.refs.map((ref) => ({
35
+ ...ref,
36
+ from: unqualified(ref.from, schema),
37
+ to: unqualified(ref.to, schema)
38
+ })),
39
+ tableGroups: model.tableGroups.map((group) => ({
40
+ ...group,
41
+ tables: group.tables.map((entry) => unqualified(entry, schema))
42
+ })),
43
+ tables: model.tables.map((table) => ({
44
+ ...unqualified(table, schema),
45
+ columns: table.columns.map((column) => {
46
+ if (column.typeSchema !== schema)
47
+ return column;
48
+ const { typeSchema: dropped, ...rest } = column;
49
+ return rest;
50
+ })
51
+ }))
52
+ };
53
+ return result;
54
+ };
18
55
 
19
56
  // src/drizzle/dialects.ts
20
57
  import { is, SQL, sql } from "drizzle-orm";
package/dist/index.js CHANGED
@@ -10,6 +10,43 @@ var emptyModel = (project) => ({
10
10
  tableGroups: [],
11
11
  tables: []
12
12
  });
13
+ var unqualified = (place, schema) => {
14
+ if (place.schema !== schema)
15
+ return place;
16
+ const { schema: dropped, ...rest } = place;
17
+ return rest;
18
+ };
19
+ var withDefaultSchema = (model, schema) => {
20
+ const result = {
21
+ ...model,
22
+ deps: model.deps.map((dep) => ({
23
+ ...dep,
24
+ downstream: unqualified(dep.downstream, schema),
25
+ upstream: unqualified(dep.upstream, schema)
26
+ })),
27
+ enums: model.enums.map((entry) => unqualified(entry, schema)),
28
+ records: model.records.map((records) => unqualified(records, schema)),
29
+ refs: model.refs.map((ref) => ({
30
+ ...ref,
31
+ from: unqualified(ref.from, schema),
32
+ to: unqualified(ref.to, schema)
33
+ })),
34
+ tableGroups: model.tableGroups.map((group) => ({
35
+ ...group,
36
+ tables: group.tables.map((entry) => unqualified(entry, schema))
37
+ })),
38
+ tables: model.tables.map((table) => ({
39
+ ...unqualified(table, schema),
40
+ columns: table.columns.map((column) => {
41
+ if (column.typeSchema !== schema)
42
+ return column;
43
+ const { typeSchema: dropped, ...rest } = column;
44
+ return rest;
45
+ })
46
+ }))
47
+ };
48
+ return result;
49
+ };
13
50
  // src/print.ts
14
51
  var INDENT = " ";
15
52
  var quoteName = (name) => `"${name.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
@@ -169,5 +206,6 @@ export {
169
206
  printDbml,
170
207
  quoteExpression,
171
208
  quoteName,
172
- quoteText
209
+ quoteText,
210
+ withDefaultSchema
173
211
  };
package/dist/model.d.ts CHANGED
@@ -156,3 +156,9 @@ export type DbmlModel = {
156
156
  };
157
157
  /** A model with nothing in it, to build on. */
158
158
  export declare const emptyModel: (project?: DbmlProject) => DbmlModel;
159
+ /**
160
+ * The model as read from inside one schema: everything in `schema` loses
161
+ * its qualifier (`"orders"`, not `"app"."orders"`), the way a query run
162
+ * there would name it, and everything elsewhere keeps its own.
163
+ */
164
+ export declare const withDefaultSchema: (model: DbmlModel, schema: string) => DbmlModel;
@@ -10,6 +10,9 @@ export type FromPostgresOptions = {
10
10
  name?: string;
11
11
  note?: string;
12
12
  };
13
+ /** The schema whose tables are named without it, as a query run there
14
+ * names them: `public` unless the app keeps its tables elsewhere. */
15
+ defaultSchema?: string;
13
16
  /** The schemas to read; every schema that isn't Postgres's own by
14
17
  * default. */
15
18
  schemas?: string[];
@@ -13,6 +13,43 @@ var emptyModel = (project) => ({
13
13
  tableGroups: [],
14
14
  tables: []
15
15
  });
16
+ var unqualified = (place, schema) => {
17
+ if (place.schema !== schema)
18
+ return place;
19
+ const { schema: dropped, ...rest } = place;
20
+ return rest;
21
+ };
22
+ var withDefaultSchema = (model, schema) => {
23
+ const result = {
24
+ ...model,
25
+ deps: model.deps.map((dep) => ({
26
+ ...dep,
27
+ downstream: unqualified(dep.downstream, schema),
28
+ upstream: unqualified(dep.upstream, schema)
29
+ })),
30
+ enums: model.enums.map((entry) => unqualified(entry, schema)),
31
+ records: model.records.map((records) => unqualified(records, schema)),
32
+ refs: model.refs.map((ref) => ({
33
+ ...ref,
34
+ from: unqualified(ref.from, schema),
35
+ to: unqualified(ref.to, schema)
36
+ })),
37
+ tableGroups: model.tableGroups.map((group) => ({
38
+ ...group,
39
+ tables: group.tables.map((entry) => unqualified(entry, schema))
40
+ })),
41
+ tables: model.tables.map((table) => ({
42
+ ...unqualified(table, schema),
43
+ columns: table.columns.map((column) => {
44
+ if (column.typeSchema !== schema)
45
+ return column;
46
+ const { typeSchema: dropped, ...rest } = column;
47
+ return rest;
48
+ })
49
+ }))
50
+ };
51
+ return result;
52
+ };
16
53
 
17
54
  // src/postgres/queries.ts
18
55
  var SCHEMAS = `
@@ -269,7 +306,7 @@ var viewSourceRow = (row) => ({
269
306
 
270
307
  // src/postgres/index.ts
271
308
  var DEFAULT_SCHEMA = "public";
272
- var inSchema = (schema) => schema === DEFAULT_SCHEMA ? {} : { schema };
309
+ var inSchema = (schema) => ({ schema });
273
310
  var ACTIONS = {
274
311
  a: undefined,
275
312
  c: "cascade",
@@ -353,7 +390,7 @@ var generatedNote = (row) => {
353
390
  return `Generated always as (${row.default}), ${mode}`;
354
391
  };
355
392
  var isSerial = (row) => row.serialSequence !== undefined && row.default?.startsWith("nextval(") === true;
356
- var enumSchema = (row) => row.enumType && row.enumSchema && row.enumSchema !== DEFAULT_SCHEMA ? { typeSchema: row.enumSchema } : {};
393
+ var enumSchema = (row) => row.enumType && row.enumSchema ? { typeSchema: row.enumSchema } : {};
357
394
  var columnOf = (row) => {
358
395
  const serial = isSerial(row);
359
396
  const fallback = row.default !== undefined && !serial && !row.generated ? parseDefault(row.default) : undefined;
@@ -561,9 +598,9 @@ var applyConstraints = (rows, context) => rows.filter((row) => {
561
598
  });
562
599
  return false;
563
600
  });
564
- var sequenceNote = (rows) => ({
601
+ var sequenceNote = (rows, defaultSchema) => ({
565
602
  content: `Sequences
566
- ${rows.map((row) => `${row.schema === DEFAULT_SCHEMA ? "" : `${row.schema}.`}${row.name}: start ${row.start}, increment ${row.increment}`).join(`
603
+ ${rows.map((row) => `${row.schema === defaultSchema ? "" : `${row.schema}.`}${row.name}: start ${row.start}, increment ${row.increment}`).join(`
567
604
  `)}`,
568
605
  name: "sequences"
569
606
  });
@@ -612,10 +649,10 @@ var addDeps = (model, catalogs, relations) => catalogs.sources.forEach((row) =>
612
649
  upstream: { ...inSchema(source.schema), table: source.name }
613
650
  });
614
651
  });
615
- var addNotes = (model, catalogs) => {
652
+ var addNotes = (model, catalogs, defaultSchema) => {
616
653
  if (catalogs.sequences.length > 0)
617
- model.notes.push(sequenceNote(catalogs.sequences));
618
- const described = catalogs.comments.filter((row) => row.comment !== undefined && row.name !== DEFAULT_SCHEMA);
654
+ model.notes.push(sequenceNote(catalogs.sequences, defaultSchema));
655
+ const described = catalogs.comments.filter((row) => row.comment !== undefined && row.name !== defaultSchema);
619
656
  if (described.length > 0)
620
657
  model.notes.push({
621
658
  content: `Schemas
@@ -654,11 +691,12 @@ var fromPostgres = async (query, options = {}) => {
654
691
  model.tables.push(...tables.values());
655
692
  model.refs.push(...foreign.map((row) => refOf(row, context)).filter((ref) => ref !== undefined));
656
693
  addDeps(model, catalogs, relations);
657
- addNotes(model, catalogs);
694
+ const defaultSchema = options.defaultSchema ?? DEFAULT_SCHEMA;
695
+ addNotes(model, catalogs, defaultSchema);
658
696
  const limit = options.records?.limit ?? 0;
659
697
  if (limit > 0)
660
698
  model.records.push(...await readRecords(query, model.tables.filter((table) => !table.headerColor), limit));
661
- return model;
699
+ return withDefaultSchema(model, defaultSchema);
662
700
  };
663
701
  export {
664
702
  fromPostgres,
package/package.json CHANGED
@@ -86,5 +86,5 @@
86
86
  },
87
87
  "type": "module",
88
88
  "types": "./dist/index.d.ts",
89
- "version": "0.1.0"
89
+ "version": "0.2.0"
90
90
  }