@mikro-orm/postgresql 7.0.0-dev.17 → 7.0.0-dev.170
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 +1 -1
- package/PostgreSqlConnection.js +3 -1
- package/PostgreSqlDriver.d.ts +5 -2
- package/PostgreSqlDriver.js +6 -1
- package/PostgreSqlMikroORM.d.ts +7 -8
- package/PostgreSqlMikroORM.js +6 -8
- package/PostgreSqlPlatform.d.ts +2 -100
- package/PostgreSqlPlatform.js +12 -350
- package/README.md +3 -2
- package/index.d.ts +3 -5
- package/index.js +2 -4
- package/package.json +9 -9
- package/raw.d.ts +58 -0
- package/raw.js +64 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/PostgreSqlExceptionConverter.d.ts +0 -8
- package/PostgreSqlExceptionConverter.js +0 -48
- package/PostgreSqlSchemaHelper.d.ts +0 -56
- package/PostgreSqlSchemaHelper.js +0 -545
- package/types/FullTextType.d.ts +0 -14
- package/types/FullTextType.js +0 -59
- package/types/index.d.ts +0 -1
- package/types/index.js +0 -1
package/index.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export * from '@mikro-orm/
|
|
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.
|
|
4
|
+
"version": "7.0.0-dev.170",
|
|
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,10 +38,10 @@
|
|
|
38
38
|
},
|
|
39
39
|
"homepage": "https://mikro-orm.io",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">= 22.
|
|
41
|
+
"node": ">= 22.17.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "yarn
|
|
44
|
+
"build": "yarn compile && yarn copy",
|
|
45
45
|
"clean": "yarn run -T rimraf ./dist",
|
|
46
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
@@ -50,18 +50,18 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/
|
|
54
|
-
"
|
|
53
|
+
"@mikro-orm/sql": "7.0.0-dev.170",
|
|
54
|
+
"kysely": "0.28.10",
|
|
55
|
+
"pg": "8.17.2",
|
|
56
|
+
"pg-cursor": "2.16.2",
|
|
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
|
|
61
|
-
"kysely": "0.28.2"
|
|
62
|
+
"@mikro-orm/core": "^6.6.4"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
|
-
"@mikro-orm/core": "7.0.0-dev.
|
|
65
|
-
"kysely": "*"
|
|
65
|
+
"@mikro-orm/core": "7.0.0-dev.170"
|
|
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
|
+
}
|