@mikro-orm/postgresql 7.0.0-dev.11 → 7.0.0-dev.110

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/index.js CHANGED
@@ -1,8 +1,6 @@
1
- export * from '@mikro-orm/knex';
1
+ export * from '@mikro-orm/sql';
2
2
  export * from './PostgreSqlConnection.js';
3
3
  export * from './PostgreSqlDriver.js';
4
4
  export * from './PostgreSqlPlatform.js';
5
- export * from './PostgreSqlSchemaHelper.js';
6
- export * from './PostgreSqlExceptionConverter.js';
7
- export * from './types/index.js';
8
5
  export { PostgreSqlMikroORM as MikroORM, definePostgreSqlConfig as defineConfig, } from './PostgreSqlMikroORM.js';
6
+ export { raw } from './raw.js';
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.11",
4
+ "version": "7.0.0-dev.110",
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",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://mikro-orm.io",
40
40
  "engines": {
41
- "node": ">= 22.11.0"
41
+ "node": ">= 22.17.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "yarn clean && yarn compile && yarn copy",
@@ -50,18 +50,18 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/knex": "7.0.0-dev.11",
54
- "pg": "8.14.1",
53
+ "@mikro-orm/sql": "7.0.0-dev.110",
54
+ "kysely": "0.28.9",
55
+ "pg": "8.16.3",
56
+ "pg-cursor": "2.15.3",
55
57
  "postgres-array": "3.0.4",
56
58
  "postgres-date": "2.1.0",
57
59
  "postgres-interval": "4.0.2"
58
60
  },
59
61
  "devDependencies": {
60
- "@mikro-orm/core": "^6.4.13",
61
- "kysely": "0.28.0"
62
+ "@mikro-orm/core": "^6.6.2"
62
63
  },
63
64
  "peerDependencies": {
64
- "@mikro-orm/core": "7.0.0-dev.11",
65
- "kysely": "*"
65
+ "@mikro-orm/core": "7.0.0-dev.110"
66
66
  }
67
67
  }
package/raw.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { type AnyString, type Dictionary, type EntityKey, type RawQueryFragment, type QueryBuilder } from '@mikro-orm/sql';
2
+ import type { SelectQueryBuilder } from 'kysely';
3
+ /**
4
+ * Creates raw SQL query fragment that can be assigned to a property or part of a filter. This fragment is represented
5
+ * by `RawQueryFragment` class instance that can be serialized to a string, so it can be used both as an object value
6
+ * and key. When serialized, the fragment key gets cached and only such cached key will be recognized by the ORM.
7
+ * This adds a runtime safety to the raw query fragments.
8
+ *
9
+ * > **`raw()` helper is required since v6 to use a raw fragment in your query, both through EntityManager and QueryBuilder.**
10
+ *
11
+ * ```ts
12
+ * // as a value
13
+ * await em.find(User, { time: raw('now()') });
14
+ *
15
+ * // as a key
16
+ * await em.find(User, { [raw('lower(name)')]: name.toLowerCase() });
17
+ *
18
+ * // value can be empty array
19
+ * await em.find(User, { [raw('(select 1 = 1)')]: [] });
20
+ * ```
21
+ *
22
+ * The `raw` helper supports several signatures, you can pass in a callback that receives the current property alias:
23
+ *
24
+ * ```ts
25
+ * await em.find(User, { [raw(alias => `lower(${alias}.name)`)]: name.toLowerCase() });
26
+ * ```
27
+ *
28
+ * You can also use the `sql` tagged template function, which works the same, but supports only the simple string signature:
29
+ *
30
+ * ```ts
31
+ * await em.find(User, { [sql`lower(name)`]: name.toLowerCase() });
32
+ * ```
33
+ *
34
+ * When using inside filters, you might have to use a callback signature to create new raw instance for every filter usage.
35
+ *
36
+ * ```ts
37
+ * @Filter({ name: 'long', cond: () => ({ [raw('length(perex)')]: { $gt: 10000 } }) })
38
+ * ```
39
+ *
40
+ * The `raw` helper can be used within indexes and uniques to write database-agnostic SQL expressions. In that case, you can use `'??'` to tag your database identifiers (table name, column names, index name, ...) inside your expression, and pass those identifiers as a second parameter to the `raw` helper. Internally, those will automatically be quoted according to the database in use:
41
+ *
42
+ * ```ts
43
+ * // On postgres, will produce: create index "index custom_idx_on_name" on "library.author" ("country")
44
+ * // On mysql, will produce: create index `index custom_idx_on_name` on `library.author` (`country`)
45
+ * @Index({ name: 'custom_idx_on_name', expression: (table, columns) => raw(`create index ?? on ?? (??)`, ['custom_idx_on_name', table, columns.name]) })
46
+ * @Entity({ schema: 'library' })
47
+ * export class Author { ... }
48
+ * ```
49
+ *
50
+ * You can also use the `quote` tag function to write database-agnostic SQL expressions. The end-result is the same as using the `raw` function regarding database identifiers quoting, only to have a more elegant expression syntax:
51
+ *
52
+ * ```ts
53
+ * @Index({ name: 'custom_idx_on_name', expression: (table, columns) => quote`create index ${'custom_idx_on_name'} on ${table} (${columns.name})` })
54
+ * @Entity({ schema: 'library' })
55
+ * export class Author { ... }
56
+ * ```
57
+ */
58
+ export declare function raw<T extends object = any, R = any>(sql: SelectQueryBuilder<any, any, any> | QueryBuilder<T> | EntityKey<T> | EntityKey<T>[] | AnyString | ((alias: string) => string) | RawQueryFragment, params?: readonly unknown[] | Dictionary<unknown>): NoInfer<R>;
package/raw.js ADDED
@@ -0,0 +1,64 @@
1
+ import { raw as raw_, Utils } from '@mikro-orm/sql';
2
+ /**
3
+ * Creates raw SQL query fragment that can be assigned to a property or part of a filter. This fragment is represented
4
+ * by `RawQueryFragment` class instance that can be serialized to a string, so it can be used both as an object value
5
+ * and key. When serialized, the fragment key gets cached and only such cached key will be recognized by the ORM.
6
+ * This adds a runtime safety to the raw query fragments.
7
+ *
8
+ * > **`raw()` helper is required since v6 to use a raw fragment in your query, both through EntityManager and QueryBuilder.**
9
+ *
10
+ * ```ts
11
+ * // as a value
12
+ * await em.find(User, { time: raw('now()') });
13
+ *
14
+ * // as a key
15
+ * await em.find(User, { [raw('lower(name)')]: name.toLowerCase() });
16
+ *
17
+ * // value can be empty array
18
+ * await em.find(User, { [raw('(select 1 = 1)')]: [] });
19
+ * ```
20
+ *
21
+ * The `raw` helper supports several signatures, you can pass in a callback that receives the current property alias:
22
+ *
23
+ * ```ts
24
+ * await em.find(User, { [raw(alias => `lower(${alias}.name)`)]: name.toLowerCase() });
25
+ * ```
26
+ *
27
+ * You can also use the `sql` tagged template function, which works the same, but supports only the simple string signature:
28
+ *
29
+ * ```ts
30
+ * await em.find(User, { [sql`lower(name)`]: name.toLowerCase() });
31
+ * ```
32
+ *
33
+ * When using inside filters, you might have to use a callback signature to create new raw instance for every filter usage.
34
+ *
35
+ * ```ts
36
+ * @Filter({ name: 'long', cond: () => ({ [raw('length(perex)')]: { $gt: 10000 } }) })
37
+ * ```
38
+ *
39
+ * The `raw` helper can be used within indexes and uniques to write database-agnostic SQL expressions. In that case, you can use `'??'` to tag your database identifiers (table name, column names, index name, ...) inside your expression, and pass those identifiers as a second parameter to the `raw` helper. Internally, those will automatically be quoted according to the database in use:
40
+ *
41
+ * ```ts
42
+ * // On postgres, will produce: create index "index custom_idx_on_name" on "library.author" ("country")
43
+ * // On mysql, will produce: create index `index custom_idx_on_name` on `library.author` (`country`)
44
+ * @Index({ name: 'custom_idx_on_name', expression: (table, columns) => raw(`create index ?? on ?? (??)`, ['custom_idx_on_name', table, columns.name]) })
45
+ * @Entity({ schema: 'library' })
46
+ * export class Author { ... }
47
+ * ```
48
+ *
49
+ * You can also use the `quote` tag function to write database-agnostic SQL expressions. The end-result is the same as using the `raw` function regarding database identifiers quoting, only to have a more elegant expression syntax:
50
+ *
51
+ * ```ts
52
+ * @Index({ name: 'custom_idx_on_name', expression: (table, columns) => quote`create index ${'custom_idx_on_name'} on ${table} (${columns.name})` })
53
+ * @Entity({ schema: 'library' })
54
+ * export class Author { ... }
55
+ * ```
56
+ */
57
+ export function raw(sql, params) {
58
+ if (Utils.isObject(sql) && 'compile' in sql) {
59
+ const query = sql.compile();
60
+ const processed = query.sql.replaceAll(/\$\d+/g, '?');
61
+ return raw_(processed, query.parameters);
62
+ }
63
+ return raw_(sql, params);
64
+ }
@@ -1,8 +0,0 @@
1
- import { ExceptionConverter, type Dictionary, type DriverException } from '@mikro-orm/core';
2
- export declare class PostgreSqlExceptionConverter extends ExceptionConverter {
3
- /**
4
- * @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
5
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractPostgreSQLDriver.php
6
- */
7
- convertException(exception: Error & Dictionary): DriverException;
8
- }
@@ -1,48 +0,0 @@
1
- import { DeadlockException, ExceptionConverter, ForeignKeyConstraintViolationException, InvalidFieldNameException, NonUniqueFieldNameException, NotNullConstraintViolationException, SyntaxErrorException, TableExistsException, TableNotFoundException, UniqueConstraintViolationException, CheckConstraintViolationException, } from '@mikro-orm/core';
2
- export class PostgreSqlExceptionConverter extends ExceptionConverter {
3
- /**
4
- * @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
5
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractPostgreSQLDriver.php
6
- */
7
- convertException(exception) {
8
- if (exception.detail?.toString().trim()) {
9
- exception.message += '\n - detail: ' + exception.detail;
10
- }
11
- if (exception.hint?.toString().trim()) {
12
- exception.message += '\n - hint: ' + exception.hint;
13
- }
14
- /* v8 ignore start */
15
- switch (exception.code) {
16
- case '40001':
17
- case '40P01':
18
- return new DeadlockException(exception);
19
- case '0A000':
20
- // Foreign key constraint violations during a TRUNCATE operation
21
- // are considered "feature not supported" in PostgreSQL.
22
- if (exception.message.includes('truncate')) {
23
- return new ForeignKeyConstraintViolationException(exception);
24
- }
25
- break;
26
- case '23502':
27
- return new NotNullConstraintViolationException(exception);
28
- case '23503':
29
- return new ForeignKeyConstraintViolationException(exception);
30
- case '23505':
31
- return new UniqueConstraintViolationException(exception);
32
- case '23514':
33
- return new CheckConstraintViolationException(exception);
34
- case '42601':
35
- return new SyntaxErrorException(exception);
36
- case '42702':
37
- return new NonUniqueFieldNameException(exception);
38
- case '42703':
39
- return new InvalidFieldNameException(exception);
40
- case '42P01':
41
- return new TableNotFoundException(exception);
42
- case '42P07':
43
- return new TableExistsException(exception);
44
- }
45
- /* v8 ignore stop */
46
- return super.convertException(exception);
47
- }
48
- }
@@ -1,56 +0,0 @@
1
- import { type Dictionary } from '@mikro-orm/core';
2
- import { SchemaHelper, type AbstractSqlConnection, type CheckDef, type Column, type DatabaseSchema, type DatabaseTable, type ForeignKey, type IndexDef, type Table, type TableDifference } from '@mikro-orm/knex';
3
- export declare class PostgreSqlSchemaHelper extends SchemaHelper {
4
- static readonly DEFAULT_VALUES: {
5
- 'now()': string[];
6
- 'current_timestamp(?)': string[];
7
- "('now'::text)::timestamp(?) with time zone": string[];
8
- "('now'::text)::timestamp(?) without time zone": string[];
9
- 'null::character varying': string[];
10
- 'null::timestamp with time zone': string[];
11
- 'null::timestamp without time zone': string[];
12
- };
13
- getSchemaBeginning(charset: string, disableForeignKeys?: boolean): string;
14
- getCreateDatabaseSQL(name: string): string;
15
- getListTablesSQL(): string;
16
- getNamespaces(connection: AbstractSqlConnection): Promise<string[]>;
17
- private getIgnoredNamespacesConditionSQL;
18
- loadInformationSchema(schema: DatabaseSchema, connection: AbstractSqlConnection, tables: Table[], schemas?: string[]): Promise<void>;
19
- getAllIndexes(connection: AbstractSqlConnection, tables: Table[]): Promise<Dictionary<IndexDef[]>>;
20
- getAllColumns(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>, nativeEnums?: Dictionary<{
21
- name: string;
22
- schema?: string;
23
- items: string[];
24
- }>): Promise<Dictionary<Column[]>>;
25
- getAllChecks(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<CheckDef[]>>;
26
- getAllForeignKeys(connection: AbstractSqlConnection, tablesBySchemas: Map<string | undefined, Table[]>): Promise<Dictionary<Dictionary<ForeignKey>>>;
27
- getNativeEnumDefinitions(connection: AbstractSqlConnection, schemas: string[]): Promise<Dictionary<{
28
- name: string;
29
- schema?: string;
30
- items: string[];
31
- }>>;
32
- getCreateNativeEnumSQL(name: string, values: unknown[], schema?: string): string;
33
- getDropNativeEnumSQL(name: string, schema?: string): string;
34
- getAlterNativeEnumSQL(name: string, schema?: string, value?: string, items?: string[], oldItems?: string[]): string;
35
- private getEnumDefinitions;
36
- createTableColumn(column: Column, table: DatabaseTable): string | undefined;
37
- getPreAlterTable(tableDiff: TableDifference, safe: boolean): string[];
38
- castColumn(name: string, type: string): string;
39
- dropForeignKey(tableName: string, constraintName: string): string;
40
- getPostAlterTable(tableDiff: TableDifference, safe: boolean): string[];
41
- private getAlterColumnAutoincrement;
42
- getChangeColumnCommentSQL(tableName: string, to: Column, schemaName?: string): string;
43
- alterTableComment(table: DatabaseTable, comment?: string): string;
44
- normalizeDefaultValue(defaultValue: string, length: number): string | number;
45
- appendComments(table: DatabaseTable): string[];
46
- getDatabaseExistsSQL(name: string): string;
47
- getDatabaseNotExistsError(dbName: string): string;
48
- getManagementDbName(): string;
49
- disableForeignKeysSQL(): string;
50
- enableForeignKeysSQL(): string;
51
- getRenameIndexSQL(tableName: string, index: IndexDef, oldIndexName: string): string[];
52
- dropIndex(table: string, index: IndexDef, oldIndexName?: string): string;
53
- private getIndexesSQL;
54
- private getChecksSQL;
55
- inferLengthFromColumnType(type: string): number | undefined;
56
- }