@absolutejs/dbml 0.0.0-stage → 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 +21 -0
- package/LICENSE +21 -0
- package/README.md +72 -2
- package/changelog.json +32 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1698 -0
- package/dist/drizzle/dialects.d.ts +121 -0
- package/dist/drizzle/index.d.ts +21 -0
- package/dist/drizzle/index.js +796 -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 +211 -0
- package/dist/model.d.ts +164 -0
- package/dist/postgres/index.d.ts +38 -0
- package/dist/postgres/index.js +704 -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,10 @@
|
|
|
1
|
+
export declare const SCHEMAS = "\nselect nspname as name\nfrom pg_namespace\nwhere nspname not in ('pg_catalog', 'information_schema', 'pg_toast')\n\tand nspname not like 'pg_temp_%' and nspname not like 'pg_toast_temp_%'\norder by nspname";
|
|
2
|
+
export declare const ENUMS = "\nselect n.nspname as schema, t.typname as name,\n\tarray_agg(e.enumlabel order by e.enumsortorder) as \"values\"\nfrom pg_type t\njoin pg_namespace n on n.oid = t.typnamespace\njoin pg_enum e on e.enumtypid = t.oid\nwhere n.nspname = any($1)\ngroup by n.nspname, t.typname\norder by n.nspname, t.typname";
|
|
3
|
+
export declare const RELATIONS = "\nselect c.oid::int as id, n.nspname as schema, c.relname as name, c.relkind as kind,\n\tobj_description(c.oid, 'pg_class') as comment,\n\tc.relrowsecurity as rls, c.relforcerowsecurity as force_rls,\n\tcase when c.relkind = 'p' then pg_get_partkeydef(c.oid) end as partition_key,\n\tcase when c.relkind in ('v', 'm') then pg_get_viewdef(c.oid, true) end as definition,\n\t(select count(*)::int from pg_inherits i where i.inhparent = c.oid) as partitions\nfrom pg_class c\njoin pg_namespace n on n.oid = c.relnamespace\nwhere n.nspname = any($1) and c.relkind in ('r', 'p', 'v', 'm', 'f') and not c.relispartition\norder by n.nspname, c.relname";
|
|
4
|
+
export declare const COLUMNS = "\nselect a.attrelid::int as table_id, a.attnum::int as position, a.attname as name,\n\tformat_type(a.atttypid, a.atttypmod) as type,\n\ta.attnotnull as not_null, a.attidentity as identity, a.attgenerated as generated,\n\tpg_get_expr(d.adbin, d.adrelid) as \"default\",\n\tcol_description(a.attrelid, a.attnum) as comment,\n\tcase when t.typtype = 'e' then tn.nspname\n\t\twhen et.typtype = 'e' then etn.nspname end as enum_schema,\n\tcoalesce(case when t.typtype = 'e' then t.typname end,\n\t\tcase when et.typtype = 'e' then et.typname || '[]' end) as enum_type,\n\tpg_get_serial_sequence(quote_ident(n.nspname) || '.' || quote_ident(c.relname), a.attname) as serial_sequence\nfrom pg_attribute a\njoin pg_class c on c.oid = a.attrelid\njoin pg_namespace n on n.oid = c.relnamespace\njoin pg_type t on t.oid = a.atttypid\njoin pg_namespace tn on tn.oid = t.typnamespace\nleft join pg_type et on et.oid = t.typelem and t.typcategory = 'A'\nleft join pg_namespace etn on etn.oid = et.typnamespace\nleft join pg_attrdef d on d.adrelid = a.attrelid and d.adnum = a.attnum\nwhere n.nspname = any($1) and c.relkind in ('r', 'p', 'v', 'm', 'f') and not c.relispartition\n\tand a.attnum > 0 and not a.attisdropped\norder by a.attrelid, a.attnum";
|
|
5
|
+
export declare const CONSTRAINTS = "\nselect con.conrelid::int as table_id, con.conname as name, con.contype as kind,\n\t(select array_agg(k::int order by o) from unnest(con.conkey) with ordinality as u(k, o)) as columns,\n\tcon.confrelid::int as foreign_table_id,\n\t(select array_agg(k::int order by o) from unnest(con.confkey) with ordinality as u(k, o)) as foreign_columns,\n\tcon.confdeltype as on_delete, con.confupdtype as on_update,\n\tpg_get_constraintdef(con.oid, true) as definition,\n\tcase when con.contype = 'c' then pg_get_expr(con.conbin, con.conrelid, true) end as check_expression,\n\tobj_description(con.oid, 'pg_constraint') as comment,\n\tcon.condeferrable as deferrable, con.condeferred as deferred,\n\t/* Read through jsonb so a Postgres older than 15, without the column,\n\t * reads null instead of failing. */\n\t(to_jsonb(con) ->> 'connullsnotdistinct')::boolean as nulls_not_distinct\nfrom pg_constraint con\njoin pg_namespace n on n.oid = con.connamespace\nwhere n.nspname = any($1) and con.contype in ('p', 'u', 'f', 'c', 'x') and con.conrelid <> 0\norder by con.conrelid, con.contype, con.conname";
|
|
6
|
+
export declare const INDEXES = "\nselect i.indrelid::int as table_id, ic.relname as name, am.amname as method,\n\ti.indisunique as is_unique, i.indnkeyatts::int as key_count, i.indnatts::int as count,\n\t(select array_agg(pg_get_indexdef(i.indexrelid, k, true) order by k)\n\t\tfrom generate_series(1, i.indnatts) as k) as parts,\n\t(select array_agg(i.indkey[k - 1]::int order by k)\n\t\tfrom generate_series(1, i.indnatts) as k) as attnums,\n\t(select array_agg((i.indoption[k - 1] & 1) = 1 order by k)\n\t\tfrom generate_series(1, i.indnkeyatts) as k) as descending,\n\tpg_get_expr(i.indpred, i.indrelid, true) as predicate,\n\tobj_description(i.indexrelid, 'pg_class') as comment\nfrom pg_index i\njoin pg_class ic on ic.oid = i.indexrelid\njoin pg_class tc on tc.oid = i.indrelid\njoin pg_namespace n on n.oid = tc.relnamespace\njoin pg_am am on am.oid = ic.relam\nwhere n.nspname = any($1)\n\tand not exists (select 1 from pg_constraint con where con.conindid = i.indexrelid and con.contype in ('p', 'u', 'x'))\norder by i.indrelid, ic.relname";
|
|
7
|
+
export declare const VIEW_SOURCES = "\nselect distinct v.oid::int as view_id, d.refobjid::int as source_id\nfrom pg_class v\njoin pg_namespace n on n.oid = v.relnamespace\njoin pg_rewrite r on r.ev_class = v.oid\njoin pg_depend d on d.objid = r.oid and d.classid = 'pg_rewrite'::regclass\n\tand d.refclassid = 'pg_class'::regclass and d.refobjid <> v.oid\nwhere n.nspname = any($1) and v.relkind in ('v', 'm')";
|
|
8
|
+
export declare const POLICIES = "\nselect p.polrelid::int as table_id, p.polname as name, p.polpermissive as permissive,\n\tp.polcmd as command,\n\t(select array_agg(case when r = 0 then 'public' else pg_get_userbyid(r) end) from unnest(p.polroles) as r) as roles,\n\tpg_get_expr(p.polqual, p.polrelid, true) as \"using\",\n\tpg_get_expr(p.polwithcheck, p.polrelid, true) as with_check\nfrom pg_policy p\njoin pg_class c on c.oid = p.polrelid\njoin pg_namespace n on n.oid = c.relnamespace\nwhere n.nspname = any($1)\norder by p.polrelid, p.polname";
|
|
9
|
+
export declare const SEQUENCES = "\nselect n.nspname as schema, c.relname as name, s.seqstart::text as start,\n\ts.seqincrement::text as increment\nfrom pg_sequence s\njoin pg_class c on c.oid = s.seqrelid\njoin pg_namespace n on n.oid = c.relnamespace\nwhere n.nspname = any($1)\n\tand not exists (select 1 from pg_depend d where d.objid = c.oid and d.deptype in ('a', 'i'))\norder by n.nspname, c.relname";
|
|
10
|
+
export declare const SCHEMA_COMMENTS = "\nselect nspname as name, obj_description(oid, 'pg_namespace') as comment\nfrom pg_namespace where nspname = any($1)";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
type Raw = Record<string, unknown>;
|
|
2
|
+
export type RelationRow = {
|
|
3
|
+
comment?: string;
|
|
4
|
+
definition?: string;
|
|
5
|
+
forceRls: boolean;
|
|
6
|
+
id: number;
|
|
7
|
+
kind: string;
|
|
8
|
+
name: string;
|
|
9
|
+
partitionKey?: string;
|
|
10
|
+
partitions: number;
|
|
11
|
+
rls: boolean;
|
|
12
|
+
schema: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const relationRow: (row: Raw) => RelationRow;
|
|
15
|
+
export type ColumnRow = {
|
|
16
|
+
comment?: string;
|
|
17
|
+
default?: string;
|
|
18
|
+
enumSchema?: string;
|
|
19
|
+
enumType?: string;
|
|
20
|
+
generated?: string;
|
|
21
|
+
identity?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
notNull: boolean;
|
|
24
|
+
position: number;
|
|
25
|
+
serialSequence?: string;
|
|
26
|
+
tableId: number;
|
|
27
|
+
type: string;
|
|
28
|
+
};
|
|
29
|
+
export declare const columnRow: (row: Raw) => ColumnRow;
|
|
30
|
+
export type ConstraintRow = {
|
|
31
|
+
checkExpression?: string;
|
|
32
|
+
columns: number[];
|
|
33
|
+
comment?: string;
|
|
34
|
+
deferrable: boolean;
|
|
35
|
+
deferred: boolean;
|
|
36
|
+
definition: string;
|
|
37
|
+
foreignColumns: number[];
|
|
38
|
+
foreignTableId: number;
|
|
39
|
+
kind: string;
|
|
40
|
+
name: string;
|
|
41
|
+
nullsNotDistinct: boolean;
|
|
42
|
+
onDelete: string;
|
|
43
|
+
onUpdate: string;
|
|
44
|
+
tableId: number;
|
|
45
|
+
};
|
|
46
|
+
export declare const constraintRow: (row: Raw) => ConstraintRow;
|
|
47
|
+
export type IndexRow = {
|
|
48
|
+
attnums: number[];
|
|
49
|
+
comment?: string;
|
|
50
|
+
descending: boolean[];
|
|
51
|
+
keyCount: number;
|
|
52
|
+
method: string;
|
|
53
|
+
name: string;
|
|
54
|
+
parts: string[];
|
|
55
|
+
predicate?: string;
|
|
56
|
+
tableId: number;
|
|
57
|
+
unique: boolean;
|
|
58
|
+
};
|
|
59
|
+
export declare const indexRow: (row: Raw) => IndexRow;
|
|
60
|
+
export type PolicyRow = {
|
|
61
|
+
command: string;
|
|
62
|
+
name: string;
|
|
63
|
+
permissive: boolean;
|
|
64
|
+
roles: string[];
|
|
65
|
+
tableId: number;
|
|
66
|
+
using?: string;
|
|
67
|
+
withCheck?: string;
|
|
68
|
+
};
|
|
69
|
+
export declare const policyRow: (row: Raw) => PolicyRow;
|
|
70
|
+
export type NamedRow = {
|
|
71
|
+
comment?: string;
|
|
72
|
+
name: string;
|
|
73
|
+
schema: string;
|
|
74
|
+
};
|
|
75
|
+
export declare const namedRow: (row: Raw) => NamedRow;
|
|
76
|
+
export declare const enumRow: (row: Raw) => {
|
|
77
|
+
name: string;
|
|
78
|
+
schema: string;
|
|
79
|
+
values: string[];
|
|
80
|
+
};
|
|
81
|
+
export declare const sequenceRow: (row: Raw) => {
|
|
82
|
+
increment: string;
|
|
83
|
+
name: string;
|
|
84
|
+
schema: string;
|
|
85
|
+
start: string;
|
|
86
|
+
};
|
|
87
|
+
export declare const viewSourceRow: (row: Raw) => {
|
|
88
|
+
sourceId: number;
|
|
89
|
+
viewId: number;
|
|
90
|
+
};
|
|
91
|
+
export {};
|
package/dist/print.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DbmlModel } from './model';
|
|
2
|
+
/** A name in double quotes, a quote inside it escaped. */
|
|
3
|
+
export declare const quoteName: (name: string) => string;
|
|
4
|
+
/** Text in single quotes, or triple quotes when it runs over lines. */
|
|
5
|
+
export declare const quoteText: (text: string) => string;
|
|
6
|
+
/** An expression in backticks. DBML has no escape for a backtick inside
|
|
7
|
+
* one, so a stray one becomes a double quote, which is what an
|
|
8
|
+
* identifier quoted the other way means. */
|
|
9
|
+
export declare const quoteExpression: (expression: string) => string;
|
|
10
|
+
/** The model as DBML text. */
|
|
11
|
+
export declare const printDbml: (model: DbmlModel) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"author": "Alex Kahn",
|
|
3
|
+
"bin": {
|
|
4
|
+
"absolute-dbml": "./dist/cli.js"
|
|
5
|
+
},
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/absolutejs/dbml/issues"
|
|
8
|
+
},
|
|
9
|
+
"description": "Turn any Drizzle schema, or a live Postgres database, into DBML: tables, enums, keys, indexes, checks, relations and notes, with one model behind both.",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@absolutejs/changelog": "^0.6.0",
|
|
12
|
+
"@dbml/core": "12.1.0",
|
|
13
|
+
"@electric-sql/pglite": "0.5.15",
|
|
14
|
+
"@stylistic/eslint-plugin-ts": "4.2.0",
|
|
15
|
+
"@types/bun": "latest",
|
|
16
|
+
"drizzle-orm": "1.0.0-rc.4",
|
|
17
|
+
"eslint": "9.26.0",
|
|
18
|
+
"eslint-plugin-absolute": "0.0.3",
|
|
19
|
+
"eslint-plugin-import": "2.31.0",
|
|
20
|
+
"eslint-plugin-promise": "7.2.1",
|
|
21
|
+
"eslint-plugin-security": "3.0.1",
|
|
22
|
+
"prettier": "3.5.3",
|
|
23
|
+
"typescript": "5.9.3",
|
|
24
|
+
"typescript-eslint": "8.32.0"
|
|
25
|
+
},
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"default": "./dist/index.js",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./drizzle": {
|
|
33
|
+
"default": "./dist/drizzle/index.js",
|
|
34
|
+
"import": "./dist/drizzle/index.js",
|
|
35
|
+
"types": "./dist/drizzle/index.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./postgres": {
|
|
38
|
+
"default": "./dist/postgres/index.js",
|
|
39
|
+
"import": "./dist/postgres/index.js",
|
|
40
|
+
"types": "./dist/postgres/index.d.ts"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"CHANGELOG.md",
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"README.md",
|
|
47
|
+
"changelog.json",
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"homepage": "https://github.com/absolutejs/dbml",
|
|
51
|
+
"keywords": [
|
|
52
|
+
"dbml",
|
|
53
|
+
"drizzle",
|
|
54
|
+
"drizzle-orm",
|
|
55
|
+
"postgres",
|
|
56
|
+
"schema",
|
|
57
|
+
"erd",
|
|
58
|
+
"diagram"
|
|
59
|
+
],
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"main": "./dist/index.js",
|
|
62
|
+
"name": "@absolutejs/dbml",
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"drizzle-orm": ">=1.0.0-rc.4 <2"
|
|
65
|
+
},
|
|
66
|
+
"peerDependenciesMeta": {
|
|
67
|
+
"drizzle-orm": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
},
|
|
74
|
+
"repository": {
|
|
75
|
+
"type": "git",
|
|
76
|
+
"url": "https://github.com/absolutejs/dbml.git"
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "rm -rf dist && bun build src/index.ts src/drizzle/index.ts src/postgres/index.ts src/cli.ts --outdir dist --root ./src --target=bun --external drizzle-orm && tsc --emitDeclarationOnly --project tsconfig.build.json",
|
|
80
|
+
"check:package": "bun run typecheck && bun run lint && bun run build && bun run test && absolute-changelog check",
|
|
81
|
+
"format": "prettier --write \"./**/*.{ts,json,mjs,md}\"",
|
|
82
|
+
"lint": "eslint ./",
|
|
83
|
+
"prepublishOnly": "bun run check:package",
|
|
84
|
+
"test": "bun test",
|
|
85
|
+
"typecheck": "tsc --noEmit"
|
|
86
|
+
},
|
|
87
|
+
"type": "module",
|
|
88
|
+
"types": "./dist/index.d.ts",
|
|
89
|
+
"version": "0.2.0"
|
|
90
|
+
}
|