@tstdl/base 0.92.71 → 0.92.72
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/orm/server/database.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
2
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
3
|
-
import type
|
|
3
|
+
import { type PoolConfig } from 'pg';
|
|
4
4
|
import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
5
|
-
export type DatabaseArgument =
|
|
5
|
+
export type DatabaseArgument = PoolConfig;
|
|
6
6
|
export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
|
|
7
7
|
readonly [resolveArgumentType]?: DatabaseArgument;
|
|
8
8
|
}
|
package/orm/server/database.js
CHANGED
|
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { drizzle, NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
8
8
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
9
|
+
import { Pool } from 'pg';
|
|
9
10
|
import { inject, Injector, ReplaceClass } from '../../injector/index.js';
|
|
10
11
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
11
12
|
import { DatabaseConfig } from './module.js';
|
|
@@ -16,12 +17,14 @@ Database = __decorate([
|
|
|
16
17
|
], Database);
|
|
17
18
|
export { Database };
|
|
18
19
|
Injector.registerSingleton(Database, {
|
|
19
|
-
useFactory: (argument) => {
|
|
20
|
+
useFactory: (argument, context) => {
|
|
20
21
|
const connection = argument ?? inject(DatabaseConfig, undefined, { optional: true })?.connection;
|
|
21
22
|
if (isUndefined(connection)) {
|
|
22
23
|
throw new Error('Missing postgres connection. Provide it either via injection argument or provider.');
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
+
const pool = new Pool(connection);
|
|
26
|
+
context.addDisposeHandler(async () => pool.end());
|
|
27
|
+
return drizzle(pool);
|
|
25
28
|
}
|
|
26
29
|
});
|
|
27
30
|
export { migrate };
|
package/orm/server/module.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PoolConfig } from 'pg';
|
|
2
2
|
import { EntityRepositoryConfig } from './repository.js';
|
|
3
3
|
export declare class DatabaseConfig {
|
|
4
|
-
connection?:
|
|
4
|
+
connection?: PoolConfig;
|
|
5
5
|
}
|
|
6
6
|
export type OrmModuleOptions = {
|
|
7
|
-
connection?:
|
|
7
|
+
connection?: PoolConfig;
|
|
8
8
|
repositoryConfig?: EntityRepositoryConfig;
|
|
9
9
|
};
|
|
10
10
|
export declare function configureOrm(options: OrmModuleOptions & {
|