@holo-js/db-postgres 0.1.9 → 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/dist/index.d.ts +2 -1
- package/dist/index.mjs +10 -8
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ declare class PostgresAdapter implements DriverAdapter {
|
|
|
34
34
|
private readonly transactionScope;
|
|
35
35
|
constructor(options?: PostgresAdapterOptions);
|
|
36
36
|
initialize(): Promise<void>;
|
|
37
|
+
isDatabaseMissingError(error: unknown): boolean;
|
|
37
38
|
disconnect(): Promise<void>;
|
|
38
39
|
isConnected(): boolean;
|
|
39
40
|
runWithTransactionScope<T>(callback: () => Promise<T>): Promise<T>;
|
|
@@ -47,7 +48,7 @@ declare class PostgresAdapter implements DriverAdapter {
|
|
|
47
48
|
rollbackToSavepoint(name: string): Promise<void>;
|
|
48
49
|
releaseSavepoint(name: string): Promise<void>;
|
|
49
50
|
private getQueryable;
|
|
50
|
-
|
|
51
|
+
ensureDatabaseExists(): Promise<void>;
|
|
51
52
|
private leaseTransactionClient;
|
|
52
53
|
private requireTransactionClient;
|
|
53
54
|
private releaseTransactionClient;
|
package/dist/index.mjs
CHANGED
|
@@ -68,11 +68,13 @@ var PostgresAdapter = class {
|
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
if (this.createPoolInstance) {
|
|
71
|
-
await this.ensureDatabaseExists();
|
|
72
71
|
this.pool = this.createPoolInstance(this.config);
|
|
73
72
|
}
|
|
74
73
|
this.connected = true;
|
|
75
74
|
}
|
|
75
|
+
isDatabaseMissingError(error) {
|
|
76
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "3D000";
|
|
77
|
+
}
|
|
76
78
|
async disconnect() {
|
|
77
79
|
if (!this.connected) {
|
|
78
80
|
return;
|
|
@@ -102,8 +104,7 @@ var PostgresAdapter = class {
|
|
|
102
104
|
if (this.directClient) {
|
|
103
105
|
return this.transactionScope.run({
|
|
104
106
|
client: this.directClient,
|
|
105
|
-
leased: false
|
|
106
|
-
released: false
|
|
107
|
+
leased: false
|
|
107
108
|
}, callback);
|
|
108
109
|
}
|
|
109
110
|
if (!this.pool) {
|
|
@@ -111,8 +112,7 @@ var PostgresAdapter = class {
|
|
|
111
112
|
}
|
|
112
113
|
const state = {
|
|
113
114
|
client: await this.pool.connect(),
|
|
114
|
-
leased: true
|
|
115
|
-
released: false
|
|
115
|
+
leased: true
|
|
116
116
|
};
|
|
117
117
|
return this.transactionScope.run(state, async () => {
|
|
118
118
|
try {
|
|
@@ -199,7 +199,10 @@ var PostgresAdapter = class {
|
|
|
199
199
|
}
|
|
200
200
|
} catch (error) {
|
|
201
201
|
const message = error instanceof Error ? error.message : String(error);
|
|
202
|
-
throw new Error(
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Postgres database "${target.database}" could not be found or created. Please create the database and try again. Original error: ${message}`,
|
|
204
|
+
{ cause: error }
|
|
205
|
+
);
|
|
203
206
|
} finally {
|
|
204
207
|
await bootstrapPool.end();
|
|
205
208
|
}
|
|
@@ -243,11 +246,10 @@ var PostgresAdapter = class {
|
|
|
243
246
|
this.leasedTransactionClient = false;
|
|
244
247
|
}
|
|
245
248
|
releaseScopedTransaction(state) {
|
|
246
|
-
if (!state.leased
|
|
249
|
+
if (!state.leased) {
|
|
247
250
|
return;
|
|
248
251
|
}
|
|
249
252
|
state.client.release?.();
|
|
250
|
-
state.released = true;
|
|
251
253
|
}
|
|
252
254
|
normalizeSavepointName(name) {
|
|
253
255
|
if (!/^[A-Z_]\w*$/i.test(name)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/db-postgres",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Holo-JS Framework - Postgres database adapter",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"test:integration": "HOLO_POSTGRES_INTEGRATION=1 vitest --run tests/postgres.test.ts"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@holo-js/db": "^0.
|
|
27
|
+
"@holo-js/db": "^0.2.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"pg": "^8.13.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@holo-js/db": "^0.
|
|
33
|
+
"@holo-js/db": "^0.2.0",
|
|
34
34
|
"@types/pg": "^8.11.0",
|
|
35
35
|
"tsup": "^8.3.5",
|
|
36
36
|
"typescript": "^5.7.2",
|