@mikro-orm/postgresql 7.1.0-dev.42 → 7.1.0-dev.44
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/PostgreSqlConnection.d.ts +3 -0
- package/PostgreSqlConnection.js +34 -0
- package/package.json +3 -3
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type PoolConfig } from 'pg';
|
|
2
2
|
import { PostgresDialect } from 'kysely';
|
|
3
|
+
import { type Routine, type Transaction } from '@mikro-orm/core';
|
|
3
4
|
import { AbstractSqlConnection } from '@mikro-orm/sql';
|
|
4
5
|
/** PostgreSQL database connection using the `pg` driver. */
|
|
5
6
|
export declare class PostgreSqlConnection extends AbstractSqlConnection {
|
|
6
7
|
createKyselyDialect(overrides: PoolConfig): PostgresDialect;
|
|
7
8
|
mapOptions(overrides: PoolConfig): PoolConfig;
|
|
9
|
+
callRoutine<T>(routine: Routine, args?: Record<string, unknown>, ctx?: Transaction): Promise<T>;
|
|
10
|
+
private fetchRefcursors;
|
|
8
11
|
}
|
package/PostgreSqlConnection.js
CHANGED
|
@@ -28,4 +28,38 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
|
|
|
28
28
|
ret.types = types;
|
|
29
29
|
return Utils.mergeConfig(ret, overrides);
|
|
30
30
|
}
|
|
31
|
+
async callRoutine(routine, args = {}, ctx) {
|
|
32
|
+
if (routine.type === 'function') {
|
|
33
|
+
return this.callRoutineFunction(routine, args, ctx);
|
|
34
|
+
}
|
|
35
|
+
const quoted = (id) => this.platform.quoteIdentifier(id);
|
|
36
|
+
const qualified = (routine.schema ? `${quoted(routine.schema)}.` : '') + quoted(routine.name);
|
|
37
|
+
// Refcursor OUT params come back as server-generated cursor names to FETCH from later.
|
|
38
|
+
const refcursorParams = routine.params.filter(p => p.direction !== 'in' && typeof p.type === 'string' && /^refcursor$/i.test(p.type));
|
|
39
|
+
// Refcursors are transaction-scoped — fail fast instead of opening cursors we can't read.
|
|
40
|
+
if (refcursorParams.length > 0 && !ctx) {
|
|
41
|
+
throw new Error(`Routine ${routine.name} declares refcursor OUT params on PostgreSQL but was not called inside a transaction. Wrap the call in 'em.transactional(...)' so the refcursor OUT params remain valid for FETCH.`);
|
|
42
|
+
}
|
|
43
|
+
const placeholders = routine.params.map(() => '?').join(', ');
|
|
44
|
+
const positional = routine.params.map(p => this.convertRoutineInbound(args[p.name], p));
|
|
45
|
+
const rows = (await this.execute(`call ${qualified}(${placeholders})`, positional, 'all', ctx));
|
|
46
|
+
const row = rows[0] ?? {};
|
|
47
|
+
const scalarOutParams = routine.params.filter(p => p.direction !== 'in' && !refcursorParams.includes(p));
|
|
48
|
+
this.applyRoutineOutParams(row, scalarOutParams, args);
|
|
49
|
+
if (refcursorParams.length > 0) {
|
|
50
|
+
return (await this.fetchRefcursors(row, routine, refcursorParams, ctx));
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
async fetchRefcursors(row, routine, refcursorParams, ctx) {
|
|
55
|
+
const cursorNames = refcursorParams
|
|
56
|
+
.map(p => row[p.name])
|
|
57
|
+
.filter((name) => typeof name === 'string');
|
|
58
|
+
const sets = [];
|
|
59
|
+
for (const cursorName of cursorNames) {
|
|
60
|
+
const fetched = (await this.execute(`fetch all from "${cursorName.replaceAll('"', '""')}"`, [], 'all', ctx));
|
|
61
|
+
sets.push(fetched);
|
|
62
|
+
}
|
|
63
|
+
return sets;
|
|
64
|
+
}
|
|
31
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/postgresql",
|
|
3
|
-
"version": "7.1.0-dev.
|
|
3
|
+
"version": "7.1.0-dev.44",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@mikro-orm/sql": "7.1.0-dev.
|
|
50
|
+
"@mikro-orm/sql": "7.1.0-dev.44",
|
|
51
51
|
"kysely": "0.29.2",
|
|
52
52
|
"pg": "8.20.0",
|
|
53
53
|
"pg-cursor": "2.19.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@mikro-orm/core": "^7.0.17"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
|
-
"@mikro-orm/core": "7.1.0-dev.
|
|
62
|
+
"@mikro-orm/core": "7.1.0-dev.44"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">= 22.17.0"
|