@mikro-orm/postgresql 7.0.17 → 7.0.18-dev.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/PostgreSqlConnection.d.ts +3 -0
- package/PostgreSqlConnection.js +38 -14
- package/PostgreSqlEntityManager.d.ts +2 -13
- package/PostgreSqlEntityManager.js +2 -19
- package/PostgreSqlMikroORM.d.ts +4 -4
- package/PostgreSqlPlatform.d.ts +0 -1
- package/PostgreSqlPlatform.js +0 -19
- package/README.md +2 -1
- 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
|
@@ -2,7 +2,7 @@ import { Pool, TypeOverrides } from 'pg';
|
|
|
2
2
|
import Cursor from 'pg-cursor';
|
|
3
3
|
import { PostgresDialect } from 'kysely';
|
|
4
4
|
import array from 'postgres-array';
|
|
5
|
-
import { AbstractSqlConnection, Utils } from '@mikro-orm/sql';
|
|
5
|
+
import { AbstractSqlConnection, createPostgreSqlTypeParsers, Utils } from '@mikro-orm/sql';
|
|
6
6
|
/** PostgreSQL database connection using the `pg` driver. */
|
|
7
7
|
export class PostgreSqlConnection extends AbstractSqlConnection {
|
|
8
8
|
createKyselyDialect(overrides) {
|
|
@@ -21,21 +21,45 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
|
|
|
21
21
|
const pool = this.config.get('pool');
|
|
22
22
|
Utils.defaultValue(ret, 'max', pool?.max);
|
|
23
23
|
Utils.defaultValue(ret, 'idleTimeoutMillis', pool?.idleTimeoutMillis);
|
|
24
|
-
// use `select typname, oid, typarray from pg_type order by oid` to get the list of OIDs
|
|
25
24
|
const types = new TypeOverrides();
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
1184, // timestamptz
|
|
30
|
-
1186, // interval
|
|
31
|
-
].forEach(oid => types.setTypeParser(oid, str => str));
|
|
32
|
-
[
|
|
33
|
-
1182, // date[]
|
|
34
|
-
1115, // timestamp[]
|
|
35
|
-
1185, // timestamptz[]
|
|
36
|
-
1187, // interval[]
|
|
37
|
-
].forEach(oid => types.setTypeParser(oid, str => array.parse(str)));
|
|
25
|
+
for (const [oid, parser] of Object.entries(createPostgreSqlTypeParsers(s => array.parse(s)))) {
|
|
26
|
+
types.setTypeParser(Number(oid), parser);
|
|
27
|
+
}
|
|
38
28
|
ret.types = types;
|
|
39
29
|
return Utils.mergeConfig(ret, overrides);
|
|
40
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
|
+
}
|
|
41
65
|
}
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SqlEntityManager } from '@mikro-orm/sql';
|
|
1
|
+
import { BasePostgreSqlEntityManager } from '@mikro-orm/sql';
|
|
3
2
|
import type { PostgreSqlDriver } from './PostgreSqlDriver.js';
|
|
4
3
|
/**
|
|
5
4
|
* @inheritDoc
|
|
6
5
|
*/
|
|
7
|
-
export declare class PostgreSqlEntityManager<Driver extends PostgreSqlDriver = PostgreSqlDriver> extends
|
|
8
|
-
/**
|
|
9
|
-
* Refreshes a materialized view.
|
|
10
|
-
*
|
|
11
|
-
* @param entityName - The entity name or class of the materialized view
|
|
12
|
-
* @param options - Optional settings
|
|
13
|
-
* @param options.concurrently - If true, refreshes the view concurrently (requires a unique index on the view)
|
|
14
|
-
*/
|
|
15
|
-
refreshMaterializedView<Entity extends object>(entityName: EntityName<Entity>, options?: {
|
|
16
|
-
concurrently?: boolean;
|
|
17
|
-
}): Promise<void>;
|
|
6
|
+
export declare class PostgreSqlEntityManager<Driver extends PostgreSqlDriver = PostgreSqlDriver> extends BasePostgreSqlEntityManager<Driver> {
|
|
18
7
|
}
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BasePostgreSqlEntityManager } from '@mikro-orm/sql';
|
|
2
2
|
/**
|
|
3
3
|
* @inheritDoc
|
|
4
4
|
*/
|
|
5
|
-
export class PostgreSqlEntityManager extends
|
|
6
|
-
/**
|
|
7
|
-
* Refreshes a materialized view.
|
|
8
|
-
*
|
|
9
|
-
* @param entityName - The entity name or class of the materialized view
|
|
10
|
-
* @param options - Optional settings
|
|
11
|
-
* @param options.concurrently - If true, refreshes the view concurrently (requires a unique index on the view)
|
|
12
|
-
*/
|
|
13
|
-
async refreshMaterializedView(entityName, options) {
|
|
14
|
-
const meta = this.getMetadata(entityName);
|
|
15
|
-
if (!meta.view || !meta.materialized) {
|
|
16
|
-
throw new Error(`Entity ${meta.className} is not a materialized view`);
|
|
17
|
-
}
|
|
18
|
-
const helper = this.getDriver().getPlatform().getSchemaHelper();
|
|
19
|
-
const schema = meta.schema ?? this.config.get('schema');
|
|
20
|
-
const sql = helper.refreshMaterializedView(meta.tableName, schema, options?.concurrently);
|
|
21
|
-
await this.execute(sql);
|
|
22
|
-
}
|
|
5
|
+
export class PostgreSqlEntityManager extends BasePostgreSqlEntityManager {
|
|
23
6
|
}
|
package/PostgreSqlMikroORM.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { SqlMikroORM } from '@mikro-orm/sql';
|
|
|
3
3
|
import { PostgreSqlDriver } from './PostgreSqlDriver.js';
|
|
4
4
|
import type { PostgreSqlEntityManager } from './PostgreSqlEntityManager.js';
|
|
5
5
|
/** Configuration options for the PostgreSQL driver. */
|
|
6
|
-
export type PostgreSqlOptions<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<PostgreSqlDriver, EM, Entities>>;
|
|
6
|
+
export type PostgreSqlOptions<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Partial<Options<PostgreSqlDriver, EM, Entities>>;
|
|
7
7
|
/** Creates a type-safe configuration object for the PostgreSQL driver. */
|
|
8
|
-
export declare function definePostgreSqlConfig<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<PostgreSqlDriver, EM, Entities>>): Partial<Options<PostgreSqlDriver, EM, Entities>>;
|
|
8
|
+
export declare function definePostgreSqlConfig<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<PostgreSqlDriver, EM, Entities>>): Partial<Options<PostgreSqlDriver, EM, Entities>>;
|
|
9
9
|
/**
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
*/
|
|
12
|
-
export declare class PostgreSqlMikroORM<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<PostgreSqlDriver, EM, Entities> {
|
|
12
|
+
export declare class PostgreSqlMikroORM<EM extends PostgreSqlEntityManager = PostgreSqlEntityManager, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends SqlMikroORM<PostgreSqlDriver, EM, Entities> {
|
|
13
13
|
/**
|
|
14
14
|
* @inheritDoc
|
|
15
15
|
*/
|
|
16
|
-
static init<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
16
|
+
static init<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager<D> = D[typeof EntityManagerType] & EntityManager<D>, Entities extends readonly (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Partial<Options<D, EM, Entities>>): Promise<MikroORM<D, EM, Entities>>;
|
|
17
17
|
/**
|
|
18
18
|
* @inheritDoc
|
|
19
19
|
*/
|
package/PostgreSqlPlatform.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export declare class PostgreSqlPlatform extends BasePostgreSqlPlatform {
|
|
|
5
5
|
convertIntervalToJSValue(value: string): unknown;
|
|
6
6
|
convertIntervalToDatabaseValue(value: IPostgresInterval): unknown;
|
|
7
7
|
unmarshallArray(value: string): string[];
|
|
8
|
-
escape(value: any): string;
|
|
9
8
|
/**
|
|
10
9
|
* @inheritDoc
|
|
11
10
|
*/
|
package/PostgreSqlPlatform.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Client } from 'pg';
|
|
2
1
|
import array from 'postgres-array';
|
|
3
2
|
import parseDate from 'postgres-date';
|
|
4
3
|
import PostgresInterval from 'postgres-interval';
|
|
@@ -17,24 +16,6 @@ export class PostgreSqlPlatform extends BasePostgreSqlPlatform {
|
|
|
17
16
|
unmarshallArray(value) {
|
|
18
17
|
return array.parse(value);
|
|
19
18
|
}
|
|
20
|
-
escape(value) {
|
|
21
|
-
if (typeof value === 'bigint') {
|
|
22
|
-
value = value.toString();
|
|
23
|
-
}
|
|
24
|
-
if (typeof value === 'string') {
|
|
25
|
-
return Client.prototype.escapeLiteral(value);
|
|
26
|
-
}
|
|
27
|
-
if (value instanceof Date) {
|
|
28
|
-
return `'${this.formatDate(value)}'`;
|
|
29
|
-
}
|
|
30
|
-
if (ArrayBuffer.isView(value)) {
|
|
31
|
-
return `E'\\\\x${value.toString('hex')}'`;
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(value)) {
|
|
34
|
-
return value.map(v => this.escape(v)).join(', ');
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
19
|
/**
|
|
39
20
|
* @inheritDoc
|
|
40
21
|
*/
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
|
|
3
3
|
</h1>
|
|
4
4
|
|
|
5
|
-
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite (including libSQL), MSSQL and Oracle databases.
|
|
5
|
+
TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL (including CockroachDB and PGlite), SQLite (including libSQL), MSSQL and Oracle databases.
|
|
6
6
|
|
|
7
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
8
8
|
|
|
@@ -19,6 +19,7 @@ Install a driver package for your database:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install @mikro-orm/postgresql # PostgreSQL
|
|
22
|
+
npm install @mikro-orm/pglite # PGlite (embedded PostgreSQL in WASM)
|
|
22
23
|
npm install @mikro-orm/mysql # MySQL
|
|
23
24
|
npm install @mikro-orm/mariadb # MariaDB
|
|
24
25
|
npm install @mikro-orm/sqlite # SQLite
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/postgresql",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.18-dev.1",
|
|
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.0.
|
|
50
|
+
"@mikro-orm/sql": "7.0.18-dev.1",
|
|
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.0.
|
|
62
|
+
"@mikro-orm/core": "7.0.18-dev.1"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">= 22.17.0"
|