@holo-js/db-postgres 0.3.21 → 0.3.22
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 +7 -5
- package/dist/index.mjs +11 -5
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { PoolConfig
|
|
1
|
+
import { PoolConfig } from 'pg';
|
|
2
2
|
import { DriverAdapter, DriverQueryResult, DriverExecutionResult, DatabaseDriverFactory } from '@holo-js/db';
|
|
3
3
|
export { DriverAdapter, DriverExecutionResult, DriverQueryResult } from '@holo-js/db';
|
|
4
4
|
|
|
5
|
+
type PostgresQueryResult = {
|
|
6
|
+
rows: Record<string, unknown>[];
|
|
7
|
+
rowCount?: number | null;
|
|
8
|
+
};
|
|
5
9
|
interface PostgresQueryableLike {
|
|
6
|
-
query(sql: string, bindings?: readonly unknown[]): Promise<
|
|
7
|
-
rows: Record<string, unknown>[];
|
|
8
|
-
rowCount?: number | null;
|
|
9
|
-
}>;
|
|
10
|
+
query(sql: string, bindings?: readonly unknown[]): Promise<PostgresQueryResult | PostgresQueryResult[]>;
|
|
10
11
|
}
|
|
11
12
|
interface PostgresClientLike extends PostgresQueryableLike {
|
|
12
13
|
release?(): void;
|
|
@@ -47,6 +48,7 @@ declare class PostgresAdapter<TConfig extends PoolConfig = PoolConfig> implement
|
|
|
47
48
|
rollbackToSavepoint(name: string): Promise<void>;
|
|
48
49
|
releaseSavepoint(name: string): Promise<void>;
|
|
49
50
|
private getQueryable;
|
|
51
|
+
private queryResult;
|
|
50
52
|
ensureDatabaseExists(): Promise<void>;
|
|
51
53
|
private normalizeSavepointName;
|
|
52
54
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,9 @@ import { holoRuntimeInternals } from "@holo-js/db";
|
|
|
3
3
|
import { Pool, types } from "pg";
|
|
4
4
|
var TransactionError = class extends Error {
|
|
5
5
|
};
|
|
6
|
+
function finalQueryResult(result) {
|
|
7
|
+
return Array.isArray(result) ? result.at(-1) ?? { rows: [], rowCount: 0 } : result;
|
|
8
|
+
}
|
|
6
9
|
function quoteDatabaseIdentifier(database) {
|
|
7
10
|
return `"${database.replaceAll('"', '""')}"`;
|
|
8
11
|
}
|
|
@@ -116,8 +119,7 @@ var PostgresAdapter = class {
|
|
|
116
119
|
return this.transactionClients.run(callback);
|
|
117
120
|
}
|
|
118
121
|
async query(sql, bindings = []) {
|
|
119
|
-
const
|
|
120
|
-
const result = await client.query(sql, bindings);
|
|
122
|
+
const result = await this.queryResult(sql, bindings);
|
|
121
123
|
return {
|
|
122
124
|
rows: result.rows,
|
|
123
125
|
rowCount: result.rowCount ?? result.rows.length
|
|
@@ -127,8 +129,7 @@ var PostgresAdapter = class {
|
|
|
127
129
|
return this.query(sql, bindings);
|
|
128
130
|
}
|
|
129
131
|
async execute(sql, bindings = []) {
|
|
130
|
-
const
|
|
131
|
-
const result = await client.query(sql, bindings);
|
|
132
|
+
const result = await this.queryResult(sql, bindings);
|
|
132
133
|
const firstRow = result.rows[0];
|
|
133
134
|
const firstValue = firstRow ? Object.values(firstRow)[0] : void 0;
|
|
134
135
|
return {
|
|
@@ -173,6 +174,11 @@ var PostgresAdapter = class {
|
|
|
173
174
|
}
|
|
174
175
|
return this.pool;
|
|
175
176
|
}
|
|
177
|
+
async queryResult(sql, bindings) {
|
|
178
|
+
const client = await this.getQueryable();
|
|
179
|
+
const result = await client.query(sql, bindings);
|
|
180
|
+
return finalQueryResult(result);
|
|
181
|
+
}
|
|
176
182
|
async ensureDatabaseExists() {
|
|
177
183
|
if (!this.createPoolInstance) {
|
|
178
184
|
return;
|
|
@@ -183,7 +189,7 @@ var PostgresAdapter = class {
|
|
|
183
189
|
}
|
|
184
190
|
const bootstrapPool = this.createPoolInstance(target.config);
|
|
185
191
|
try {
|
|
186
|
-
const existing = await bootstrapPool.query("select 1 from pg_database where datname = $1", [target.database]);
|
|
192
|
+
const existing = finalQueryResult(await bootstrapPool.query("select 1 from pg_database where datname = $1", [target.database]));
|
|
187
193
|
if (existing.rows.length === 0) {
|
|
188
194
|
await bootstrapPool.query(`create database ${quoteDatabaseIdentifier(target.database)}`);
|
|
189
195
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/db-postgres",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22",
|
|
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.3.
|
|
27
|
+
"@holo-js/db": "^0.3.22"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"pg": "^8.13.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@holo-js/db": "^0.3.
|
|
33
|
+
"@holo-js/db": "^0.3.22",
|
|
34
34
|
"@types/pg": "^8.11.0",
|
|
35
35
|
"tsup": "^8.3.5",
|
|
36
36
|
"typescript": "^5.7.2",
|