@tstdl/base 0.92.70 → 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 };
|
|
@@ -136,7 +136,7 @@ function getPostgresColumn(columnName, dbSchema, propertySchema, reflectionData,
|
|
|
136
136
|
break;
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
let column = getPostgresBaseColumn(columnName, dbSchema, baseSchema, context);
|
|
139
|
+
let column = getPostgresBaseColumn(columnName, dbSchema, baseSchema, reflectionData, context);
|
|
140
140
|
if (array) {
|
|
141
141
|
column = column.array();
|
|
142
142
|
}
|
|
@@ -154,11 +154,14 @@ function getPostgresColumn(columnName, dbSchema, propertySchema, reflectionData,
|
|
|
154
154
|
}
|
|
155
155
|
return column;
|
|
156
156
|
}
|
|
157
|
-
function getPostgresBaseColumn(columnName, dbSchema, schema, context) {
|
|
157
|
+
function getPostgresBaseColumn(columnName, dbSchema, schema, reflectionData, context) {
|
|
158
158
|
if (schema instanceof DefaultSchema) {
|
|
159
|
-
const column = getPostgresBaseColumn(columnName, dbSchema, schema.schema, context);
|
|
159
|
+
const column = getPostgresBaseColumn(columnName, dbSchema, schema.schema, reflectionData, context);
|
|
160
160
|
return column.default(schema.defaultValue);
|
|
161
161
|
}
|
|
162
|
+
if (reflectionData.encrypted) {
|
|
163
|
+
return bytea(columnName);
|
|
164
|
+
}
|
|
162
165
|
if (schema instanceof UuidSchema) {
|
|
163
166
|
let column = uuid(columnName);
|
|
164
167
|
if (schema.defaultRandom) {
|
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 & {
|