@holo-js/db-postgres 0.2.6 → 0.3.1

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PoolConfig, QueryResult } from 'pg';
2
- import { DriverAdapter, DriverQueryResult, DriverExecutionResult } from '@holo-js/db';
2
+ import { DriverAdapter, DriverQueryResult, DriverExecutionResult, DatabaseDriverFactory } from '@holo-js/db';
3
3
  export { DriverAdapter, DriverExecutionResult, DriverQueryResult } from '@holo-js/db';
4
4
 
5
5
  interface PostgresQueryableLike {
@@ -16,14 +16,15 @@ interface PostgresPoolLike extends PostgresQueryableLike {
16
16
  connect(): Promise<PostgresClientLike>;
17
17
  end(): Promise<void>;
18
18
  }
19
- interface PostgresAdapterOptions {
19
+ interface PostgresAdapterOptions<TConfig extends PoolConfig = PoolConfig> {
20
20
  connectionString?: string;
21
- config?: PoolConfig;
21
+ config?: TConfig;
22
22
  client?: PostgresClientLike;
23
23
  pool?: PostgresPoolLike;
24
- createPool?: (config?: PoolConfig) => PostgresPoolLike;
24
+ createPool?: (config?: TConfig) => PostgresPoolLike;
25
25
  }
26
- declare class PostgresAdapter implements DriverAdapter {
26
+ declare class PostgresAdapter<TConfig extends PoolConfig = PoolConfig> implements DriverAdapter {
27
+ readonly supportsConcurrentTransactionScopes = true;
27
28
  private pool?;
28
29
  private readonly directClient?;
29
30
  private readonly createPoolInstance?;
@@ -32,7 +33,7 @@ declare class PostgresAdapter implements DriverAdapter {
32
33
  private transactionClient?;
33
34
  private leasedTransactionClient;
34
35
  private readonly transactionScope;
35
- constructor(options?: PostgresAdapterOptions);
36
+ constructor(options?: PostgresAdapterOptions<TConfig>);
36
37
  initialize(): Promise<void>;
37
38
  isDatabaseMissingError(error: unknown): boolean;
38
39
  disconnect(): Promise<void>;
@@ -55,6 +56,7 @@ declare class PostgresAdapter implements DriverAdapter {
55
56
  private releaseScopedTransaction;
56
57
  private normalizeSavepointName;
57
58
  }
58
- declare function createPostgresAdapter(options?: PostgresAdapterOptions): PostgresAdapter;
59
+ declare function createPostgresAdapter<TConfig extends PoolConfig = PoolConfig>(options?: PostgresAdapterOptions<TConfig>): PostgresAdapter<TConfig>;
60
+ declare const postgresDatabaseDriverFactory: DatabaseDriverFactory;
59
61
 
60
- export { PostgresAdapter, type PostgresAdapterOptions, type PostgresClientLike, type PostgresPoolLike, type PostgresQueryableLike, createPostgresAdapter };
62
+ export { PostgresAdapter, type PostgresAdapterOptions, type PostgresClientLike, type PostgresPoolLike, type PostgresQueryableLike, createPostgresAdapter, postgresDatabaseDriverFactory };
package/dist/index.mjs CHANGED
@@ -48,6 +48,7 @@ function resolveBootstrapTarget(config) {
48
48
  return void 0;
49
49
  }
50
50
  var PostgresAdapter = class {
51
+ supportsConcurrentTransactionScopes = true;
51
52
  pool;
52
53
  directClient;
53
54
  createPoolInstance;
@@ -103,16 +104,14 @@ var PostgresAdapter = class {
103
104
  await this.initialize();
104
105
  if (this.directClient) {
105
106
  return this.transactionScope.run({
106
- client: this.directClient,
107
- leased: false
107
+ client: this.directClient
108
108
  }, callback);
109
109
  }
110
110
  if (!this.pool) {
111
111
  throw new TransactionError("Postgres adapter is not initialized with a pool or client.");
112
112
  }
113
113
  const state = {
114
- client: await this.pool.connect(),
115
- leased: true
114
+ client: await this.pool.connect()
116
115
  };
117
116
  return this.transactionScope.run(state, async () => {
118
117
  try {
@@ -246,9 +245,6 @@ var PostgresAdapter = class {
246
245
  this.leasedTransactionClient = false;
247
246
  }
248
247
  releaseScopedTransaction(state) {
249
- if (!state.leased) {
250
- return;
251
- }
252
248
  state.client.release?.();
253
249
  }
254
250
  normalizeSavepointName(name) {
@@ -261,7 +257,22 @@ var PostgresAdapter = class {
261
257
  function createPostgresAdapter(options = {}) {
262
258
  return new PostgresAdapter(options);
263
259
  }
260
+ var postgresDatabaseDriverFactory = Object.freeze({
261
+ driver: "postgres",
262
+ supportsConcurrentTransactionScopes: true,
263
+ create(connection) {
264
+ return connection.url ? createPostgresAdapter({ connectionString: connection.url }) : createPostgresAdapter({ config: {
265
+ host: connection.host,
266
+ port: connection.port,
267
+ user: connection.username,
268
+ password: connection.password,
269
+ database: connection.database,
270
+ ssl: connection.ssl
271
+ } });
272
+ }
273
+ });
264
274
  export {
265
275
  PostgresAdapter,
266
- createPostgresAdapter
276
+ createPostgresAdapter,
277
+ postgresDatabaseDriverFactory
267
278
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@holo-js/db-postgres",
3
- "version": "0.2.6",
3
+ "version": "0.3.1",
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.2.6"
27
+ "@holo-js/db": "^0.3.1"
28
28
  },
29
29
  "dependencies": {
30
30
  "pg": "^8.13.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@holo-js/db": "^0.2.6",
33
+ "@holo-js/db": "^0.3.1",
34
34
  "@types/pg": "^8.11.0",
35
35
  "tsup": "^8.3.5",
36
36
  "typescript": "^5.7.2",