@mikro-orm/postgresql 7.0.0-dev.17 → 7.0.0-dev.171
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PoolConfig } from 'pg';
|
|
2
2
|
import { PostgresDialect } from 'kysely';
|
|
3
|
-
import { AbstractSqlConnection } from '@mikro-orm/
|
|
3
|
+
import { AbstractSqlConnection } from '@mikro-orm/sql';
|
|
4
4
|
export declare class PostgreSqlConnection extends AbstractSqlConnection {
|
|
5
5
|
createKyselyDialect(overrides: PoolConfig): PostgresDialect;
|
|
6
6
|
mapOptions(overrides: PoolConfig): PoolConfig;
|
package/PostgreSqlConnection.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Pool, TypeOverrides } from 'pg';
|
|
2
|
+
import Cursor from 'pg-cursor';
|
|
2
3
|
import { PostgresDialect } from 'kysely';
|
|
3
4
|
import array from 'postgres-array';
|
|
4
|
-
import { AbstractSqlConnection, Utils } from '@mikro-orm/
|
|
5
|
+
import { AbstractSqlConnection, Utils } from '@mikro-orm/sql';
|
|
5
6
|
export class PostgreSqlConnection extends AbstractSqlConnection {
|
|
6
7
|
createKyselyDialect(overrides) {
|
|
7
8
|
const options = this.mapOptions(overrides);
|
|
8
9
|
return new PostgresDialect({
|
|
9
10
|
pool: new Pool(options),
|
|
11
|
+
cursor: Cursor,
|
|
10
12
|
onCreateConnection: this.options.onCreateConnection ?? this.config.get('onCreateConnection'),
|
|
11
13
|
});
|
|
12
14
|
}
|
package/PostgreSqlDriver.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { Configuration } from '@mikro-orm/core';
|
|
2
|
-
import { AbstractSqlDriver } from '@mikro-orm/
|
|
1
|
+
import type { Configuration, Constructor } from '@mikro-orm/core';
|
|
2
|
+
import { AbstractSqlDriver } from '@mikro-orm/sql';
|
|
3
3
|
import { PostgreSqlConnection } from './PostgreSqlConnection.js';
|
|
4
|
+
import { PostgreSqlMikroORM } from './PostgreSqlMikroORM.js';
|
|
4
5
|
export declare class PostgreSqlDriver extends AbstractSqlDriver<PostgreSqlConnection> {
|
|
5
6
|
constructor(config: Configuration);
|
|
7
|
+
/** @inheritDoc */
|
|
8
|
+
getORMClass(): Constructor<PostgreSqlMikroORM>;
|
|
6
9
|
}
|
package/PostgreSqlDriver.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import { AbstractSqlDriver } from '@mikro-orm/
|
|
1
|
+
import { AbstractSqlDriver } from '@mikro-orm/sql';
|
|
2
2
|
import { PostgreSqlConnection } from './PostgreSqlConnection.js';
|
|
3
3
|
import { PostgreSqlPlatform } from './PostgreSqlPlatform.js';
|
|
4
|
+
import { PostgreSqlMikroORM } from './PostgreSqlMikroORM.js';
|
|
4
5
|
export class PostgreSqlDriver extends AbstractSqlDriver {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
super(config, new PostgreSqlPlatform(), PostgreSqlConnection, ['kysely', 'pg']);
|
|
7
8
|
}
|
|
9
|
+
/** @inheritDoc */
|
|
10
|
+
getORMClass() {
|
|
11
|
+
return PostgreSqlMikroORM;
|
|
12
|
+
}
|
|
8
13
|
}
|
package/PostgreSqlMikroORM.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
1
|
+
import { type AnyEntity, type EntityClass, type EntitySchema, MikroORM, type Options, type IDatabaseDriver, type EntityManager, type EntityManagerType } from '@mikro-orm/core';
|
|
2
|
+
import type { SqlEntityManager } from '@mikro-orm/sql';
|
|
2
3
|
import { PostgreSqlDriver } from './PostgreSqlDriver.js';
|
|
3
|
-
|
|
4
|
+
export type PostgreSqlOptions<EM extends SqlEntityManager<PostgreSqlDriver> = SqlEntityManager<PostgreSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> = Options<PostgreSqlDriver, EM, Entities>;
|
|
5
|
+
export declare function definePostgreSqlConfig<EM extends SqlEntityManager<PostgreSqlDriver> = SqlEntityManager<PostgreSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]>(options: Options<PostgreSqlDriver, EM, Entities>): Options<PostgreSqlDriver, EM, Entities>;
|
|
4
6
|
/**
|
|
5
7
|
* @inheritDoc
|
|
6
8
|
*/
|
|
7
|
-
export declare class PostgreSqlMikroORM<EM extends
|
|
8
|
-
private static DRIVER;
|
|
9
|
+
export declare class PostgreSqlMikroORM<EM extends SqlEntityManager<PostgreSqlDriver> = SqlEntityManager<PostgreSqlDriver>, Entities extends (string | EntityClass<AnyEntity> | EntitySchema)[] = (string | EntityClass<AnyEntity> | EntitySchema)[]> extends MikroORM<PostgreSqlDriver, EM, Entities> {
|
|
9
10
|
/**
|
|
10
11
|
* @inheritDoc
|
|
11
12
|
*/
|
|
12
|
-
static init<D extends IDatabaseDriver = PostgreSqlDriver, EM extends EntityManager = D[typeof EntityManagerType] & EntityManager>(options
|
|
13
|
+
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: Options<D, EM, Entities>): Promise<MikroORM<D, EM, Entities>>;
|
|
13
14
|
/**
|
|
14
15
|
* @inheritDoc
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
+
constructor(options: Options<PostgreSqlDriver, EM, Entities>);
|
|
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>>>;
|
package/PostgreSqlMikroORM.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { defineConfig, MikroORM, } from '@mikro-orm/core';
|
|
2
2
|
import { PostgreSqlDriver } from './PostgreSqlDriver.js';
|
|
3
|
+
export function definePostgreSqlConfig(options) {
|
|
4
|
+
return defineConfig({ driver: PostgreSqlDriver, ...options });
|
|
5
|
+
}
|
|
3
6
|
/**
|
|
4
7
|
* @inheritDoc
|
|
5
8
|
*/
|
|
6
9
|
export class PostgreSqlMikroORM extends MikroORM {
|
|
7
|
-
static DRIVER = PostgreSqlDriver;
|
|
8
10
|
/**
|
|
9
11
|
* @inheritDoc
|
|
10
12
|
*/
|
|
11
13
|
static async init(options) {
|
|
12
|
-
return super.init(options);
|
|
14
|
+
return super.init(definePostgreSqlConfig(options));
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* @inheritDoc
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
constructor(options) {
|
|
20
|
+
super(definePostgreSqlConfig(options));
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
|
-
/* v8 ignore next 3 */
|
|
22
|
-
export function definePostgreSqlConfig(options) {
|
|
23
|
-
return defineConfig({ driver: PostgreSqlDriver, ...options });
|
|
24
|
-
}
|
package/PostgreSqlPlatform.d.ts
CHANGED
|
@@ -1,110 +1,12 @@
|
|
|
1
1
|
import { type IPostgresInterval } from 'postgres-interval';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { PostgreSqlSchemaHelper } from './PostgreSqlSchemaHelper.js';
|
|
5
|
-
import { PostgreSqlExceptionConverter } from './PostgreSqlExceptionConverter.js';
|
|
6
|
-
export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
7
|
-
protected readonly schemaHelper: PostgreSqlSchemaHelper;
|
|
8
|
-
protected readonly exceptionConverter: PostgreSqlExceptionConverter;
|
|
9
|
-
setConfig(config: Configuration): void;
|
|
10
|
-
createNativeQueryBuilder(): PostgreSqlNativeQueryBuilder;
|
|
11
|
-
usesReturningStatement(): boolean;
|
|
12
|
-
usesCascadeStatement(): boolean;
|
|
13
|
-
supportsNativeEnums(): boolean;
|
|
14
|
-
usesEnumCheckConstraints(): boolean;
|
|
15
|
-
supportsCustomPrimaryKeyNames(): boolean;
|
|
16
|
-
getCurrentTimestampSQL(length: number): string;
|
|
17
|
-
getDateTimeTypeDeclarationSQL(column: {
|
|
18
|
-
length?: number;
|
|
19
|
-
}): string;
|
|
20
|
-
getDefaultDateTimeLength(): number;
|
|
2
|
+
import { BasePostgreSqlPlatform } from '@mikro-orm/sql';
|
|
3
|
+
export declare class PostgreSqlPlatform extends BasePostgreSqlPlatform {
|
|
21
4
|
convertIntervalToJSValue(value: string): unknown;
|
|
22
5
|
convertIntervalToDatabaseValue(value: IPostgresInterval): unknown;
|
|
23
|
-
getTimeTypeDeclarationSQL(): string;
|
|
24
|
-
getIntegerTypeDeclarationSQL(column: {
|
|
25
|
-
length?: number;
|
|
26
|
-
autoincrement?: boolean;
|
|
27
|
-
generated?: string;
|
|
28
|
-
}): string;
|
|
29
|
-
getBigIntTypeDeclarationSQL(column: {
|
|
30
|
-
autoincrement?: boolean;
|
|
31
|
-
}): string;
|
|
32
|
-
getTinyIntTypeDeclarationSQL(column: {
|
|
33
|
-
length?: number;
|
|
34
|
-
unsigned?: boolean;
|
|
35
|
-
autoincrement?: boolean;
|
|
36
|
-
}): string;
|
|
37
|
-
getUuidTypeDeclarationSQL(column: {
|
|
38
|
-
length?: number;
|
|
39
|
-
}): string;
|
|
40
|
-
getFullTextWhereClause(prop: EntityProperty): string;
|
|
41
|
-
supportsCreatingFullTextIndex(): boolean;
|
|
42
|
-
getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
|
|
43
|
-
normalizeColumnType(type: string, options: {
|
|
44
|
-
length?: number;
|
|
45
|
-
precision?: number;
|
|
46
|
-
scale?: number;
|
|
47
|
-
autoincrement?: boolean;
|
|
48
|
-
}): string;
|
|
49
|
-
getMappedType(type: string): Type<unknown>;
|
|
50
|
-
getRegExpOperator(val?: unknown, flags?: string): string;
|
|
51
|
-
getRegExpValue(val: RegExp): {
|
|
52
|
-
$re: string;
|
|
53
|
-
$flags?: string;
|
|
54
|
-
};
|
|
55
|
-
isBigIntProperty(prop: EntityProperty): boolean;
|
|
56
|
-
getArrayDeclarationSQL(): string;
|
|
57
|
-
getFloatDeclarationSQL(): string;
|
|
58
|
-
getDoubleDeclarationSQL(): string;
|
|
59
|
-
getEnumTypeDeclarationSQL(column: {
|
|
60
|
-
fieldNames: string[];
|
|
61
|
-
items?: unknown[];
|
|
62
|
-
nativeEnumName?: string;
|
|
63
|
-
}): string;
|
|
64
|
-
supportsMultipleStatements(): boolean;
|
|
65
|
-
getBeginTransactionSQL(options?: {
|
|
66
|
-
isolationLevel?: IsolationLevel;
|
|
67
|
-
readOnly?: boolean;
|
|
68
|
-
}): string[];
|
|
69
|
-
marshallArray(values: string[]): string;
|
|
70
6
|
unmarshallArray(value: string): string[];
|
|
71
|
-
getVarcharTypeDeclarationSQL(column: {
|
|
72
|
-
length?: number;
|
|
73
|
-
}): string;
|
|
74
|
-
getCharTypeDeclarationSQL(column: {
|
|
75
|
-
length?: number;
|
|
76
|
-
}): string;
|
|
77
|
-
getIntervalTypeDeclarationSQL(column: {
|
|
78
|
-
length?: number;
|
|
79
|
-
}): string;
|
|
80
|
-
getBlobDeclarationSQL(): string;
|
|
81
|
-
getJsonDeclarationSQL(): string;
|
|
82
|
-
getSearchJsonPropertyKey(path: string[], type: string | undefined | Type, aliased: boolean, value?: unknown): string;
|
|
83
|
-
getJsonIndexDefinition(index: IndexDef): string[];
|
|
84
|
-
quoteIdentifier(id: string, quote?: string): string;
|
|
85
7
|
escape(value: any): string;
|
|
86
|
-
private pad;
|
|
87
|
-
/** @internal */
|
|
88
|
-
formatDate(date: Date): string;
|
|
89
|
-
indexForeignKeys(): boolean;
|
|
90
|
-
getDefaultMappedType(type: string): Type<unknown>;
|
|
91
|
-
supportsSchemas(): boolean;
|
|
92
|
-
getDefaultSchemaName(): string | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Returns the default name of index for the given columns
|
|
95
|
-
* cannot go past 63 character length for identifiers in MySQL
|
|
96
|
-
*/
|
|
97
|
-
getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence'): string;
|
|
98
|
-
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
99
|
-
/**
|
|
100
|
-
* @inheritDoc
|
|
101
|
-
*/
|
|
102
|
-
castColumn(prop?: {
|
|
103
|
-
columnTypes?: string[];
|
|
104
|
-
}): string;
|
|
105
8
|
/**
|
|
106
9
|
* @inheritDoc
|
|
107
10
|
*/
|
|
108
11
|
parseDate(value: string | number): Date;
|
|
109
|
-
getDefaultClientUrl(): string;
|
|
110
12
|
}
|
package/PostgreSqlPlatform.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
1
|
import { Client } from 'pg';
|
|
2
|
+
import array from 'postgres-array';
|
|
2
3
|
import parseDate from 'postgres-date';
|
|
3
4
|
import PostgresInterval from 'postgres-interval';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { PostgreSqlSchemaHelper } from './PostgreSqlSchemaHelper.js';
|
|
7
|
-
import { PostgreSqlExceptionConverter } from './PostgreSqlExceptionConverter.js';
|
|
8
|
-
import { FullTextType } from './types/FullTextType.js';
|
|
9
|
-
export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
10
|
-
schemaHelper = new PostgreSqlSchemaHelper(this);
|
|
11
|
-
exceptionConverter = new PostgreSqlExceptionConverter();
|
|
12
|
-
setConfig(config) {
|
|
13
|
-
if (config.get('forceUtcTimezone') == null) {
|
|
14
|
-
config.set('forceUtcTimezone', true);
|
|
15
|
-
}
|
|
16
|
-
super.setConfig(config);
|
|
17
|
-
}
|
|
18
|
-
createNativeQueryBuilder() {
|
|
19
|
-
return new PostgreSqlNativeQueryBuilder(this);
|
|
20
|
-
}
|
|
21
|
-
usesReturningStatement() {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
usesCascadeStatement() {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
supportsNativeEnums() {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
usesEnumCheckConstraints() {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
supportsCustomPrimaryKeyNames() {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
getCurrentTimestampSQL(length) {
|
|
37
|
-
return `current_timestamp(${length})`;
|
|
38
|
-
}
|
|
39
|
-
getDateTimeTypeDeclarationSQL(column) {
|
|
40
|
-
/* v8 ignore next */
|
|
41
|
-
return 'timestamptz' + (column.length != null ? `(${column.length})` : '');
|
|
42
|
-
}
|
|
43
|
-
getDefaultDateTimeLength() {
|
|
44
|
-
return 6;
|
|
45
|
-
}
|
|
5
|
+
import { BasePostgreSqlPlatform, Utils } from '@mikro-orm/sql';
|
|
6
|
+
export class PostgreSqlPlatform extends BasePostgreSqlPlatform {
|
|
46
7
|
convertIntervalToJSValue(value) {
|
|
47
8
|
return PostgresInterval(value);
|
|
48
9
|
}
|
|
@@ -52,215 +13,13 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
52
13
|
}
|
|
53
14
|
return value;
|
|
54
15
|
}
|
|
55
|
-
getTimeTypeDeclarationSQL() {
|
|
56
|
-
return 'time(0)';
|
|
57
|
-
}
|
|
58
|
-
getIntegerTypeDeclarationSQL(column) {
|
|
59
|
-
if (column.autoincrement && !column.generated) {
|
|
60
|
-
return 'serial';
|
|
61
|
-
}
|
|
62
|
-
return 'int';
|
|
63
|
-
}
|
|
64
|
-
getBigIntTypeDeclarationSQL(column) {
|
|
65
|
-
/* v8 ignore next 3 */
|
|
66
|
-
if (column.autoincrement) {
|
|
67
|
-
return `bigserial`;
|
|
68
|
-
}
|
|
69
|
-
return 'bigint';
|
|
70
|
-
}
|
|
71
|
-
getTinyIntTypeDeclarationSQL(column) {
|
|
72
|
-
return 'smallint';
|
|
73
|
-
}
|
|
74
|
-
getUuidTypeDeclarationSQL(column) {
|
|
75
|
-
return `uuid`;
|
|
76
|
-
}
|
|
77
|
-
getFullTextWhereClause(prop) {
|
|
78
|
-
if (prop.customType instanceof FullTextType) {
|
|
79
|
-
return `:column: @@ plainto_tsquery('${prop.customType.regconfig}', :query)`;
|
|
80
|
-
}
|
|
81
|
-
/* v8 ignore next 3 */
|
|
82
|
-
if (prop.columnTypes[0] === 'tsvector') {
|
|
83
|
-
return `:column: @@ plainto_tsquery('simple', :query)`;
|
|
84
|
-
}
|
|
85
|
-
return `to_tsvector('simple', :column:) @@ plainto_tsquery('simple', :query)`;
|
|
86
|
-
}
|
|
87
|
-
supportsCreatingFullTextIndex() {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
|
|
91
|
-
/* v8 ignore next */
|
|
92
|
-
const quotedTableName = this.quoteIdentifier(schemaName ? `${schemaName}.${tableName}` : tableName);
|
|
93
|
-
const quotedColumnNames = columns.map(c => this.quoteIdentifier(c.name));
|
|
94
|
-
const quotedIndexName = this.quoteIdentifier(indexName);
|
|
95
|
-
if (columns.length === 1 && columns[0].type === 'tsvector') {
|
|
96
|
-
return `create index ${quotedIndexName} on ${quotedTableName} using gin(${quotedColumnNames[0]})`;
|
|
97
|
-
}
|
|
98
|
-
return `create index ${quotedIndexName} on ${quotedTableName} using gin(to_tsvector('simple', ${quotedColumnNames.join(` || ' ' || `)}))`;
|
|
99
|
-
}
|
|
100
|
-
normalizeColumnType(type, options) {
|
|
101
|
-
const simpleType = this.extractSimpleType(type);
|
|
102
|
-
if (['int', 'int4', 'integer'].includes(simpleType)) {
|
|
103
|
-
return this.getIntegerTypeDeclarationSQL({});
|
|
104
|
-
}
|
|
105
|
-
if (['bigint', 'int8'].includes(simpleType)) {
|
|
106
|
-
return this.getBigIntTypeDeclarationSQL({});
|
|
107
|
-
}
|
|
108
|
-
if (['smallint', 'int2'].includes(simpleType)) {
|
|
109
|
-
return this.getSmallIntTypeDeclarationSQL({});
|
|
110
|
-
}
|
|
111
|
-
if (['boolean', 'bool'].includes(simpleType)) {
|
|
112
|
-
return this.getBooleanTypeDeclarationSQL();
|
|
113
|
-
}
|
|
114
|
-
if (['varchar', 'character varying'].includes(simpleType)) {
|
|
115
|
-
return this.getVarcharTypeDeclarationSQL(options);
|
|
116
|
-
}
|
|
117
|
-
if (['char', 'bpchar'].includes(simpleType)) {
|
|
118
|
-
return this.getCharTypeDeclarationSQL(options);
|
|
119
|
-
}
|
|
120
|
-
if (['decimal', 'numeric'].includes(simpleType)) {
|
|
121
|
-
return this.getDecimalTypeDeclarationSQL(options);
|
|
122
|
-
}
|
|
123
|
-
if (['interval'].includes(simpleType)) {
|
|
124
|
-
return this.getIntervalTypeDeclarationSQL(options);
|
|
125
|
-
}
|
|
126
|
-
return super.normalizeColumnType(type, options);
|
|
127
|
-
}
|
|
128
|
-
getMappedType(type) {
|
|
129
|
-
switch (this.extractSimpleType(type)) {
|
|
130
|
-
case 'tsvector': return Type.getType(FullTextType);
|
|
131
|
-
default: return super.getMappedType(type);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
getRegExpOperator(val, flags) {
|
|
135
|
-
/* v8 ignore next 3 */
|
|
136
|
-
if ((val instanceof RegExp && val.flags.includes('i')) || flags?.includes('i')) {
|
|
137
|
-
return '~*';
|
|
138
|
-
}
|
|
139
|
-
return '~';
|
|
140
|
-
}
|
|
141
|
-
/* v8 ignore next 8 */
|
|
142
|
-
getRegExpValue(val) {
|
|
143
|
-
if (val.flags.includes('i')) {
|
|
144
|
-
return { $re: val.source, $flags: val.flags };
|
|
145
|
-
}
|
|
146
|
-
return { $re: val.source };
|
|
147
|
-
}
|
|
148
|
-
isBigIntProperty(prop) {
|
|
149
|
-
return super.isBigIntProperty(prop) || (['bigserial', 'int8'].includes(prop.columnTypes?.[0]));
|
|
150
|
-
}
|
|
151
|
-
getArrayDeclarationSQL() {
|
|
152
|
-
return 'text[]';
|
|
153
|
-
}
|
|
154
|
-
getFloatDeclarationSQL() {
|
|
155
|
-
return 'real';
|
|
156
|
-
}
|
|
157
|
-
getDoubleDeclarationSQL() {
|
|
158
|
-
return 'double precision';
|
|
159
|
-
}
|
|
160
|
-
getEnumTypeDeclarationSQL(column) {
|
|
161
|
-
/* v8 ignore next 3 */
|
|
162
|
-
if (column.nativeEnumName) {
|
|
163
|
-
return column.nativeEnumName;
|
|
164
|
-
}
|
|
165
|
-
if (column.items?.every(item => Utils.isString(item))) {
|
|
166
|
-
return 'text';
|
|
167
|
-
}
|
|
168
|
-
return `smallint`;
|
|
169
|
-
}
|
|
170
|
-
supportsMultipleStatements() {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
getBeginTransactionSQL(options) {
|
|
174
|
-
if (options?.isolationLevel || options?.readOnly) {
|
|
175
|
-
let sql = 'start transaction';
|
|
176
|
-
sql += options.isolationLevel ? ` isolation level ${options.isolationLevel}` : '';
|
|
177
|
-
sql += options.readOnly ? ` read only` : '';
|
|
178
|
-
return [sql];
|
|
179
|
-
}
|
|
180
|
-
return ['begin'];
|
|
181
|
-
}
|
|
182
|
-
marshallArray(values) {
|
|
183
|
-
const quote = (v) => v === '' || v.match(/["{},\\]/) ? JSON.stringify(v) : v;
|
|
184
|
-
return `{${values.map(v => quote('' + v)).join(',')}}`;
|
|
185
|
-
}
|
|
186
16
|
unmarshallArray(value) {
|
|
187
|
-
|
|
188
|
-
return [];
|
|
189
|
-
}
|
|
190
|
-
return value.substring(1, value.length - 1).split(',').map(v => {
|
|
191
|
-
if (v === `""`) {
|
|
192
|
-
return '';
|
|
193
|
-
}
|
|
194
|
-
if (v.match(/"(.*)"/)) {
|
|
195
|
-
return v.substring(1, v.length - 1).replaceAll('\\"', '"');
|
|
196
|
-
}
|
|
197
|
-
return v;
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
getVarcharTypeDeclarationSQL(column) {
|
|
201
|
-
if (column.length === -1) {
|
|
202
|
-
return 'varchar';
|
|
203
|
-
}
|
|
204
|
-
return super.getVarcharTypeDeclarationSQL(column);
|
|
205
|
-
}
|
|
206
|
-
getCharTypeDeclarationSQL(column) {
|
|
207
|
-
if (column.length === -1) {
|
|
208
|
-
return 'char';
|
|
209
|
-
}
|
|
210
|
-
return super.getCharTypeDeclarationSQL(column);
|
|
211
|
-
}
|
|
212
|
-
getIntervalTypeDeclarationSQL(column) {
|
|
213
|
-
return 'interval' + (column.length != null ? `(${column.length})` : '');
|
|
214
|
-
}
|
|
215
|
-
getBlobDeclarationSQL() {
|
|
216
|
-
return 'bytea';
|
|
217
|
-
}
|
|
218
|
-
getJsonDeclarationSQL() {
|
|
219
|
-
return 'jsonb';
|
|
220
|
-
}
|
|
221
|
-
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
222
|
-
const first = path.shift();
|
|
223
|
-
const last = path.pop();
|
|
224
|
-
const root = this.quoteIdentifier(aliased ? `${ALIAS_REPLACEMENT}.${first}` : first);
|
|
225
|
-
type = typeof type === 'string' ? this.getMappedType(type).runtimeType : String(type);
|
|
226
|
-
const types = {
|
|
227
|
-
number: 'float8',
|
|
228
|
-
bigint: 'int8',
|
|
229
|
-
boolean: 'bool',
|
|
230
|
-
};
|
|
231
|
-
const cast = (key) => raw(type in types ? `(${key})::${types[type]}` : key);
|
|
232
|
-
let lastOperator = '->>';
|
|
233
|
-
// force `->` for operator payloads with array values
|
|
234
|
-
if (Utils.isPlainObject(value) && Object.keys(value).every(key => Utils.isArrayOperator(key) && Array.isArray(value[key]))) {
|
|
235
|
-
lastOperator = '->';
|
|
236
|
-
}
|
|
237
|
-
if (path.length === 0) {
|
|
238
|
-
return cast(`${root}${lastOperator}'${last}'`);
|
|
239
|
-
}
|
|
240
|
-
return cast(`${root}->${path.map(a => this.quoteValue(a)).join('->')}${lastOperator}'${last}'`);
|
|
241
|
-
}
|
|
242
|
-
getJsonIndexDefinition(index) {
|
|
243
|
-
return index.columnNames
|
|
244
|
-
.map(column => {
|
|
245
|
-
if (!column.includes('.')) {
|
|
246
|
-
return column;
|
|
247
|
-
}
|
|
248
|
-
const path = column.split('.');
|
|
249
|
-
const first = path.shift();
|
|
250
|
-
const last = path.pop();
|
|
251
|
-
if (path.length === 0) {
|
|
252
|
-
return `(${this.quoteIdentifier(first)}->>${this.quoteValue(last)})`;
|
|
253
|
-
}
|
|
254
|
-
return `(${this.quoteIdentifier(first)}->${path.map(c => this.quoteValue(c)).join('->')}->>${this.quoteValue(last)})`;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
quoteIdentifier(id, quote = '"') {
|
|
258
|
-
if (RawQueryFragment.isKnownFragment(id)) {
|
|
259
|
-
return super.quoteIdentifier(id);
|
|
260
|
-
}
|
|
261
|
-
return `${quote}${id.replace('.', `${quote}.${quote}`)}${quote}`;
|
|
17
|
+
return array.parse(value);
|
|
262
18
|
}
|
|
263
19
|
escape(value) {
|
|
20
|
+
if (typeof value === 'bigint') {
|
|
21
|
+
value = value.toString();
|
|
22
|
+
}
|
|
264
23
|
if (typeof value === 'string') {
|
|
265
24
|
return Client.prototype.escapeLiteral(value);
|
|
266
25
|
}
|
|
@@ -270,104 +29,10 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
270
29
|
if (ArrayBuffer.isView(value)) {
|
|
271
30
|
return `E'\\\\x${value.toString('hex')}'`;
|
|
272
31
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
pad(number, digits) {
|
|
276
|
-
return String(number).padStart(digits, '0');
|
|
277
|
-
}
|
|
278
|
-
/** @internal */
|
|
279
|
-
formatDate(date) {
|
|
280
|
-
if (this.timezone === 'Z') {
|
|
281
|
-
return date.toISOString();
|
|
282
|
-
}
|
|
283
|
-
let offset = -date.getTimezoneOffset();
|
|
284
|
-
let year = date.getFullYear();
|
|
285
|
-
const isBCYear = year < 1;
|
|
286
|
-
/* v8 ignore next 3 */
|
|
287
|
-
if (isBCYear) {
|
|
288
|
-
year = Math.abs(year) + 1;
|
|
289
|
-
}
|
|
290
|
-
const datePart = `${this.pad(year, 4)}-${this.pad(date.getMonth() + 1, 2)}-${this.pad(date.getDate(), 2)}`;
|
|
291
|
-
const timePart = `${this.pad(date.getHours(), 2)}:${this.pad(date.getMinutes(), 2)}:${this.pad(date.getSeconds(), 2)}.${this.pad(date.getMilliseconds(), 3)}`;
|
|
292
|
-
let ret = `${datePart}T${timePart}`;
|
|
293
|
-
/* v8 ignore next 4 */
|
|
294
|
-
if (offset < 0) {
|
|
295
|
-
ret += '-';
|
|
296
|
-
offset *= -1;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
ret += '+';
|
|
300
|
-
}
|
|
301
|
-
ret += this.pad(Math.floor(offset / 60), 2) + ':' + this.pad(offset % 60, 2);
|
|
302
|
-
/* v8 ignore next 3 */
|
|
303
|
-
if (isBCYear) {
|
|
304
|
-
ret += ' BC';
|
|
305
|
-
}
|
|
306
|
-
return ret;
|
|
307
|
-
}
|
|
308
|
-
indexForeignKeys() {
|
|
309
|
-
return false;
|
|
310
|
-
}
|
|
311
|
-
getDefaultMappedType(type) {
|
|
312
|
-
const normalizedType = this.extractSimpleType(type);
|
|
313
|
-
const map = {
|
|
314
|
-
'int2': 'smallint',
|
|
315
|
-
'smallserial': 'smallint',
|
|
316
|
-
'int': 'integer',
|
|
317
|
-
'int4': 'integer',
|
|
318
|
-
'serial': 'integer',
|
|
319
|
-
'serial4': 'integer',
|
|
320
|
-
'int8': 'bigint',
|
|
321
|
-
'bigserial': 'bigint',
|
|
322
|
-
'serial8': 'bigint',
|
|
323
|
-
'numeric': 'decimal',
|
|
324
|
-
'bool': 'boolean',
|
|
325
|
-
'real': 'float',
|
|
326
|
-
'float4': 'float',
|
|
327
|
-
'float8': 'double',
|
|
328
|
-
'timestamp': 'datetime',
|
|
329
|
-
'timestamptz': 'datetime',
|
|
330
|
-
'bytea': 'blob',
|
|
331
|
-
'jsonb': 'json',
|
|
332
|
-
'character varying': 'varchar',
|
|
333
|
-
'bpchar': 'character',
|
|
334
|
-
};
|
|
335
|
-
return super.getDefaultMappedType(map[normalizedType] ?? type);
|
|
336
|
-
}
|
|
337
|
-
supportsSchemas() {
|
|
338
|
-
return true;
|
|
339
|
-
}
|
|
340
|
-
getDefaultSchemaName() {
|
|
341
|
-
return 'public';
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Returns the default name of index for the given columns
|
|
345
|
-
* cannot go past 63 character length for identifiers in MySQL
|
|
346
|
-
*/
|
|
347
|
-
getIndexName(tableName, columns, type) {
|
|
348
|
-
const indexName = super.getIndexName(tableName, columns, type);
|
|
349
|
-
if (indexName.length > 63) {
|
|
350
|
-
const suffix = type === 'primary' ? 'pkey' : type;
|
|
351
|
-
return `${indexName.substring(0, 55 - type.length)}_${Utils.hash(indexName, 5)}_${suffix}`;
|
|
352
|
-
}
|
|
353
|
-
return indexName;
|
|
354
|
-
}
|
|
355
|
-
getDefaultPrimaryName(tableName, columns) {
|
|
356
|
-
const indexName = `${tableName}_pkey`;
|
|
357
|
-
if (indexName.length > 63) {
|
|
358
|
-
return `${indexName.substring(0, 55 - 'pkey'.length)}_${Utils.hash(indexName, 5)}_pkey`;
|
|
359
|
-
}
|
|
360
|
-
return indexName;
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* @inheritDoc
|
|
364
|
-
*/
|
|
365
|
-
castColumn(prop) {
|
|
366
|
-
switch (prop?.columnTypes?.[0]) {
|
|
367
|
-
case this.getUuidTypeDeclarationSQL({}): return '::text';
|
|
368
|
-
case this.getBooleanTypeDeclarationSQL(): return '::int';
|
|
369
|
-
default: return '';
|
|
32
|
+
if (Array.isArray(value)) {
|
|
33
|
+
return value.map(v => this.escape(v)).join(', ');
|
|
370
34
|
}
|
|
35
|
+
return value;
|
|
371
36
|
}
|
|
372
37
|
/**
|
|
373
38
|
* @inheritDoc
|
|
@@ -377,19 +42,16 @@ export class PostgreSqlPlatform extends AbstractSqlPlatform {
|
|
|
377
42
|
if (typeof value === 'string' && value.charAt(10) === 'T') {
|
|
378
43
|
return new Date(value);
|
|
379
44
|
}
|
|
380
|
-
/* v8 ignore next
|
|
45
|
+
/* v8 ignore next */
|
|
381
46
|
if (typeof value === 'number') {
|
|
382
47
|
return new Date(value);
|
|
383
48
|
}
|
|
384
49
|
// @ts-ignore fix wrong type resolution during build
|
|
385
50
|
const parsed = parseDate(value);
|
|
386
|
-
/* v8 ignore next
|
|
51
|
+
/* v8 ignore next */
|
|
387
52
|
if (parsed === null) {
|
|
388
53
|
return value;
|
|
389
54
|
}
|
|
390
55
|
return parsed;
|
|
391
56
|
}
|
|
392
|
-
getDefaultClientUrl() {
|
|
393
|
-
return 'postgresql://postgres@127.0.0.1:5432';
|
|
394
|
-
}
|
|
395
57
|
}
|
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/index.d.ts
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
|
|
6
|
-
export
|
|
7
|
-
export * from './types/index.js';
|
|
8
|
-
export { PostgreSqlMikroORM as MikroORM, PostgreSqlOptions as Options, definePostgreSqlConfig as defineConfig, } from './PostgreSqlMikroORM.js';
|
|
5
|
+
export { PostgreSqlMikroORM as MikroORM, type PostgreSqlOptions as Options, definePostgreSqlConfig as defineConfig, } from './PostgreSqlMikroORM.js';
|
|
6
|
+
export { raw } from './raw.js';
|