@holo-js/db-postgres 0.3.21 → 0.3.23
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 +8 -6
- package/dist/index.mjs +13 -6
- 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;
|
|
@@ -24,7 +25,7 @@ interface PostgresAdapterOptions<TConfig extends PoolConfig = PoolConfig> {
|
|
|
24
25
|
createPool?: (config?: TConfig) => PostgresPoolLike;
|
|
25
26
|
}
|
|
26
27
|
declare class PostgresAdapter<TConfig extends PoolConfig = PoolConfig> implements DriverAdapter {
|
|
27
|
-
readonly supportsConcurrentTransactionScopes
|
|
28
|
+
readonly supportsConcurrentTransactionScopes: boolean;
|
|
28
29
|
private pool?;
|
|
29
30
|
private readonly directClient?;
|
|
30
31
|
private readonly createPoolInstance?;
|
|
@@ -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
|
}
|
|
@@ -48,7 +51,7 @@ function resolveBootstrapTarget(config) {
|
|
|
48
51
|
return void 0;
|
|
49
52
|
}
|
|
50
53
|
var PostgresAdapter = class {
|
|
51
|
-
supportsConcurrentTransactionScopes
|
|
54
|
+
supportsConcurrentTransactionScopes;
|
|
52
55
|
pool;
|
|
53
56
|
directClient;
|
|
54
57
|
createPoolInstance;
|
|
@@ -56,6 +59,7 @@ var PostgresAdapter = class {
|
|
|
56
59
|
connected;
|
|
57
60
|
transactionClients;
|
|
58
61
|
constructor(options = {}) {
|
|
62
|
+
this.supportsConcurrentTransactionScopes = !options.client;
|
|
59
63
|
this.directClient = options.client;
|
|
60
64
|
this.pool = options.pool;
|
|
61
65
|
this.createPoolInstance = options.createPool ?? (options.client || options.pool ? void 0 : (config) => new Pool({
|
|
@@ -116,8 +120,7 @@ var PostgresAdapter = class {
|
|
|
116
120
|
return this.transactionClients.run(callback);
|
|
117
121
|
}
|
|
118
122
|
async query(sql, bindings = []) {
|
|
119
|
-
const
|
|
120
|
-
const result = await client.query(sql, bindings);
|
|
123
|
+
const result = await this.queryResult(sql, bindings);
|
|
121
124
|
return {
|
|
122
125
|
rows: result.rows,
|
|
123
126
|
rowCount: result.rowCount ?? result.rows.length
|
|
@@ -127,8 +130,7 @@ var PostgresAdapter = class {
|
|
|
127
130
|
return this.query(sql, bindings);
|
|
128
131
|
}
|
|
129
132
|
async execute(sql, bindings = []) {
|
|
130
|
-
const
|
|
131
|
-
const result = await client.query(sql, bindings);
|
|
133
|
+
const result = await this.queryResult(sql, bindings);
|
|
132
134
|
const firstRow = result.rows[0];
|
|
133
135
|
const firstValue = firstRow ? Object.values(firstRow)[0] : void 0;
|
|
134
136
|
return {
|
|
@@ -173,6 +175,11 @@ var PostgresAdapter = class {
|
|
|
173
175
|
}
|
|
174
176
|
return this.pool;
|
|
175
177
|
}
|
|
178
|
+
async queryResult(sql, bindings) {
|
|
179
|
+
const client = await this.getQueryable();
|
|
180
|
+
const result = await client.query(sql, bindings);
|
|
181
|
+
return finalQueryResult(result);
|
|
182
|
+
}
|
|
176
183
|
async ensureDatabaseExists() {
|
|
177
184
|
if (!this.createPoolInstance) {
|
|
178
185
|
return;
|
|
@@ -183,7 +190,7 @@ var PostgresAdapter = class {
|
|
|
183
190
|
}
|
|
184
191
|
const bootstrapPool = this.createPoolInstance(target.config);
|
|
185
192
|
try {
|
|
186
|
-
const existing = await bootstrapPool.query("select 1 from pg_database where datname = $1", [target.database]);
|
|
193
|
+
const existing = finalQueryResult(await bootstrapPool.query("select 1 from pg_database where datname = $1", [target.database]));
|
|
187
194
|
if (existing.rows.length === 0) {
|
|
188
195
|
await bootstrapPool.query(`create database ${quoteDatabaseIdentifier(target.database)}`);
|
|
189
196
|
}
|
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.23",
|
|
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.23"
|
|
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.23",
|
|
34
34
|
"@types/pg": "^8.11.0",
|
|
35
35
|
"tsup": "^8.3.5",
|
|
36
36
|
"typescript": "^5.7.2",
|