@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 +14 -0
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/changelog.json +17 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1660 -0
- package/dist/drizzle/dialects.d.ts +121 -0
- package/dist/drizzle/index.d.ts +21 -0
- package/dist/drizzle/index.js +759 -0
- package/dist/drizzle/relations.d.ts +40 -0
- package/dist/drizzle/tables.d.ts +10 -0
- package/dist/drizzle/views.d.ts +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +173 -0
- package/dist/model.d.ts +158 -0
- package/dist/postgres/index.d.ts +35 -0
- package/dist/postgres/index.js +666 -0
- package/dist/postgres/queries.d.ts +10 -0
- package/dist/postgres/rows.d.ts +91 -0
- package/dist/print.d.ts +11 -0
- package/package.json +89 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Column, type Relation } from 'drizzle-orm';
|
|
2
|
+
import { Relations } from 'drizzle-orm/_relations';
|
|
3
|
+
import type { DbmlEndpoint, DbmlRef } from '../model';
|
|
4
|
+
/** Where a table object sits: its schema and name, as the model has them. */
|
|
5
|
+
export type TableLookup = (table: object) => {
|
|
6
|
+
schema?: string;
|
|
7
|
+
table: string;
|
|
8
|
+
} | undefined;
|
|
9
|
+
/** A relation as both styles reduce to it. */
|
|
10
|
+
export type RelationLink = {
|
|
11
|
+
field: string;
|
|
12
|
+
from: readonly Column[];
|
|
13
|
+
kind: 'many-through' | 'one';
|
|
14
|
+
owner: object;
|
|
15
|
+
through?: object;
|
|
16
|
+
target: readonly Column[];
|
|
17
|
+
};
|
|
18
|
+
type RelationsV2 = Record<string, {
|
|
19
|
+
relations: Record<string, Relation>;
|
|
20
|
+
}>;
|
|
21
|
+
/** Whether a value is what `defineRelations` returns. */
|
|
22
|
+
export declare const isRelationsV2: (value: unknown) => value is RelationsV2;
|
|
23
|
+
export declare const linksFromV2: (relations: RelationsV2) => RelationLink[];
|
|
24
|
+
/** Whether a schema export is an older `relations(table, ...)` value. */
|
|
25
|
+
export declare const isRelationsV1: (value: unknown) => value is Relations;
|
|
26
|
+
export declare const linksFromV1: (relations: Relations) => RelationLink[];
|
|
27
|
+
/** A ref's identity whichever way round it was written. */
|
|
28
|
+
export declare const refKey: (ref: Pick<DbmlRef, "from" | "to">) => string;
|
|
29
|
+
type Applying = {
|
|
30
|
+
isUnique: (end: DbmlEndpoint) => boolean;
|
|
31
|
+
links: RelationLink[];
|
|
32
|
+
lookup: TableLookup;
|
|
33
|
+
refs: DbmlRef[];
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Adds relations to the refs the foreign keys made: names the ones they
|
|
37
|
+
* match, and adds the rest as inactive refs (or `<>` for many-to-many).
|
|
38
|
+
*/
|
|
39
|
+
export declare const applyRelations: (options: Applying) => void;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DbmlEnum, DbmlTable } from '../model';
|
|
2
|
+
import { type TableConfig } from './dialects';
|
|
3
|
+
/** One table, and the enums its columns use. */
|
|
4
|
+
export declare const tableOf: (config: TableConfig) => {
|
|
5
|
+
enums: DbmlEnum[];
|
|
6
|
+
table: DbmlTable;
|
|
7
|
+
};
|
|
8
|
+
/** Whether these columns alone are unique in the table: a one-to-one
|
|
9
|
+
* link rather than many-to-one when they're what a foreign key holds. */
|
|
10
|
+
export declare const isUniqueSet: (table: DbmlTable, columns: string[]) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DbmlTable } from '../model';
|
|
2
|
+
import { type ViewConfig } from './dialects';
|
|
3
|
+
/** The header colour views are drawn with, to set them apart. */
|
|
4
|
+
export declare const VIEW_COLOR = "#64748b";
|
|
5
|
+
/** Every table and view a query reads, found by walking it: a view's own
|
|
6
|
+
* record of what it uses leaves out the tables it joins. */
|
|
7
|
+
export declare const sourcesOf: (fragment: unknown) => Set<object>;
|
|
8
|
+
/** A table the view reads, with its columns' names. */
|
|
9
|
+
export type ViewSource = {
|
|
10
|
+
columns: string[];
|
|
11
|
+
table: string;
|
|
12
|
+
};
|
|
13
|
+
export declare const viewOf: (config: ViewConfig, materialized: boolean, sources: ViewSource[]) => DbmlTable;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/model.ts
|
|
3
|
+
var emptyModel = (project) => ({
|
|
4
|
+
deps: [],
|
|
5
|
+
enums: [],
|
|
6
|
+
notes: [],
|
|
7
|
+
...project ? { project } : {},
|
|
8
|
+
records: [],
|
|
9
|
+
refs: [],
|
|
10
|
+
tableGroups: [],
|
|
11
|
+
tables: []
|
|
12
|
+
});
|
|
13
|
+
// src/print.ts
|
|
14
|
+
var INDENT = " ";
|
|
15
|
+
var quoteName = (name) => `"${name.replaceAll("\\", "\\\\").replaceAll('"', "\\\"")}"`;
|
|
16
|
+
var qualified = (schema, name) => schema ? `${quoteName(schema)}.${quoteName(name)}` : quoteName(name);
|
|
17
|
+
var quoteText = (text) => {
|
|
18
|
+
const escaped = text.replaceAll("\\", "\\\\").replaceAll(`\r
|
|
19
|
+
`, `
|
|
20
|
+
`);
|
|
21
|
+
if (/[\n']/u.test(escaped))
|
|
22
|
+
return `'''${escaped.replaceAll("'''", "\\'''")}'''`;
|
|
23
|
+
return `'${escaped}'`;
|
|
24
|
+
};
|
|
25
|
+
var quoteExpression = (expression) => `\`${expression.replaceAll("`", '"')}\``;
|
|
26
|
+
var BARE_TYPE = /^[A-Za-z_][\w]*(\([\w,]*\))?$/u;
|
|
27
|
+
var printType = (column) => {
|
|
28
|
+
const type = BARE_TYPE.test(column.type) ? column.type : quoteName(column.type);
|
|
29
|
+
return column.typeSchema ? `${quoteName(column.typeSchema)}.${type}` : type;
|
|
30
|
+
};
|
|
31
|
+
var printDefault = (value) => {
|
|
32
|
+
if (value.kind === "null")
|
|
33
|
+
return "null";
|
|
34
|
+
if (value.kind === "boolean")
|
|
35
|
+
return `${value.value}`;
|
|
36
|
+
if (value.kind === "number")
|
|
37
|
+
return `${value.value}`;
|
|
38
|
+
if (value.kind === "string")
|
|
39
|
+
return quoteText(value.value);
|
|
40
|
+
return quoteExpression(value.value);
|
|
41
|
+
};
|
|
42
|
+
var settings = (entries) => {
|
|
43
|
+
const present = entries.filter((entry) => typeof entry === "string");
|
|
44
|
+
return present.length > 0 ? ` [${present.join(", ")}]` : "";
|
|
45
|
+
};
|
|
46
|
+
var printColumn = (column) => `${quoteName(column.name)} ${printType(column)}${settings([
|
|
47
|
+
column.pk && "pk",
|
|
48
|
+
column.increment && "increment",
|
|
49
|
+
column.unique && "unique",
|
|
50
|
+
column.notNull && "not null",
|
|
51
|
+
column.default && `default: ${printDefault(column.default)}`,
|
|
52
|
+
...(column.checks ?? []).map((check) => `check: ${quoteExpression(check)}`),
|
|
53
|
+
column.note !== undefined && `note: ${quoteText(column.note)}`
|
|
54
|
+
])}`;
|
|
55
|
+
var printIndexPart = (part) => {
|
|
56
|
+
const target = part.kind === "column" ? quoteName(part.column) : quoteExpression(part.expression);
|
|
57
|
+
return part.desc ? `${target} [desc]` : target;
|
|
58
|
+
};
|
|
59
|
+
var printIndex = (index) => {
|
|
60
|
+
const parts = index.parts.map(printIndexPart);
|
|
61
|
+
const grouped = parts.length === 1 && !index.parts[0]?.desc ? parts[0] ?? "" : `(${parts.join(", ")})`;
|
|
62
|
+
return `${grouped}${settings([
|
|
63
|
+
index.pk && "pk",
|
|
64
|
+
index.unique && "unique",
|
|
65
|
+
index.type !== undefined && `type: ${index.type}`,
|
|
66
|
+
index.name !== undefined && `name: ${quoteName(index.name)}`,
|
|
67
|
+
index.note !== undefined && `note: ${quoteText(index.note)}`
|
|
68
|
+
])}`;
|
|
69
|
+
};
|
|
70
|
+
var printCheck = (check) => `${quoteExpression(check.expression)}${settings([
|
|
71
|
+
check.name !== undefined && `name: ${quoteText(check.name)}`
|
|
72
|
+
])}`;
|
|
73
|
+
var block = (title, lines, depth = 1) => {
|
|
74
|
+
const pad = INDENT.repeat(depth);
|
|
75
|
+
return `${INDENT.repeat(depth - 1)}${title} {
|
|
76
|
+
${lines.map((line) => `${pad}${line}`).join(`
|
|
77
|
+
`)}
|
|
78
|
+
${INDENT.repeat(depth - 1)}}`;
|
|
79
|
+
};
|
|
80
|
+
var printTable = (table) => {
|
|
81
|
+
const head = `Table ${qualified(table.schema, table.name)}${table.alias ? ` as ${quoteName(table.alias)}` : ""}${settings([
|
|
82
|
+
table.headerColor !== undefined && `headerColor: ${table.headerColor}`
|
|
83
|
+
])}`;
|
|
84
|
+
const body = table.columns.map(printColumn);
|
|
85
|
+
const sections = [];
|
|
86
|
+
if (table.checks.length > 0)
|
|
87
|
+
sections.push(block("Checks", table.checks.map(printCheck), 2));
|
|
88
|
+
if (table.indexes.length > 0)
|
|
89
|
+
sections.push(block("Indexes", table.indexes.map(printIndex), 2));
|
|
90
|
+
if (table.note !== undefined)
|
|
91
|
+
sections.push(`${INDENT}Note: ${quoteText(table.note)}`);
|
|
92
|
+
const lines = body.map((line) => `${INDENT}${line}`);
|
|
93
|
+
return `${head} {
|
|
94
|
+
${[lines.join(`
|
|
95
|
+
`), ...sections].join(`
|
|
96
|
+
|
|
97
|
+
`)}
|
|
98
|
+
}`;
|
|
99
|
+
};
|
|
100
|
+
var printEnum = (entry) => block(`Enum ${qualified(entry.schema, entry.name)}`, entry.values.map((value) => `${quoteName(value.name)}${settings([
|
|
101
|
+
value.note !== undefined && `note: ${quoteText(value.note)}`
|
|
102
|
+
])}`));
|
|
103
|
+
var printEndpoint = (endpoint) => {
|
|
104
|
+
const columns = endpoint.columns.length === 1 ? quoteName(endpoint.columns[0] ?? "") : `(${endpoint.columns.map(quoteName).join(", ")})`;
|
|
105
|
+
return `${qualified(endpoint.schema, endpoint.table)}.${columns}`;
|
|
106
|
+
};
|
|
107
|
+
var printRef = (ref) => `Ref${ref.name === undefined ? "" : ` ${quoteName(ref.name)}`}: ${printEndpoint(ref.from)} ${ref.relation} ${printEndpoint(ref.to)}${settings([
|
|
108
|
+
ref.onDelete !== undefined && `delete: ${ref.onDelete}`,
|
|
109
|
+
ref.onUpdate !== undefined && `update: ${ref.onUpdate}`,
|
|
110
|
+
ref.color !== undefined && `color: ${ref.color}`,
|
|
111
|
+
ref.inactive && "inactive",
|
|
112
|
+
ref.note !== undefined && `note: ${quoteText(ref.note)}`
|
|
113
|
+
])}`;
|
|
114
|
+
var printDepEnd = (end) => {
|
|
115
|
+
const table = qualified(end.schema, end.table);
|
|
116
|
+
if (!end.columns || end.columns.length === 0)
|
|
117
|
+
return table;
|
|
118
|
+
return `${table}.${end.columns.length === 1 ? quoteName(end.columns[0] ?? "") : `(${end.columns.map(quoteName).join(", ")})`}`;
|
|
119
|
+
};
|
|
120
|
+
var printDep = (dep) => {
|
|
121
|
+
const edge = `${printDepEnd(dep.upstream)} -> ${printDepEnd(dep.downstream)}`;
|
|
122
|
+
if (dep.note === undefined)
|
|
123
|
+
return `Dep: ${edge}`;
|
|
124
|
+
return block("Dep", [edge, "", `note: ${quoteText(dep.note)}`]);
|
|
125
|
+
};
|
|
126
|
+
var printGroup = (group) => block(`TableGroup ${quoteName(group.name)}${settings([
|
|
127
|
+
group.color !== undefined && `color: ${group.color}`
|
|
128
|
+
])}`, [
|
|
129
|
+
...group.tables.map((entry) => qualified(entry.schema, entry.table)),
|
|
130
|
+
...group.note === undefined ? [] : [`Note: ${quoteText(group.note)}`]
|
|
131
|
+
]);
|
|
132
|
+
var printNote = (note) => block(`Note ${quoteName(note.name)}${settings([
|
|
133
|
+
note.color !== undefined && `color: ${note.color}`
|
|
134
|
+
])}`, [quoteText(note.content)]);
|
|
135
|
+
var printValue = (value) => {
|
|
136
|
+
if (value === null)
|
|
137
|
+
return "null";
|
|
138
|
+
if (typeof value === "boolean" || typeof value === "number")
|
|
139
|
+
return `${value}`;
|
|
140
|
+
return quoteText(value);
|
|
141
|
+
};
|
|
142
|
+
var printRecords = (records) => block(`Records ${qualified(records.schema, records.table)}(${records.columns.map(quoteName).join(", ")})`, records.rows.map((row) => row.map(printValue).join(", ")));
|
|
143
|
+
var printProject = (project) => block(`Project${project.name ? ` ${quoteName(project.name)}` : ""}`, [
|
|
144
|
+
...project.databaseType === undefined ? [] : [`database_type: ${quoteText(project.databaseType)}`],
|
|
145
|
+
...project.note === undefined ? [] : [`Note: ${quoteText(project.note)}`]
|
|
146
|
+
]);
|
|
147
|
+
var printDbml = (model) => {
|
|
148
|
+
const { project } = model;
|
|
149
|
+
const hasProject = project !== undefined && (project.name !== undefined || project.databaseType !== undefined || project.note !== undefined);
|
|
150
|
+
const sections = [
|
|
151
|
+
...hasProject && project ? [printProject(project)] : [],
|
|
152
|
+
...model.enums.map(printEnum),
|
|
153
|
+
...model.tables.map(printTable),
|
|
154
|
+
...model.tableGroups.map(printGroup),
|
|
155
|
+
...model.refs.length > 0 ? [model.refs.map(printRef).join(`
|
|
156
|
+
`)] : [],
|
|
157
|
+
...model.deps.length > 0 ? [model.deps.map(printDep).join(`
|
|
158
|
+
`)] : [],
|
|
159
|
+
...model.notes.map(printNote),
|
|
160
|
+
...model.records.filter((records) => records.rows.length > 0).map(printRecords)
|
|
161
|
+
];
|
|
162
|
+
return `${sections.join(`
|
|
163
|
+
|
|
164
|
+
`)}
|
|
165
|
+
`;
|
|
166
|
+
};
|
|
167
|
+
export {
|
|
168
|
+
emptyModel,
|
|
169
|
+
printDbml,
|
|
170
|
+
quoteExpression,
|
|
171
|
+
quoteName,
|
|
172
|
+
quoteText
|
|
173
|
+
};
|
package/dist/model.d.ts
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/** The database the model describes, DBML's `Project`. */
|
|
2
|
+
export type DbmlProject = {
|
|
3
|
+
/** As DBML spells it: `PostgreSQL`, `MySQL`, `SQLite`... */
|
|
4
|
+
databaseType?: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
note?: string;
|
|
7
|
+
};
|
|
8
|
+
/** A table, a column list or a whole table group's colour, as `#rgb` or
|
|
9
|
+
* `#rrggbb`. */
|
|
10
|
+
export type DbmlColor = `#${string}`;
|
|
11
|
+
export type DbmlEnumValue = {
|
|
12
|
+
name: string;
|
|
13
|
+
note?: string;
|
|
14
|
+
};
|
|
15
|
+
export type DbmlEnum = {
|
|
16
|
+
name: string;
|
|
17
|
+
schema?: string;
|
|
18
|
+
values: DbmlEnumValue[];
|
|
19
|
+
};
|
|
20
|
+
/** A column's default as written in the database. A function or any SQL
|
|
21
|
+
* is an expression; the rest are literals. */
|
|
22
|
+
export type DbmlDefault = {
|
|
23
|
+
kind: 'boolean';
|
|
24
|
+
value: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'expression';
|
|
27
|
+
value: string;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'null';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'number';
|
|
32
|
+
value: number | string;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'string';
|
|
35
|
+
value: string;
|
|
36
|
+
};
|
|
37
|
+
export type DbmlColumn = {
|
|
38
|
+
/** Column-level checks, each a SQL expression. */
|
|
39
|
+
checks?: string[];
|
|
40
|
+
default?: DbmlDefault;
|
|
41
|
+
/** An identity, serial or auto-increment column. */
|
|
42
|
+
increment?: boolean;
|
|
43
|
+
name: string;
|
|
44
|
+
note?: string;
|
|
45
|
+
notNull?: boolean;
|
|
46
|
+
pk?: boolean;
|
|
47
|
+
/** The type as the database names it (`varchar(255)`, `text[]`), or an
|
|
48
|
+
* enum's name. */
|
|
49
|
+
type: string;
|
|
50
|
+
/** The schema of an enum type that lives outside the default one. */
|
|
51
|
+
typeSchema?: string;
|
|
52
|
+
unique?: boolean;
|
|
53
|
+
};
|
|
54
|
+
export type DbmlIndexPart = {
|
|
55
|
+
column: string;
|
|
56
|
+
desc?: boolean;
|
|
57
|
+
kind: 'column';
|
|
58
|
+
} | {
|
|
59
|
+
desc?: boolean;
|
|
60
|
+
expression: string;
|
|
61
|
+
kind: 'expression';
|
|
62
|
+
};
|
|
63
|
+
export type DbmlIndex = {
|
|
64
|
+
name?: string;
|
|
65
|
+
note?: string;
|
|
66
|
+
parts: DbmlIndexPart[];
|
|
67
|
+
/** A primary key over these parts (how DBML writes a composite one). */
|
|
68
|
+
pk?: boolean;
|
|
69
|
+
/** The access method: `btree`, `hash`, `gin`, `gist`... */
|
|
70
|
+
type?: string;
|
|
71
|
+
unique?: boolean;
|
|
72
|
+
};
|
|
73
|
+
export type DbmlCheck = {
|
|
74
|
+
expression: string;
|
|
75
|
+
name?: string;
|
|
76
|
+
};
|
|
77
|
+
export type DbmlTable = {
|
|
78
|
+
alias?: string;
|
|
79
|
+
checks: DbmlCheck[];
|
|
80
|
+
columns: DbmlColumn[];
|
|
81
|
+
headerColor?: DbmlColor;
|
|
82
|
+
indexes: DbmlIndex[];
|
|
83
|
+
name: string;
|
|
84
|
+
note?: string;
|
|
85
|
+
schema?: string;
|
|
86
|
+
};
|
|
87
|
+
export type DbmlEndpoint = {
|
|
88
|
+
columns: string[];
|
|
89
|
+
schema?: string;
|
|
90
|
+
table: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* How many rows on each side: `>` many-to-one (from many to one), `<`
|
|
94
|
+
* one-to-many, `-` one-to-one, `<>` many-to-many.
|
|
95
|
+
*/
|
|
96
|
+
export type DbmlRelation = '-' | '<' | '<>' | '>';
|
|
97
|
+
export type DbmlReferentialAction = 'cascade' | 'no action' | 'restrict' | 'set default' | 'set null';
|
|
98
|
+
export type DbmlRef = {
|
|
99
|
+
color?: DbmlColor;
|
|
100
|
+
from: DbmlEndpoint;
|
|
101
|
+
/** A link the app relies on that no foreign key enforces. */
|
|
102
|
+
inactive?: boolean;
|
|
103
|
+
name?: string;
|
|
104
|
+
note?: string;
|
|
105
|
+
onDelete?: DbmlReferentialAction;
|
|
106
|
+
onUpdate?: DbmlReferentialAction;
|
|
107
|
+
relation: DbmlRelation;
|
|
108
|
+
to: DbmlEndpoint;
|
|
109
|
+
};
|
|
110
|
+
/** Lineage: `downstream` is made from `upstream` (a view from its tables). */
|
|
111
|
+
export type DbmlDep = {
|
|
112
|
+
downstream: {
|
|
113
|
+
columns?: string[];
|
|
114
|
+
schema?: string;
|
|
115
|
+
table: string;
|
|
116
|
+
};
|
|
117
|
+
note?: string;
|
|
118
|
+
upstream: {
|
|
119
|
+
columns?: string[];
|
|
120
|
+
schema?: string;
|
|
121
|
+
table: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export type DbmlTableGroup = {
|
|
125
|
+
color?: DbmlColor;
|
|
126
|
+
name: string;
|
|
127
|
+
note?: string;
|
|
128
|
+
tables: {
|
|
129
|
+
schema?: string;
|
|
130
|
+
table: string;
|
|
131
|
+
}[];
|
|
132
|
+
};
|
|
133
|
+
export type DbmlStickyNote = {
|
|
134
|
+
color?: DbmlColor;
|
|
135
|
+
content: string;
|
|
136
|
+
name: string;
|
|
137
|
+
};
|
|
138
|
+
/** A value in a `Records` block: text, a number, true or false, or null. */
|
|
139
|
+
export type DbmlRecordValue = boolean | number | string | null;
|
|
140
|
+
/** Rows of a table, DBML's `Records`: sample data shown with the table. */
|
|
141
|
+
export type DbmlRecords = {
|
|
142
|
+
columns: string[];
|
|
143
|
+
rows: DbmlRecordValue[][];
|
|
144
|
+
schema?: string;
|
|
145
|
+
table: string;
|
|
146
|
+
};
|
|
147
|
+
export type DbmlModel = {
|
|
148
|
+
deps: DbmlDep[];
|
|
149
|
+
enums: DbmlEnum[];
|
|
150
|
+
notes: DbmlStickyNote[];
|
|
151
|
+
project?: DbmlProject;
|
|
152
|
+
records: DbmlRecords[];
|
|
153
|
+
refs: DbmlRef[];
|
|
154
|
+
tableGroups: DbmlTableGroup[];
|
|
155
|
+
tables: DbmlTable[];
|
|
156
|
+
};
|
|
157
|
+
/** A model with nothing in it, to build on. */
|
|
158
|
+
export declare const emptyModel: (project?: DbmlProject) => DbmlModel;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type DbmlModel } from '../model';
|
|
2
|
+
/** Runs one query with positional parameters and returns its rows. */
|
|
3
|
+
export type PostgresQuery = (text: string, params: unknown[]) => Promise<Record<string, unknown>[]>;
|
|
4
|
+
export type FromPostgresOptions = {
|
|
5
|
+
/** Each table's first rows as DBML `Records`, read with the same query. */
|
|
6
|
+
records?: {
|
|
7
|
+
limit: number;
|
|
8
|
+
};
|
|
9
|
+
project?: {
|
|
10
|
+
name?: string;
|
|
11
|
+
note?: string;
|
|
12
|
+
};
|
|
13
|
+
/** The schemas to read; every schema that isn't Postgres's own by
|
|
14
|
+
* default. */
|
|
15
|
+
schemas?: string[];
|
|
16
|
+
};
|
|
17
|
+
/** A default as Postgres writes it, as a literal when it is one. */
|
|
18
|
+
export declare const parseDefault: (expression: string) => {
|
|
19
|
+
kind: "expression";
|
|
20
|
+
value: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "number";
|
|
23
|
+
value: number | string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "string";
|
|
26
|
+
value: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: "null";
|
|
29
|
+
value?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "boolean";
|
|
32
|
+
value: boolean;
|
|
33
|
+
};
|
|
34
|
+
/** The database's structure as a DBML model. */
|
|
35
|
+
export declare const fromPostgres: (query: PostgresQuery, options?: FromPostgresOptions) => Promise<DbmlModel>;
|