@typesql/pg 0.1.0 → 0.1.2
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 +2 -0
- package/dist/bin.js +1 -1
- package/dist/introspect/cli.js +1 -1
- package/dist/introspect/emit.d.ts +1 -1
- package/dist/introspect/emit.js +3 -3
- package/dist/introspect/introspect.d.ts +1 -1
- package/dist/introspect/introspect.js +1 -1
- package/package.json +21 -3
- package/src/bin.ts +1 -1
- package/src/introspect/cli.ts +1 -1
- package/src/introspect/emit.ts +3 -3
- package/src/introspect/introspect.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @typesql/pg
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- npm package pages link to the documentation site and the issue tracker, and list keywords.
|
|
8
|
+
|
|
9
|
+
- READMEs link to an example in the TypeScript Playground.
|
|
10
|
+
|
|
11
|
+
- Updated dependencies:
|
|
12
|
+
- @typesql/core@0.1.2
|
|
13
|
+
|
|
14
|
+
## 0.1.1
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Docs, package descriptions and error messages spell the project name TypeSQL.
|
|
19
|
+
|
|
20
|
+
- Updated dependencies:
|
|
21
|
+
- @typesql/core@0.1.1
|
|
22
|
+
|
|
3
23
|
## 0.1.0
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -8,6 +8,8 @@ map of `pg`'s default parsers, whose queries run on your pool and return rows ty
|
|
|
8
8
|
pnpm add @typesql/core @typesql/pg pg
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
[Open an example in the TypeScript Playground](https://www.typescriptlang.org/play/#code/PTAEBUE8AcFMGUCKAZUB3AlgFwBagHYD2AJrALTSEDOWA5gE6xWgAUAAljEwI4A2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FFqyaGuwGa+DkxTlNU4w8sPJb4ZSFgACohFAMT4AIba3M8udaoBNyAFUtFAI0AE1sakpK+Re9rOqJcHcWDaGBawWMkmKK4HHUTIsEIZQQVsN1IKMTCVEjDz3ICtS0H6JRcAGAJFBVpQSL0HoKlANzkGQI0xJ+ABpFxgSZPpQdGcDRrCGmArMJHpvRTVFaoZWqhUFgeUgWtWBFknYP9RdQD66HzWq2YYuWX2UZFuSgsU5y1KC8BXL261WBOgxlurEwDRJgA1MTkHphTyZYErDEKgAmEnsvAennIhIKAUdMqtgYZXYBu2M7raR7NkMAAGbm3qJD7vt+-7AeB0H+eTj2arq5HPljbOIVz-OIULmrmDDnHEqWqosHhWv68b5vW9ADuu4Unu+4HofDCWzY7RYAFkIM9NqS9YArx+n9GgG8QYWG3oMWI9AlA0w0sQECQkBZaGsDmIkJdrADFVB1b6ZgjC0GsrDPosA-qgExLwHICR2b5RiqSYUvoxhTRRrNJo81wA5R2tTIizBDrZWYbjH279zpbHKmA16vNurMQTmAaQax6CJCMDNXCyRaBiwIIQMIJh2E+ncEAA) <!-- playground:pg --> to hover the types and edit the SQL, with nothing to install.
|
|
12
|
+
|
|
11
13
|
## Usage
|
|
12
14
|
|
|
13
15
|
```ts
|
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/** `typesql`: `typesql introspect` writes the
|
|
2
|
+
/** `typesql`: `typesql introspect` writes the TypeSQL schema of a live database. */
|
|
3
3
|
import { main } from "./introspect/cli.js";
|
|
4
4
|
process.exitCode = await main(process.argv.slice(2));
|
|
5
5
|
//# sourceMappingURL=bin.js.map
|
package/dist/introspect/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { generateSource } from "./emit.js";
|
|
|
6
6
|
import { introspect } from "./introspect.js";
|
|
7
7
|
const USAGE = `Usage: typesql introspect [options]
|
|
8
8
|
|
|
9
|
-
Reads a live Postgres database and writes its
|
|
9
|
+
Reads a live Postgres database and writes its TypeSQL schema (tables, views, enums).
|
|
10
10
|
|
|
11
11
|
Options:
|
|
12
12
|
--url <url> connection string (default: $DATABASE_URL)
|
|
@@ -22,7 +22,7 @@ export interface GenerateOptions {
|
|
|
22
22
|
readonly comments?: boolean;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* TypeScript source declaring the
|
|
25
|
+
* TypeScript source declaring the TypeSQL schema of an introspected database: `public`
|
|
26
26
|
* relations at the top level, other schemas nested (`DB["auth"]["sessions"]`), views and
|
|
27
27
|
* materialized views as `View<…>`, enums under `$types`.
|
|
28
28
|
*/
|
package/dist/introspect/emit.js
CHANGED
|
@@ -25,7 +25,7 @@ function columnNotes(c) {
|
|
|
25
25
|
return notes;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* TypeScript source declaring the
|
|
28
|
+
* TypeScript source declaring the TypeSQL schema of an introspected database: `public`
|
|
29
29
|
* relations at the top level, other schemas nested (`DB["auth"]["sessions"]`), views and
|
|
30
30
|
* materialized views as `View<…>`, enums under `$types`.
|
|
31
31
|
*/
|
|
@@ -102,13 +102,13 @@ export function generateSource(db, options = {}) {
|
|
|
102
102
|
}
|
|
103
103
|
for (const [schema, rels] of namespaces) {
|
|
104
104
|
if (topLevel.has(schema)) {
|
|
105
|
-
throw new Error(`schema "${schema}" has the same name as the table "public.${schema}":
|
|
105
|
+
throw new Error(`schema "${schema}" has the same name as the table "public.${schema}": TypeSQL keeps public relations and schemas in one object`);
|
|
106
106
|
}
|
|
107
107
|
const body = rels.map((r) => `${relDoc(r, " ")} ${key(r.name)}: ${relation(r, " ")};`);
|
|
108
108
|
lines.push(` ${key(schema)}: {\n${body.join("\n")}\n };`);
|
|
109
109
|
}
|
|
110
110
|
if (db.enums.length > 0) {
|
|
111
|
-
//
|
|
111
|
+
// TypeSQL's enum registry is flat (`Col<"mood">`, schema qualifiers are dropped), so enums
|
|
112
112
|
// of the same name in different schemas share an entry.
|
|
113
113
|
const byName = new Map();
|
|
114
114
|
for (const e of db.enums) {
|
|
@@ -4,7 +4,7 @@ export type RelationKind = "table" | "partitioned table" | "view" | "materialize
|
|
|
4
4
|
export interface IntrospectedColumn {
|
|
5
5
|
readonly name: string;
|
|
6
6
|
/**
|
|
7
|
-
* Canonical Postgres type name as
|
|
7
|
+
* Canonical Postgres type name as TypeSQL spells it: `int4`, `timestamptz`, `varchar`, an enum
|
|
8
8
|
* name, `${T}[]` for arrays. Domains are replaced by their base type; `citext` is `text`.
|
|
9
9
|
*/
|
|
10
10
|
readonly type: string;
|
|
@@ -7,7 +7,7 @@ const KINDS = {
|
|
|
7
7
|
m: "materialized view",
|
|
8
8
|
f: "foreign table",
|
|
9
9
|
};
|
|
10
|
-
/** Postgres type names
|
|
10
|
+
/** Postgres type names TypeSQL spells differently. */
|
|
11
11
|
const TYPE_ALIASES = { citext: "text" };
|
|
12
12
|
function resolver(types) {
|
|
13
13
|
const resolve = (oid) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typesql/pg",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "node-postgres (pg) adapter for
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "node-postgres (pg) adapter for TypeSQL, with `typesql introspect` to generate a schema from a live database.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@typesql/core": "0.1.
|
|
38
|
+
"@typesql/core": "0.1.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"pg": ">=8"
|
|
@@ -46,6 +46,24 @@
|
|
|
46
46
|
"typescript": "7.0.2",
|
|
47
47
|
"vitest": "^5.0.4"
|
|
48
48
|
},
|
|
49
|
+
"homepage": "https://typesql.karsli.net/adapters/pg",
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/ismailkarsli/typesql/issues"
|
|
52
|
+
},
|
|
53
|
+
"author": "İsmail Karslı",
|
|
54
|
+
"keywords": [
|
|
55
|
+
"sql",
|
|
56
|
+
"postgres",
|
|
57
|
+
"postgresql",
|
|
58
|
+
"typescript",
|
|
59
|
+
"type-safe",
|
|
60
|
+
"type-level",
|
|
61
|
+
"raw-sql",
|
|
62
|
+
"no-codegen",
|
|
63
|
+
"pg",
|
|
64
|
+
"node-postgres",
|
|
65
|
+
"introspection"
|
|
66
|
+
],
|
|
49
67
|
"scripts": {
|
|
50
68
|
"build": "tsc -p tsconfig.build.json",
|
|
51
69
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
package/src/bin.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/** `typesql`: `typesql introspect` writes the
|
|
2
|
+
/** `typesql`: `typesql introspect` writes the TypeSQL schema of a live database. */
|
|
3
3
|
import { main } from "./introspect/cli.js";
|
|
4
4
|
|
|
5
5
|
process.exitCode = await main(process.argv.slice(2));
|
package/src/introspect/cli.ts
CHANGED
|
@@ -16,7 +16,7 @@ export interface IntrospectConfig extends GenerateOptions, IntrospectOptions {
|
|
|
16
16
|
|
|
17
17
|
const USAGE = `Usage: typesql introspect [options]
|
|
18
18
|
|
|
19
|
-
Reads a live Postgres database and writes its
|
|
19
|
+
Reads a live Postgres database and writes its TypeSQL schema (tables, views, enums).
|
|
20
20
|
|
|
21
21
|
Options:
|
|
22
22
|
--url <url> connection string (default: $DATABASE_URL)
|
package/src/introspect/emit.ts
CHANGED
|
@@ -51,7 +51,7 @@ function columnNotes(c: IntrospectedColumn): string[] {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
* TypeScript source declaring the
|
|
54
|
+
* TypeScript source declaring the TypeSQL schema of an introspected database: `public`
|
|
55
55
|
* relations at the top level, other schemas nested (`DB["auth"]["sessions"]`), views and
|
|
56
56
|
* materialized views as `View<…>`, enums under `$types`.
|
|
57
57
|
*/
|
|
@@ -126,14 +126,14 @@ export function generateSource(db: IntrospectedDatabase, options: GenerateOption
|
|
|
126
126
|
}
|
|
127
127
|
for (const [schema, rels] of namespaces) {
|
|
128
128
|
if (topLevel.has(schema)) {
|
|
129
|
-
throw new Error(`schema "${schema}" has the same name as the table "public.${schema}":
|
|
129
|
+
throw new Error(`schema "${schema}" has the same name as the table "public.${schema}": TypeSQL keeps public relations and schemas in one object`);
|
|
130
130
|
}
|
|
131
131
|
const body = rels.map((r) => `${relDoc(r, " ")} ${key(r.name)}: ${relation(r, " ")};`);
|
|
132
132
|
lines.push(` ${key(schema)}: {\n${body.join("\n")}\n };`);
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
if (db.enums.length > 0) {
|
|
136
|
-
//
|
|
136
|
+
// TypeSQL's enum registry is flat (`Col<"mood">`, schema qualifiers are dropped), so enums
|
|
137
137
|
// of the same name in different schemas share an entry.
|
|
138
138
|
const byName = new Map<string, { values: Set<string>; schemas: string[] }>();
|
|
139
139
|
for (const e of db.enums) {
|
|
@@ -6,7 +6,7 @@ export type RelationKind = "table" | "partitioned table" | "view" | "materialize
|
|
|
6
6
|
export interface IntrospectedColumn {
|
|
7
7
|
readonly name: string;
|
|
8
8
|
/**
|
|
9
|
-
* Canonical Postgres type name as
|
|
9
|
+
* Canonical Postgres type name as TypeSQL spells it: `int4`, `timestamptz`, `varchar`, an enum
|
|
10
10
|
* name, `${T}[]` for arrays. Domains are replaced by their base type; `citext` is `text`.
|
|
11
11
|
*/
|
|
12
12
|
readonly type: string;
|
|
@@ -77,7 +77,7 @@ const KINDS: Readonly<Record<string, RelationKind>> = {
|
|
|
77
77
|
f: "foreign table",
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
/** Postgres type names
|
|
80
|
+
/** Postgres type names TypeSQL spells differently. */
|
|
81
81
|
const TYPE_ALIASES: Readonly<Record<string, string>> = { citext: "text" };
|
|
82
82
|
|
|
83
83
|
interface TypeRow {
|