@atscript/db-postgres 0.1.38 → 0.1.40
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/README.md +59 -0
- package/dist/index-HFavdjnf.d.mts +6 -0
- package/dist/index-Tl2u3rTo.d.cts +6 -0
- package/dist/index.cjs +308 -305
- package/dist/index.d.cts +279 -0
- package/dist/index.d.mts +279 -0
- package/dist/index.mjs +283 -257
- package/dist/plugin-C4tRUZGB.mjs +53 -0
- package/dist/plugin-Cx6tCzk4.cjs +58 -0
- package/dist/plugin.cjs +6 -72
- package/dist/plugin.d.cts +2 -0
- package/dist/plugin.d.mts +2 -0
- package/dist/plugin.mjs +2 -47
- package/package.json +26 -36
- package/LICENSE +0 -21
- package/dist/index.d.ts +0 -278
- package/dist/plugin.d.ts +0 -5
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AnnotationSpec } from "@atscript/core";
|
|
2
|
+
//#region src/plugin/annotations.ts
|
|
3
|
+
/**
|
|
4
|
+
* PostgreSQL-specific annotations.
|
|
5
|
+
*
|
|
6
|
+
* Merged into the global config under `{ db: { pg: ... } }` so they
|
|
7
|
+
* live alongside core's `@db.table`, `@db.index.*`, etc.
|
|
8
|
+
*
|
|
9
|
+
* These annotations opt-in to PostgreSQL-specific behavior. Files using only
|
|
10
|
+
* portable `@db.*` annotations remain adapter-agnostic.
|
|
11
|
+
*/
|
|
12
|
+
const annotations = {
|
|
13
|
+
type: new AnnotationSpec({
|
|
14
|
+
description: "Overrides the native PostgreSQL column type.\n\n```atscript\n@db.pg.type \"CITEXT\"\nname: string\n```",
|
|
15
|
+
nodeType: ["prop"],
|
|
16
|
+
multiple: false,
|
|
17
|
+
argument: {
|
|
18
|
+
name: "type",
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Native PostgreSQL column type (e.g., \"CITEXT\", \"INET\", \"MACADDR\")."
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
schema: new AnnotationSpec({
|
|
24
|
+
description: "Specifies the PostgreSQL schema for the table.\n\n**Default:** `\"public\"`\n\n```atscript\n@db.pg.schema \"analytics\"\nexport interface Events { ... }\n```",
|
|
25
|
+
nodeType: ["interface"],
|
|
26
|
+
multiple: false,
|
|
27
|
+
argument: {
|
|
28
|
+
name: "schema",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "PostgreSQL schema name (e.g., \"public\", \"analytics\")."
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
collate: new AnnotationSpec({
|
|
34
|
+
description: "Specifies a native PostgreSQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.pg.collate \"tr-x-icu\"\nname: string\n```",
|
|
35
|
+
nodeType: ["interface", "prop"],
|
|
36
|
+
multiple: false,
|
|
37
|
+
argument: {
|
|
38
|
+
name: "collation",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Native PostgreSQL collation name (e.g., \"tr-x-icu\", \"C\", \"und-x-icu\")."
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/plugin/index.ts
|
|
46
|
+
const PostgresPlugin = () => ({
|
|
47
|
+
name: "postgres",
|
|
48
|
+
config() {
|
|
49
|
+
return { annotations: { db: { pg: annotations } } };
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
//#endregion
|
|
53
|
+
export { PostgresPlugin as t };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
let _atscript_core = require("@atscript/core");
|
|
2
|
+
//#region src/plugin/annotations.ts
|
|
3
|
+
/**
|
|
4
|
+
* PostgreSQL-specific annotations.
|
|
5
|
+
*
|
|
6
|
+
* Merged into the global config under `{ db: { pg: ... } }` so they
|
|
7
|
+
* live alongside core's `@db.table`, `@db.index.*`, etc.
|
|
8
|
+
*
|
|
9
|
+
* These annotations opt-in to PostgreSQL-specific behavior. Files using only
|
|
10
|
+
* portable `@db.*` annotations remain adapter-agnostic.
|
|
11
|
+
*/
|
|
12
|
+
const annotations = {
|
|
13
|
+
type: new _atscript_core.AnnotationSpec({
|
|
14
|
+
description: "Overrides the native PostgreSQL column type.\n\n```atscript\n@db.pg.type \"CITEXT\"\nname: string\n```",
|
|
15
|
+
nodeType: ["prop"],
|
|
16
|
+
multiple: false,
|
|
17
|
+
argument: {
|
|
18
|
+
name: "type",
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "Native PostgreSQL column type (e.g., \"CITEXT\", \"INET\", \"MACADDR\")."
|
|
21
|
+
}
|
|
22
|
+
}),
|
|
23
|
+
schema: new _atscript_core.AnnotationSpec({
|
|
24
|
+
description: "Specifies the PostgreSQL schema for the table.\n\n**Default:** `\"public\"`\n\n```atscript\n@db.pg.schema \"analytics\"\nexport interface Events { ... }\n```",
|
|
25
|
+
nodeType: ["interface"],
|
|
26
|
+
multiple: false,
|
|
27
|
+
argument: {
|
|
28
|
+
name: "schema",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "PostgreSQL schema name (e.g., \"public\", \"analytics\")."
|
|
31
|
+
}
|
|
32
|
+
}),
|
|
33
|
+
collate: new _atscript_core.AnnotationSpec({
|
|
34
|
+
description: "Specifies a native PostgreSQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.pg.collate \"tr-x-icu\"\nname: string\n```",
|
|
35
|
+
nodeType: ["interface", "prop"],
|
|
36
|
+
multiple: false,
|
|
37
|
+
argument: {
|
|
38
|
+
name: "collation",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: "Native PostgreSQL collation name (e.g., \"tr-x-icu\", \"C\", \"und-x-icu\")."
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/plugin/index.ts
|
|
46
|
+
const PostgresPlugin = () => ({
|
|
47
|
+
name: "postgres",
|
|
48
|
+
config() {
|
|
49
|
+
return { annotations: { db: { pg: annotations } } };
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
//#endregion
|
|
53
|
+
Object.defineProperty(exports, "PostgresPlugin", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function() {
|
|
56
|
+
return PostgresPlugin;
|
|
57
|
+
}
|
|
58
|
+
});
|
package/dist/plugin.cjs
CHANGED
|
@@ -1,73 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __create = Object.create;
|
|
5
|
-
var __defProp = Object.defineProperty;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
-
key = keys[i];
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
-
get: ((k) => from[k]).bind(null, key),
|
|
15
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
21
|
-
value: mod,
|
|
22
|
-
enumerable: true
|
|
23
|
-
}) : target, mod));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
const __atscript_core = __toESM(require("@atscript/core"));
|
|
27
|
-
|
|
28
|
-
//#region packages/db-postgres/src/plugin/annotations.ts
|
|
29
|
-
const annotations = {
|
|
30
|
-
type: new __atscript_core.AnnotationSpec({
|
|
31
|
-
description: "Overrides the native PostgreSQL column type.\n\n```atscript\n@db.pg.type \"CITEXT\"\nname: string\n```",
|
|
32
|
-
nodeType: ["prop"],
|
|
33
|
-
multiple: false,
|
|
34
|
-
argument: {
|
|
35
|
-
name: "type",
|
|
36
|
-
type: "string",
|
|
37
|
-
description: "Native PostgreSQL column type (e.g., \"CITEXT\", \"INET\", \"MACADDR\")."
|
|
38
|
-
}
|
|
39
|
-
}),
|
|
40
|
-
schema: new __atscript_core.AnnotationSpec({
|
|
41
|
-
description: "Specifies the PostgreSQL schema for the table.\n\n**Default:** `\"public\"`\n\n```atscript\n@db.pg.schema \"analytics\"\nexport interface Events { ... }\n```",
|
|
42
|
-
nodeType: ["interface"],
|
|
43
|
-
multiple: false,
|
|
44
|
-
argument: {
|
|
45
|
-
name: "schema",
|
|
46
|
-
type: "string",
|
|
47
|
-
description: "PostgreSQL schema name (e.g., \"public\", \"analytics\")."
|
|
48
|
-
}
|
|
49
|
-
}),
|
|
50
|
-
collate: new __atscript_core.AnnotationSpec({
|
|
51
|
-
description: "Specifies a native PostgreSQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.pg.collate \"tr-x-icu\"\nname: string\n```",
|
|
52
|
-
nodeType: ["interface", "prop"],
|
|
53
|
-
multiple: false,
|
|
54
|
-
argument: {
|
|
55
|
-
name: "collation",
|
|
56
|
-
type: "string",
|
|
57
|
-
description: "Native PostgreSQL collation name (e.g., \"tr-x-icu\", \"C\", \"und-x-icu\")."
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
//#region packages/db-postgres/src/plugin/index.ts
|
|
64
|
-
const PostgresPlugin = () => ({
|
|
65
|
-
name: "postgres",
|
|
66
|
-
config() {
|
|
67
|
-
return { annotations: { db: { pg: annotations } } };
|
|
68
|
-
}
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
69
4
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
exports.
|
|
73
|
-
exports.default = PostgresPlugin
|
|
5
|
+
const require_plugin = require("./plugin-Cx6tCzk4.cjs");
|
|
6
|
+
exports.PostgresPlugin = require_plugin.PostgresPlugin;
|
|
7
|
+
exports.default = require_plugin.PostgresPlugin;
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,47 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region packages/db-postgres/src/plugin/annotations.ts
|
|
4
|
-
const annotations = {
|
|
5
|
-
type: new AnnotationSpec({
|
|
6
|
-
description: "Overrides the native PostgreSQL column type.\n\n```atscript\n@db.pg.type \"CITEXT\"\nname: string\n```",
|
|
7
|
-
nodeType: ["prop"],
|
|
8
|
-
multiple: false,
|
|
9
|
-
argument: {
|
|
10
|
-
name: "type",
|
|
11
|
-
type: "string",
|
|
12
|
-
description: "Native PostgreSQL column type (e.g., \"CITEXT\", \"INET\", \"MACADDR\")."
|
|
13
|
-
}
|
|
14
|
-
}),
|
|
15
|
-
schema: new AnnotationSpec({
|
|
16
|
-
description: "Specifies the PostgreSQL schema for the table.\n\n**Default:** `\"public\"`\n\n```atscript\n@db.pg.schema \"analytics\"\nexport interface Events { ... }\n```",
|
|
17
|
-
nodeType: ["interface"],
|
|
18
|
-
multiple: false,
|
|
19
|
-
argument: {
|
|
20
|
-
name: "schema",
|
|
21
|
-
type: "string",
|
|
22
|
-
description: "PostgreSQL schema name (e.g., \"public\", \"analytics\")."
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
collate: new AnnotationSpec({
|
|
26
|
-
description: "Specifies a native PostgreSQL collation (overrides portable `@db.column.collate`).\n\n```atscript\n@db.pg.collate \"tr-x-icu\"\nname: string\n```",
|
|
27
|
-
nodeType: ["interface", "prop"],
|
|
28
|
-
multiple: false,
|
|
29
|
-
argument: {
|
|
30
|
-
name: "collation",
|
|
31
|
-
type: "string",
|
|
32
|
-
description: "Native PostgreSQL collation name (e.g., \"tr-x-icu\", \"C\", \"und-x-icu\")."
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region packages/db-postgres/src/plugin/index.ts
|
|
39
|
-
const PostgresPlugin = () => ({
|
|
40
|
-
name: "postgres",
|
|
41
|
-
config() {
|
|
42
|
-
return { annotations: { db: { pg: annotations } } };
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { PostgresPlugin, PostgresPlugin as default };
|
|
1
|
+
import { t as PostgresPlugin } from "./plugin-C4tRUZGB.mjs";
|
|
2
|
+
export { PostgresPlugin, PostgresPlugin as default };
|
package/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/db-postgres",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
4
4
|
"description": "PostgreSQL adapter for @atscript/db with pg (node-postgres) driver support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
7
7
|
"database",
|
|
8
|
-
"
|
|
8
|
+
"pgvector",
|
|
9
9
|
"postgres",
|
|
10
|
-
"
|
|
10
|
+
"postgresql"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/db-postgres#readme",
|
|
12
|
+
"homepage": "https://github.com/moostjs/atscript-db/tree/main/packages/db-postgres#readme",
|
|
13
13
|
"bugs": {
|
|
14
|
-
"url": "https://github.com/moostjs/atscript/issues"
|
|
14
|
+
"url": "https://github.com/moostjs/atscript-db/issues"
|
|
15
15
|
},
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"author": "Artem Maltsev",
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/moostjs/atscript.git",
|
|
20
|
+
"url": "git+https://github.com/moostjs/atscript-db.git",
|
|
21
21
|
"directory": "packages/db-postgres"
|
|
22
22
|
},
|
|
23
23
|
"files": [
|
|
@@ -25,59 +25,49 @@
|
|
|
25
25
|
],
|
|
26
26
|
"type": "module",
|
|
27
27
|
"main": "dist/index.mjs",
|
|
28
|
-
"types": "dist/index.d.
|
|
29
|
-
"typesVersions": {
|
|
30
|
-
"*": {
|
|
31
|
-
"plugin": [
|
|
32
|
-
"dist/plugin.d.ts"
|
|
33
|
-
],
|
|
34
|
-
"": [
|
|
35
|
-
"dist/index.d.ts"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
},
|
|
28
|
+
"types": "dist/index.d.mts",
|
|
39
29
|
"exports": {
|
|
40
30
|
".": {
|
|
41
|
-
"types": "./dist/index.d.
|
|
31
|
+
"types": "./dist/index.d.mts",
|
|
42
32
|
"import": "./dist/index.mjs",
|
|
43
33
|
"require": "./dist/index.cjs"
|
|
44
34
|
},
|
|
45
35
|
"./plugin": {
|
|
46
|
-
"types": "./dist/plugin.d.
|
|
36
|
+
"types": "./dist/plugin.d.mts",
|
|
47
37
|
"import": "./dist/plugin.mjs",
|
|
48
38
|
"require": "./dist/plugin.cjs"
|
|
49
39
|
},
|
|
50
40
|
"./package.json": "./package.json"
|
|
51
41
|
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
44
|
+
},
|
|
52
45
|
"devDependencies": {
|
|
53
|
-
"
|
|
46
|
+
"@atscript/core": "^0.1.39",
|
|
47
|
+
"@atscript/typescript": "^0.1.39",
|
|
54
48
|
"@types/pg": "^8.11.0",
|
|
55
|
-
"
|
|
49
|
+
"@uniqu/core": "^0.1.2",
|
|
50
|
+
"pg": "^8.13.0",
|
|
51
|
+
"unplugin-atscript": "^0.1.39"
|
|
56
52
|
},
|
|
57
53
|
"peerDependencies": {
|
|
54
|
+
"@atscript/core": "^0.1.39",
|
|
55
|
+
"@atscript/typescript": "^0.1.39",
|
|
58
56
|
"@uniqu/core": "^0.1.2",
|
|
59
57
|
"pg": ">=8.0.0",
|
|
60
|
-
"@atscript/db": "^0.1.
|
|
61
|
-
"@atscript/
|
|
62
|
-
"@atscript/core": "^0.1.38",
|
|
63
|
-
"@atscript/db-sql-tools": "^0.1.38"
|
|
58
|
+
"@atscript/db": "^0.1.40",
|
|
59
|
+
"@atscript/db-sql-tools": "^0.1.40"
|
|
64
60
|
},
|
|
65
61
|
"peerDependenciesMeta": {
|
|
66
62
|
"pg": {
|
|
67
63
|
"optional": true
|
|
68
64
|
}
|
|
69
65
|
},
|
|
70
|
-
"build": [
|
|
71
|
-
{},
|
|
72
|
-
{
|
|
73
|
-
"entries": [
|
|
74
|
-
"src/plugin.ts"
|
|
75
|
-
],
|
|
76
|
-
"dts": true
|
|
77
|
-
}
|
|
78
|
-
],
|
|
79
66
|
"scripts": {
|
|
80
|
-
"
|
|
81
|
-
"
|
|
67
|
+
"postinstall": "asc -f dts",
|
|
68
|
+
"build": "vp pack",
|
|
69
|
+
"dev": "vp pack --watch",
|
|
70
|
+
"test": "vp test",
|
|
71
|
+
"check": "vp check"
|
|
82
72
|
}
|
|
83
73
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025-present Artem Maltsev
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/dist/index.d.ts
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { BaseDbAdapter, TDbDefaultFn, TDbFieldMeta, TValueFormatterPair, TDbInsertResult, TDbInsertManyResult, DbQuery, FilterExpr, TDbUpdateResult, TDbDeleteResult, TExistingColumn, TColumnDiff, TSyncColumnResult, TSearchIndexInfo, DbSpace } from '@atscript/db';
|
|
2
|
-
import { TAtscriptAnnotatedType, TMetadataMap } from '@atscript/typescript/utils';
|
|
3
|
-
import * as pg from 'pg';
|
|
4
|
-
import { TAtscriptPlugin } from '@atscript/core';
|
|
5
|
-
import { TSqlFragment } from '@atscript/db-sql-tools';
|
|
6
|
-
export { TSqlFragment } from '@atscript/db-sql-tools';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Result of a PostgreSQL statement that modifies data (INSERT, UPDATE, DELETE).
|
|
10
|
-
*/
|
|
11
|
-
interface TPgRunResult {
|
|
12
|
-
/** Number of rows affected by the statement. */
|
|
13
|
-
affectedRows: number;
|
|
14
|
-
/** Rows returned by a RETURNING clause (empty array when not applicable). */
|
|
15
|
-
rows: Record<string, unknown>[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Async driver interface for PostgreSQL engines.
|
|
19
|
-
*
|
|
20
|
-
* The driver has two modes of operation:
|
|
21
|
-
* 1. **Pool mode** (default) — each call acquires/releases a connection automatically
|
|
22
|
-
* 2. **Connection mode** (for transactions) — a dedicated connection is acquired
|
|
23
|
-
* and all operations run on it until released
|
|
24
|
-
*
|
|
25
|
-
* Implementations: {@link PgDriver}
|
|
26
|
-
*/
|
|
27
|
-
interface TPgDriver {
|
|
28
|
-
/**
|
|
29
|
-
* Execute a SQL statement that modifies data (INSERT, UPDATE, DELETE, DDL).
|
|
30
|
-
* Uses parameterized queries (`$1, $2, ...` placeholders).
|
|
31
|
-
*/
|
|
32
|
-
run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
|
|
33
|
-
/**
|
|
34
|
-
* Execute a query and return all matching rows.
|
|
35
|
-
*/
|
|
36
|
-
all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
37
|
-
/**
|
|
38
|
-
* Execute a query and return the first matching row, or null.
|
|
39
|
-
*/
|
|
40
|
-
get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
41
|
-
/**
|
|
42
|
-
* Execute raw SQL without returning results.
|
|
43
|
-
* Used for DDL, SET statements, etc.
|
|
44
|
-
*/
|
|
45
|
-
exec(sql: string): Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Acquire a dedicated connection for transaction use.
|
|
48
|
-
* Returns a {@link TPgConnection} that must be released after use.
|
|
49
|
-
*/
|
|
50
|
-
getConnection(): Promise<TPgConnection>;
|
|
51
|
-
/**
|
|
52
|
-
* Close the pool / end all connections.
|
|
53
|
-
*/
|
|
54
|
-
close(): Promise<void>;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* A dedicated connection acquired from the pool.
|
|
58
|
-
* Used for transactions where all operations must run on the same connection.
|
|
59
|
-
*/
|
|
60
|
-
interface TPgConnection {
|
|
61
|
-
/** Execute a statement that modifies data. */
|
|
62
|
-
run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
|
|
63
|
-
/** Execute a query and return all matching rows. */
|
|
64
|
-
all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
65
|
-
/** Execute a query and return the first matching row, or null. */
|
|
66
|
-
get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
67
|
-
/** Execute raw SQL without returning results. */
|
|
68
|
-
exec(sql: string): Promise<void>;
|
|
69
|
-
/** Release this connection back to the pool. */
|
|
70
|
-
release(): void;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* PostgreSQL adapter for {@link AtscriptDbTable}.
|
|
75
|
-
*
|
|
76
|
-
* Accepts any {@link TPgDriver} implementation — the actual PostgreSQL driver
|
|
77
|
-
* is fully swappable (pg Pool, custom implementations, etc.).
|
|
78
|
-
*
|
|
79
|
-
* Usage:
|
|
80
|
-
* ```typescript
|
|
81
|
-
* import { PgDriver, PostgresAdapter } from '@atscript/db-postgres'
|
|
82
|
-
* import { DbSpace } from '@atscript/db'
|
|
83
|
-
*
|
|
84
|
-
* const driver = new PgDriver('postgresql://user@localhost:5432/mydb')
|
|
85
|
-
* const space = new DbSpace(() => new PostgresAdapter(driver))
|
|
86
|
-
* const users = space.getTable(UsersType)
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
declare class PostgresAdapter extends BaseDbAdapter {
|
|
90
|
-
protected readonly driver: TPgDriver;
|
|
91
|
-
supportsColumnModify: boolean;
|
|
92
|
-
private static readonly NATIVE_DEFAULT_FNS;
|
|
93
|
-
private _incrementFields;
|
|
94
|
-
private _autoIncrementStart?;
|
|
95
|
-
/** Physical column names with @db.collate 'nocase'. Used to trigger CITEXT extension. */
|
|
96
|
-
private _nocaseColumns;
|
|
97
|
-
/** Whether citext extension has been provisioned (avoids redundant round-trips). */
|
|
98
|
-
private _citextProvisioned;
|
|
99
|
-
/** Whether the connected PostgreSQL instance has the pgvector extension. */
|
|
100
|
-
private _supportsVector;
|
|
101
|
-
/** Vector fields: physical field name → { dimensions, similarity, indexName }. */
|
|
102
|
-
private _vectorFields;
|
|
103
|
-
/** Default similarity thresholds per vector field (from @db.search.vector.threshold). */
|
|
104
|
-
private _vectorThresholds;
|
|
105
|
-
/** Schema name for queries (null falls through to 'public'). */
|
|
106
|
-
private get _schema();
|
|
107
|
-
constructor(driver: TPgDriver);
|
|
108
|
-
protected _beginTransaction(): Promise<TPgConnection>;
|
|
109
|
-
protected _commitTransaction(state: unknown): Promise<void>;
|
|
110
|
-
protected _rollbackTransaction(state: unknown): Promise<void>;
|
|
111
|
-
/**
|
|
112
|
-
* Returns the active executor: dedicated connection if inside a transaction,
|
|
113
|
-
* otherwise the pool-based driver.
|
|
114
|
-
*/
|
|
115
|
-
private _exec;
|
|
116
|
-
/** PostgreSQL enforces FK constraints natively. */
|
|
117
|
-
supportsNativeForeignKeys(): boolean;
|
|
118
|
-
prepareId(id: unknown, _fieldType: TAtscriptAnnotatedType): unknown;
|
|
119
|
-
supportsNativeValueDefaults(): boolean;
|
|
120
|
-
nativeDefaultFns(): ReadonlySet<TDbDefaultFn>;
|
|
121
|
-
onBeforeFlatten(_type: TAtscriptAnnotatedType): void;
|
|
122
|
-
onAfterFlatten(): void;
|
|
123
|
-
onFieldScanned(field: string, _type: TAtscriptAnnotatedType, metadata: TMetadataMap<AtscriptMetadata>): void;
|
|
124
|
-
getDesiredTableOptions(): never[];
|
|
125
|
-
getExistingTableOptions(): Promise<never[]>;
|
|
126
|
-
/**
|
|
127
|
-
* Converts vector fields between JavaScript `number[]` and pgvector text format `[1,2,3]`.
|
|
128
|
-
* The pg driver serializes JS arrays as PostgreSQL array literals `{1,2,3}` which is
|
|
129
|
-
* invalid for the pgvector `vector` type — it expects bracket-delimited `[1,2,3]`.
|
|
130
|
-
*/
|
|
131
|
-
formatValue(field: TDbFieldMeta): TValueFormatterPair | undefined;
|
|
132
|
-
/**
|
|
133
|
-
* Wraps an async write operation to catch PostgreSQL constraint errors
|
|
134
|
-
* and rethrow as structured `DbError`.
|
|
135
|
-
*
|
|
136
|
-
* PostgreSQL uses SQLSTATE codes:
|
|
137
|
-
* - 23505 = unique_violation
|
|
138
|
-
* - 23503 = foreign_key_violation
|
|
139
|
-
*/
|
|
140
|
-
private _wrapConstraintError;
|
|
141
|
-
private _extractFieldFromConstraint;
|
|
142
|
-
private _mapFkError;
|
|
143
|
-
insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
|
|
144
|
-
insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
|
|
145
|
-
findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
|
|
146
|
-
findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
147
|
-
count(query: DbQuery): Promise<number>;
|
|
148
|
-
aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
|
|
149
|
-
updateOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
150
|
-
updateMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
151
|
-
replaceOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
152
|
-
replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
|
|
153
|
-
deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
154
|
-
deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
|
|
155
|
-
ensureTable(): Promise<void>;
|
|
156
|
-
private _ensureView;
|
|
157
|
-
getExistingColumns(): Promise<TExistingColumn[]>;
|
|
158
|
-
getExistingColumnsForTable(tableName: string): Promise<TExistingColumn[]>;
|
|
159
|
-
syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
|
|
160
|
-
recreateTable(): Promise<void>;
|
|
161
|
-
afterSyncTable(): Promise<void>;
|
|
162
|
-
/**
|
|
163
|
-
* Resets IDENTITY sequences to MAX(column) so that the next auto-generated
|
|
164
|
-
* value doesn't conflict with existing data. PostgreSQL's GENERATED BY DEFAULT
|
|
165
|
-
* AS IDENTITY does not advance the sequence when rows are inserted with explicit
|
|
166
|
-
* values, so this is needed after data seeding, bulk imports, or recreateTable().
|
|
167
|
-
*/
|
|
168
|
-
private _resetIdentitySequences;
|
|
169
|
-
tableExists(): Promise<boolean>;
|
|
170
|
-
dropTable(): Promise<void>;
|
|
171
|
-
dropColumns(columns: string[]): Promise<void>;
|
|
172
|
-
dropTableByName(tableName: string): Promise<void>;
|
|
173
|
-
dropViewByName(viewName: string): Promise<void>;
|
|
174
|
-
renameTable(oldName: string): Promise<void>;
|
|
175
|
-
typeMapper(field: TDbFieldMeta): string;
|
|
176
|
-
syncIndexes(): Promise<void>;
|
|
177
|
-
syncForeignKeys(): Promise<void>;
|
|
178
|
-
dropForeignKeys(fkFieldKeys: string[]): Promise<void>;
|
|
179
|
-
/** Queries information_schema for existing FK constraints. */
|
|
180
|
-
private _getExistingFkConstraints;
|
|
181
|
-
getSearchIndexes(): TSearchIndexInfo[];
|
|
182
|
-
search(text: string, query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
|
|
183
|
-
searchWithCount(text: string, query: DbQuery, indexName?: string): Promise<{
|
|
184
|
-
data: Array<Record<string, unknown>>;
|
|
185
|
-
count: number;
|
|
186
|
-
}>;
|
|
187
|
-
private _buildSearchWhere;
|
|
188
|
-
/** Builds the tsvector SQL expression for a fulltext index's fields. Must match between index DDL and queries. */
|
|
189
|
-
private _buildTsvectorExpr;
|
|
190
|
-
private _getFulltextIndex;
|
|
191
|
-
/**
|
|
192
|
-
* Detects pgvector support by attempting to enable the extension.
|
|
193
|
-
* Idempotent — safe to call multiple times.
|
|
194
|
-
*/
|
|
195
|
-
private _detectVectorSupport;
|
|
196
|
-
isVectorSearchable(): boolean;
|
|
197
|
-
vectorSearch(vector: number[], query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
|
|
198
|
-
vectorSearchWithCount(vector: number[], query: DbQuery, indexName?: string): Promise<{
|
|
199
|
-
data: Array<Record<string, unknown>>;
|
|
200
|
-
count: number;
|
|
201
|
-
}>;
|
|
202
|
-
/** Resolves vector field and computes shared context for vector search SQL builders. */
|
|
203
|
-
private _prepareVectorSearch;
|
|
204
|
-
private _buildVectorSearchQuery;
|
|
205
|
-
private _buildVectorSearchCountQuery;
|
|
206
|
-
/** Resolves threshold: query-time $threshold > schema-level @db.search.vector.threshold. */
|
|
207
|
-
private _resolveVectorThreshold;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* {@link TPgDriver} implementation backed by `pg` (node-postgres).
|
|
212
|
-
*
|
|
213
|
-
* Accepts a connection URI string, a `pg.PoolConfig` object, or a pre-created
|
|
214
|
-
* `pg.Pool` instance.
|
|
215
|
-
*
|
|
216
|
-
* ```typescript
|
|
217
|
-
* import { PgDriver } from '@atscript/db-postgres'
|
|
218
|
-
*
|
|
219
|
-
* // Connection URI
|
|
220
|
-
* const driver = new PgDriver('postgresql://user:pass@localhost:5432/mydb')
|
|
221
|
-
*
|
|
222
|
-
* // Pool options
|
|
223
|
-
* const driver = new PgDriver({
|
|
224
|
-
* host: 'localhost',
|
|
225
|
-
* user: 'postgres',
|
|
226
|
-
* database: 'mydb',
|
|
227
|
-
* max: 10,
|
|
228
|
-
* })
|
|
229
|
-
*
|
|
230
|
-
* // Pre-created pool
|
|
231
|
-
* import pg from 'pg'
|
|
232
|
-
* const pool = new pg.Pool({ connectionString: '...' })
|
|
233
|
-
* const driver = new PgDriver(pool)
|
|
234
|
-
* ```
|
|
235
|
-
*
|
|
236
|
-
* Requires `pg` to be installed:
|
|
237
|
-
* ```bash
|
|
238
|
-
* pnpm add pg
|
|
239
|
-
* ```
|
|
240
|
-
*/
|
|
241
|
-
declare class PgDriver implements TPgDriver {
|
|
242
|
-
private pool;
|
|
243
|
-
private poolInit;
|
|
244
|
-
constructor(poolOrConfig: string | pg.Pool | pg.PoolConfig);
|
|
245
|
-
private getPool;
|
|
246
|
-
run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
|
|
247
|
-
all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
248
|
-
get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
249
|
-
exec(sql: string): Promise<void>;
|
|
250
|
-
getConnection(): Promise<TPgConnection>;
|
|
251
|
-
close(): Promise<void>;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
declare const PostgresPlugin: () => TAtscriptPlugin;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Translates a filter expression into a parameterized PostgreSQL WHERE clause.
|
|
258
|
-
*
|
|
259
|
-
* Note: The returned fragment uses `?` placeholders (not `$N`).
|
|
260
|
-
* Finalization to `$N` happens when the fragment is consumed by a DML builder
|
|
261
|
-
* (buildSelect, buildUpdate, etc.) via the dialect's `paramPlaceholder`.
|
|
262
|
-
*
|
|
263
|
-
* Case-insensitive columns (`@db.collate 'nocase'`) are handled by CITEXT
|
|
264
|
-
* column type at the storage level — no query-side wrapping needed.
|
|
265
|
-
*/
|
|
266
|
-
declare function buildWhere(filter: FilterExpr): TSqlFragment;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Creates a {@link DbSpace} backed by a PostgreSQL connection pool.
|
|
270
|
-
*
|
|
271
|
-
* @param uri - PostgreSQL connection URI (e.g., `postgresql://user@localhost:5432/mydb`)
|
|
272
|
-
* @param options - Additional pool options passed to pg.
|
|
273
|
-
* @returns A `DbSpace` that creates `PostgresAdapter` instances per table.
|
|
274
|
-
*/
|
|
275
|
-
declare function createAdapter(uri: string, options?: Record<string, unknown>): DbSpace;
|
|
276
|
-
|
|
277
|
-
export { PgDriver, PostgresAdapter, PostgresPlugin, buildWhere, createAdapter };
|
|
278
|
-
export type { TPgConnection, TPgDriver, TPgRunResult };
|