@mikro-orm/postgresql 7.0.0-dev.4 → 7.0.0-dev.41
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.js +5 -5
- package/PostgreSqlMikroORM.d.ts +5 -5
- package/PostgreSqlPlatform.d.ts +3 -1
- package/PostgreSqlPlatform.js +8 -3
- package/PostgreSqlSchemaHelper.js +11 -4
- package/README.md +3 -2
- package/package.json +8 -7
package/PostgreSqlConnection.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import TypeOverrides from 'pg
|
|
2
|
-
import
|
|
1
|
+
import { Pool, TypeOverrides } from 'pg';
|
|
2
|
+
import Cursor from 'pg-cursor';
|
|
3
3
|
import { PostgresDialect } from 'kysely';
|
|
4
4
|
import array from 'postgres-array';
|
|
5
5
|
import { AbstractSqlConnection, Utils } from '@mikro-orm/knex';
|
|
@@ -8,15 +8,15 @@ export class PostgreSqlConnection extends AbstractSqlConnection {
|
|
|
8
8
|
const options = this.mapOptions(overrides);
|
|
9
9
|
return new PostgresDialect({
|
|
10
10
|
pool: new Pool(options),
|
|
11
|
+
cursor: Cursor,
|
|
11
12
|
onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
|
|
12
13
|
});
|
|
13
14
|
}
|
|
14
15
|
mapOptions(overrides) {
|
|
15
16
|
const ret = { ...this.getConnectionOptions() };
|
|
16
17
|
const pool = this.config.get('pool');
|
|
17
|
-
ret
|
|
18
|
-
ret
|
|
19
|
-
ret.idleTimeoutMillis = pool?.idleTimeoutMillis;
|
|
18
|
+
Utils.defaultValue(ret, 'max', pool?.max);
|
|
19
|
+
Utils.defaultValue(ret, 'idleTimeoutMillis', pool?.idleTimeoutMillis);
|
|
20
20
|
// use `select typname, oid, typarray from pg_type order by oid` to get the list of OIDs
|
|
21
21
|
const types = new TypeOverrides();
|
|
22
22
|
[
|
package/PostgreSqlMikroORM.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
1
|
+
import { type AnyEntity, type EntityClass, type EntityClassGroup, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
2
2
|
import { PostgreSqlDriver } from './PostgreSqlDriver.js';
|
|
3
3
|
import type { SqlEntityManager } from '@mikro-orm/knex';
|
|
4
4
|
/**
|
|
5
5
|
* @inheritDoc
|
|
6
6
|
*/
|
|
7
|
-
export declare class PostgreSqlMikroORM<EM extends EntityManager = SqlEntityManager> extends MikroORM<PostgreSqlDriver, EM> {
|
|
7
|
+
export declare class PostgreSqlMikroORM<EM extends EntityManager = SqlEntityManager> extends MikroORM<PostgreSqlDriver, EM, any> {
|
|
8
8
|
private static DRIVER;
|
|
9
9
|
/**
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
*/
|
|
12
|
-
static init<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options?: Options<D, EM>): Promise<MikroORM<D, EM>>;
|
|
12
|
+
static init<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options?: Options<D, EM, Entities>): Promise<MikroORM<D, EM, Entities>>;
|
|
13
13
|
/**
|
|
14
14
|
* @inheritDoc
|
|
15
15
|
*/
|
|
16
|
-
static initSync<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options: Options<D, EM>): MikroORM<D, EM>;
|
|
16
|
+
static initSync<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager, Entities extends (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntityClassGroup<AnyEntity> | EntitySchema)[]>(options: Options<D, EM, Entities>): MikroORM<D, EM, Entities>;
|
|
17
17
|
}
|
|
18
18
|
export type PostgreSqlOptions = Options<PostgreSqlDriver>;
|
|
19
|
-
export declare function definePostgreSqlConfig(options: PostgreSqlOptions): Options<PostgreSqlDriver, SqlEntityManager<PostgreSqlDriver> & EntityManager<IDatabaseDriver<import("@mikro-orm/core").Connection
|
|
19
|
+
export declare function definePostgreSqlConfig(options: PostgreSqlOptions): Options<PostgreSqlDriver, SqlEntityManager<PostgreSqlDriver> & EntityManager<IDatabaseDriver<import("@mikro-orm/core").Connection>>, (string | EntityClass<Partial<any>> | EntityClassGroup<Partial<any>> | EntitySchema<any, never>)[]>;
|
package/PostgreSqlPlatform.d.ts
CHANGED
|
@@ -81,7 +81,9 @@ export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
81
81
|
getJsonDeclarationSQL(): string;
|
|
82
82
|
getSearchJsonPropertyKey(path: string[], type: string | undefined | Type, aliased: boolean, value?: unknown): string;
|
|
83
83
|
getJsonIndexDefinition(index: IndexDef): string[];
|
|
84
|
-
quoteIdentifier(id: string
|
|
84
|
+
quoteIdentifier(id: string | {
|
|
85
|
+
toString: () => string;
|
|
86
|
+
}, quote?: string): string;
|
|
85
87
|
escape(value: any): string;
|
|
86
88
|
private pad;
|
|
87
89
|
/** @internal */
|
package/PostgreSqlPlatform.js
CHANGED
|
@@ -258,7 +258,7 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
258
258
|
if (RawQueryFragment.isKnownFragment(id)) {
|
|
259
259
|
return super.quoteIdentifier(id);
|
|
260
260
|
}
|
|
261
|
-
return `${quote}${id.replace('.', `${quote}.${quote}`)}${quote}`;
|
|
261
|
+
return `${quote}${id.toString().replace('.', `${quote}.${quote}`)}${quote}`;
|
|
262
262
|
}
|
|
263
263
|
escape(value) {
|
|
264
264
|
if (typeof value === 'string') {
|
|
@@ -270,6 +270,9 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
270
270
|
if (ArrayBuffer.isView(value)) {
|
|
271
271
|
return `E'\\\\x${value.toString('hex')}'`;
|
|
272
272
|
}
|
|
273
|
+
if (Array.isArray(value)) {
|
|
274
|
+
return value.map(v => this.escape(v)).join(', ');
|
|
275
|
+
}
|
|
273
276
|
return super.escape(value);
|
|
274
277
|
}
|
|
275
278
|
pad(number, digits) {
|
|
@@ -347,15 +350,17 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
347
350
|
getIndexName(tableName, columns, type) {
|
|
348
351
|
const indexName = super.getIndexName(tableName, columns, type);
|
|
349
352
|
if (indexName.length > 63) {
|
|
353
|
+
const hashAlgorithm = this.config.get('hashAlgorithm');
|
|
350
354
|
const suffix = type === 'primary' ? 'pkey' : type;
|
|
351
|
-
return `${indexName.substring(0, 55 - type.length)}_${Utils.hash(indexName, 5)}_${suffix}`;
|
|
355
|
+
return `${indexName.substring(0, 55 - type.length)}_${Utils.hash(indexName, 5, hashAlgorithm)}_${suffix}`;
|
|
352
356
|
}
|
|
353
357
|
return indexName;
|
|
354
358
|
}
|
|
355
359
|
getDefaultPrimaryName(tableName, columns) {
|
|
356
360
|
const indexName = `${tableName}_pkey`;
|
|
357
361
|
if (indexName.length > 63) {
|
|
358
|
-
|
|
362
|
+
const hashAlgorithm = this.config.get('hashAlgorithm');
|
|
363
|
+
return `${indexName.substring(0, 55 - 'pkey'.length)}_${Utils.hash(indexName, 5, hashAlgorithm)}_pkey`;
|
|
359
364
|
}
|
|
360
365
|
return indexName;
|
|
361
366
|
}
|
|
@@ -68,7 +68,9 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
68
68
|
const table = schema.addTable(t.table_name, t.schema_name, t.table_comment);
|
|
69
69
|
const pks = await this.getPrimaryKeys(connection, indexes[key], table.name, table.schema);
|
|
70
70
|
const enums = this.getEnumDefinitions(checks[key] ?? []);
|
|
71
|
-
|
|
71
|
+
if (columns[key]) {
|
|
72
|
+
table.init(columns[key], indexes[key], checks[key], pks, fks[key], enums);
|
|
73
|
+
}
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
async getAllIndexes(connection, tables) {
|
|
@@ -250,10 +252,14 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
250
252
|
if (row.schema_name && row.schema_name !== this.platform.getDefaultSchemaName()) {
|
|
251
253
|
name = row.schema_name + '.' + name;
|
|
252
254
|
}
|
|
255
|
+
let items = row.enum_value;
|
|
256
|
+
if (!Array.isArray(items)) {
|
|
257
|
+
items = this.platform.unmarshallArray(row.enum_value);
|
|
258
|
+
}
|
|
253
259
|
o[name] = {
|
|
254
260
|
name: row.enum_name,
|
|
255
261
|
schema: row.schema_name,
|
|
256
|
-
items
|
|
262
|
+
items,
|
|
257
263
|
};
|
|
258
264
|
return o;
|
|
259
265
|
}, {});
|
|
@@ -317,7 +323,8 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
317
323
|
}, {});
|
|
318
324
|
}
|
|
319
325
|
createTableColumn(column, table) {
|
|
320
|
-
const
|
|
326
|
+
const pk = table.getPrimaryKey();
|
|
327
|
+
const compositePK = pk?.composite;
|
|
321
328
|
const primaryKey = !this.hasNonDefaultPrimaryKeyName(table);
|
|
322
329
|
const col = [this.quote(column.name)];
|
|
323
330
|
if (column.autoincrement && !column.generated && !compositePK) {
|
|
@@ -347,7 +354,7 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
347
354
|
Utils.runIfNotEmpty(() => col.push('null'), column.nullable);
|
|
348
355
|
Utils.runIfNotEmpty(() => col.push('not null'), !column.nullable);
|
|
349
356
|
}
|
|
350
|
-
if (column.autoincrement && !
|
|
357
|
+
if (column.autoincrement && !compositePK) {
|
|
351
358
|
Utils.runIfNotEmpty(() => col.push('primary key'), primaryKey && column.primary);
|
|
352
359
|
}
|
|
353
360
|
const useDefault = column.default != null && column.default !== 'null' && !column.autoincrement;
|
package/README.md
CHANGED
|
@@ -11,7 +11,6 @@ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-or
|
|
|
11
11
|
[](https://discord.gg/w8bjxFHS7X)
|
|
12
12
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
13
13
|
[](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
|
|
14
|
-
[](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
|
|
15
14
|
[](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
|
|
16
15
|
|
|
17
16
|
## 🤔 Unit of What?
|
|
@@ -141,7 +140,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
|
|
|
141
140
|
- [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
|
|
142
141
|
- [Filters](https://mikro-orm.io/docs/filters)
|
|
143
142
|
- [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
|
|
144
|
-
- [
|
|
143
|
+
- [Populating relations](https://mikro-orm.io/docs/populating-relations)
|
|
145
144
|
- [Property Validation](https://mikro-orm.io/docs/property-validation)
|
|
146
145
|
- [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
|
|
147
146
|
- [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
|
|
@@ -382,6 +381,8 @@ See also the list of contributors who [participated](https://github.com/mikro-or
|
|
|
382
381
|
|
|
383
382
|
Please ⭐️ this repository if this project helped you!
|
|
384
383
|
|
|
384
|
+
> If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
|
|
385
|
+
|
|
385
386
|
## 📝 License
|
|
386
387
|
|
|
387
388
|
Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/postgresql",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.41",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -50,18 +50,19 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/knex": "7.0.0-dev.
|
|
54
|
-
"pg": "8.
|
|
55
|
-
"
|
|
53
|
+
"@mikro-orm/knex": "7.0.0-dev.41",
|
|
54
|
+
"pg": "8.16.3",
|
|
55
|
+
"pg-cursor": "2.15.3",
|
|
56
|
+
"postgres-array": "3.0.4",
|
|
56
57
|
"postgres-date": "2.1.0",
|
|
57
58
|
"postgres-interval": "4.0.2"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
|
-
"@mikro-orm/core": "^6.
|
|
61
|
-
"kysely": "
|
|
61
|
+
"@mikro-orm/core": "^6.6.0",
|
|
62
|
+
"kysely": "0.28.7"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
65
|
+
"@mikro-orm/core": "7.0.0-dev.41",
|
|
65
66
|
"kysely": "*"
|
|
66
67
|
}
|
|
67
68
|
}
|