@tstdl/base 0.92.72 → 0.92.74
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,6 +1,6 @@
|
|
|
1
1
|
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
2
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
3
|
-
import {
|
|
3
|
+
import type { PoolConfig } from 'pg';
|
|
4
4
|
import type { Resolvable, resolveArgumentType } from '../../injector/interfaces.js';
|
|
5
5
|
export type DatabaseArgument = PoolConfig;
|
|
6
6
|
export declare class Database extends NodePgDatabase<any> implements Resolvable<DatabaseArgument> {
|
package/orm/server/database.js
CHANGED
|
@@ -6,7 +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
|
|
9
|
+
import pg from 'pg';
|
|
10
10
|
import { inject, Injector, ReplaceClass } from '../../injector/index.js';
|
|
11
11
|
import { isUndefined } from '../../utils/type-guards.js';
|
|
12
12
|
import { DatabaseConfig } from './module.js';
|
|
@@ -20,9 +20,9 @@ Injector.registerSingleton(Database, {
|
|
|
20
20
|
useFactory: (argument, context) => {
|
|
21
21
|
const connection = argument ?? inject(DatabaseConfig, undefined, { optional: true })?.connection;
|
|
22
22
|
if (isUndefined(connection)) {
|
|
23
|
-
throw new Error('Missing postgres connection. Provide it either via injection argument or provider.');
|
|
23
|
+
throw new Error('Missing postgres connection. Provide it either via injection argument or a provider for DatabaseConfig.');
|
|
24
24
|
}
|
|
25
|
-
const pool = new Pool(connection);
|
|
25
|
+
const pool = new pg.Pool(connection);
|
|
26
26
|
context.addDisposeHandler(async () => pool.end());
|
|
27
27
|
return drizzle(pool);
|
|
28
28
|
}
|
|
@@ -89,7 +89,7 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
89
89
|
protected mapManyToInsertColumns(objects: (DeepPartial<T> | NewEntity<T>)[], transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType<string, EntityType>>[]>;
|
|
90
90
|
protected mapToInsertColumns(obj: DeepPartial<T> | NewEntity<T>, transformContext: TransformContext): Promise<PgInsertValue<PgTableFromType<string, EntityType>>>;
|
|
91
91
|
protected mapUpdate(update: EntityUpdate<T>, transformContext: TransformContext): Promise<PgUpdateSetSource<PgTableFromType<string, EntityType>>>;
|
|
92
|
-
protected getIdLimitQuery(query: Query<T>): import("drizzle-orm/pg-core").
|
|
92
|
+
protected getIdLimitQuery(query: Query<T>): Omit<import("drizzle-orm/pg-core").PgSelectBase<string, {
|
|
93
93
|
id: PgColumn<{
|
|
94
94
|
name: string;
|
|
95
95
|
tableName: string;
|
|
@@ -107,7 +107,27 @@ export declare class EntityRepository<T extends Entity = Entity> implements Reso
|
|
|
107
107
|
identity: undefined;
|
|
108
108
|
generated: undefined;
|
|
109
109
|
}, {}, {}>;
|
|
110
|
-
}, "
|
|
110
|
+
}, "partial", globalThis.Record<string, "not-null">, false, "where" | "limit", {
|
|
111
|
+
id: string;
|
|
112
|
+
}[], {
|
|
113
|
+
id: PgColumn<{
|
|
114
|
+
name: string;
|
|
115
|
+
tableName: string;
|
|
116
|
+
dataType: "string";
|
|
117
|
+
columnType: "PgUUID";
|
|
118
|
+
data: string;
|
|
119
|
+
driverParam: string;
|
|
120
|
+
notNull: true;
|
|
121
|
+
hasDefault: true;
|
|
122
|
+
isPrimaryKey: true;
|
|
123
|
+
isAutoincrement: false;
|
|
124
|
+
hasRuntimeDefault: false;
|
|
125
|
+
enumValues: undefined;
|
|
126
|
+
baseColumn: never;
|
|
127
|
+
identity: undefined;
|
|
128
|
+
generated: undefined;
|
|
129
|
+
}, {}, {}>;
|
|
130
|
+
}>, "where" | "limit">;
|
|
111
131
|
protected getAttributesUpdate(attributes: EntityMetadataAttributes | undefined): SQL<unknown> | undefined;
|
|
112
132
|
protected getTransformContext(): Promise<TransformContext>;
|
|
113
133
|
}
|
package/orm/server/repository.js
CHANGED
|
@@ -268,7 +268,6 @@ let EntityRepository = class EntityRepository {
|
|
|
268
268
|
const mappedUpdate = await this.mapUpdate(update, transformContext);
|
|
269
269
|
const idQuery = this.getIdLimitQuery(query);
|
|
270
270
|
const [row] = await this.session
|
|
271
|
-
.with(idQuery)
|
|
272
271
|
.update(this.table)
|
|
273
272
|
.set(mappedUpdate)
|
|
274
273
|
.where(inArray(this.table.id, idQuery))
|
|
@@ -367,7 +366,6 @@ let EntityRepository = class EntityRepository {
|
|
|
367
366
|
async hardDeleteByQuery(query) {
|
|
368
367
|
const idQuery = this.getIdLimitQuery(query);
|
|
369
368
|
const result = await this.session
|
|
370
|
-
.with(idQuery)
|
|
371
369
|
.delete(this.table)
|
|
372
370
|
.where(inArray(this.table.id, idQuery));
|
|
373
371
|
console.log({ deleteResult: result });
|
|
@@ -439,10 +437,10 @@ let EntityRepository = class EntityRepository {
|
|
|
439
437
|
}
|
|
440
438
|
getIdLimitQuery(query) {
|
|
441
439
|
const sqlQuery = this.convertQuery(query);
|
|
442
|
-
return this.session
|
|
440
|
+
return this.session.select({ id: this.table.id })
|
|
443
441
|
.from(this.table)
|
|
444
442
|
.where(sqlQuery)
|
|
445
|
-
.limit(1)
|
|
443
|
+
.limit(1);
|
|
446
444
|
}
|
|
447
445
|
getAttributesUpdate(attributes) {
|
|
448
446
|
if (isUndefined(attributes)) {
|