@mikro-orm/postgresql 6.3.5-dev.2 → 6.3.5-dev.21

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.
@@ -1,11 +1,12 @@
1
1
  import { type IPostgresInterval } from 'postgres-interval';
2
- import { type EntityProperty, Type, type SimpleColumnMeta } from '@mikro-orm/core';
2
+ import { type EntityProperty, Type, type SimpleColumnMeta, type Configuration } from '@mikro-orm/core';
3
3
  import { AbstractSqlPlatform, type IndexDef } from '@mikro-orm/knex';
4
4
  import { PostgreSqlSchemaHelper } from './PostgreSqlSchemaHelper';
5
5
  import { PostgreSqlExceptionConverter } from './PostgreSqlExceptionConverter';
6
6
  export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
7
7
  protected readonly schemaHelper: PostgreSqlSchemaHelper;
8
8
  protected readonly exceptionConverter: PostgreSqlExceptionConverter;
9
+ setConfig(config: Configuration): void;
9
10
  usesReturningStatement(): boolean;
10
11
  usesCascadeStatement(): boolean;
11
12
  supportsNativeEnums(): boolean;
@@ -37,6 +38,12 @@ export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
37
38
  getFullTextWhereClause(prop: EntityProperty): string;
38
39
  supportsCreatingFullTextIndex(): boolean;
39
40
  getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
41
+ normalizeColumnType(type: string, options?: {
42
+ length?: number;
43
+ precision?: number;
44
+ scale?: number;
45
+ autoincrement?: boolean;
46
+ }): string;
40
47
  getMappedType(type: string): Type<unknown>;
41
48
  getRegExpOperator(val?: unknown, flags?: string): string;
42
49
  getRegExpValue(val: RegExp): {
@@ -61,12 +68,18 @@ export declare class PostgreSqlPlatform extends AbstractSqlPlatform {
61
68
  getCharTypeDeclarationSQL(column: {
62
69
  length?: number;
63
70
  }): string;
71
+ getIntervalTypeDeclarationSQL(column: {
72
+ length?: number;
73
+ }): string;
64
74
  getBlobDeclarationSQL(): string;
65
75
  getJsonDeclarationSQL(): string;
66
76
  getSearchJsonPropertyKey(path: string[], type: string | undefined | Type, aliased: boolean, value?: unknown): string;
67
77
  getJsonIndexDefinition(index: IndexDef): string[];
68
78
  quoteIdentifier(id: string, quote?: string): string;
69
79
  quoteValue(value: any): string;
80
+ private pad;
81
+ /** @internal */
82
+ formatDate(date: Date): string;
70
83
  indexForeignKeys(): boolean;
71
84
  getDefaultMappedType(type: string): Type<unknown>;
72
85
  supportsSchemas(): boolean;
@@ -15,6 +15,12 @@ const FullTextType_1 = require("./types/FullTextType");
15
15
  class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
16
16
  schemaHelper = new PostgreSqlSchemaHelper_1.PostgreSqlSchemaHelper(this);
17
17
  exceptionConverter = new PostgreSqlExceptionConverter_1.PostgreSqlExceptionConverter();
18
+ setConfig(config) {
19
+ if (config.get('forceUtcTimezone') == null) {
20
+ config.set('forceUtcTimezone', true);
21
+ }
22
+ super.setConfig(config);
23
+ }
18
24
  usesReturningStatement() {
19
25
  return true;
20
26
  }
@@ -35,7 +41,7 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
35
41
  return 'timestamptz' + (column.length != null ? `(${column.length})` : '');
36
42
  }
37
43
  getDefaultDateTimeLength() {
38
- return 6; // timestamptz actually means timestamptz(6)
44
+ return 6;
39
45
  }
40
46
  convertIntervalToJSValue(value) {
41
47
  return (0, postgres_interval_1.default)(value);
@@ -51,9 +57,9 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
51
57
  }
52
58
  getIntegerTypeDeclarationSQL(column) {
53
59
  if (column.autoincrement && !column.generated) {
54
- return `serial`;
60
+ return 'serial';
55
61
  }
56
- return `int`;
62
+ return 'int';
57
63
  }
58
64
  getBigIntTypeDeclarationSQL(column) {
59
65
  /* istanbul ignore next */
@@ -91,6 +97,34 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
91
97
  }
92
98
  return `create index ${quotedIndexName} on ${quotedTableName} using gin(to_tsvector('simple', ${quotedColumnNames.join(` || ' ' || `)}))`;
93
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
+ }
94
128
  getMappedType(type) {
95
129
  switch (this.extractSimpleType(type)) {
96
130
  case 'tsvector': return core_1.Type.getType(FullTextType_1.FullTextType);
@@ -167,6 +201,9 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
167
201
  }
168
202
  return super.getCharTypeDeclarationSQL(column);
169
203
  }
204
+ getIntervalTypeDeclarationSQL(column) {
205
+ return 'interval' + (column.length != null ? `(${column.length})` : '');
206
+ }
170
207
  getBlobDeclarationSQL() {
171
208
  return 'bytea';
172
209
  }
@@ -221,13 +258,46 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
221
258
  return pg_1.Client.prototype.escapeLiteral(value);
222
259
  }
223
260
  if (value instanceof Date) {
224
- return `'${value.toISOString()}'`;
261
+ return `'${this.formatDate(value)}'`;
225
262
  }
226
263
  if (ArrayBuffer.isView(value)) {
227
264
  return `E'\\\\x${value.toString('hex')}'`;
228
265
  }
229
266
  return super.quoteValue(value);
230
267
  }
268
+ pad(number, digits) {
269
+ return String(number).padStart(digits, '0');
270
+ }
271
+ /** @internal */
272
+ formatDate(date) {
273
+ if (this.timezone === 'Z') {
274
+ return date.toISOString();
275
+ }
276
+ let offset = -date.getTimezoneOffset();
277
+ let year = date.getFullYear();
278
+ const isBCYear = year < 1;
279
+ /* istanbul ignore next */
280
+ if (isBCYear) {
281
+ year = Math.abs(year) + 1;
282
+ }
283
+ const datePart = `${this.pad(year, 4)}-${this.pad(date.getMonth() + 1, 2)}-${this.pad(date.getDate(), 2)}`;
284
+ const timePart = `${this.pad(date.getHours(), 2)}:${this.pad(date.getMinutes(), 2)}:${this.pad(date.getSeconds(), 2)}.${this.pad(date.getMilliseconds(), 3)}`;
285
+ let ret = `${datePart}T${timePart}`;
286
+ /* istanbul ignore if */
287
+ if (offset < 0) {
288
+ ret += '-';
289
+ offset *= -1;
290
+ }
291
+ else {
292
+ ret += '+';
293
+ }
294
+ ret += this.pad(Math.floor(offset / 60), 2) + ':' + this.pad(offset % 60, 2);
295
+ /* istanbul ignore next */
296
+ if (isBCYear) {
297
+ ret += ' BC';
298
+ }
299
+ return ret;
300
+ }
231
301
  indexForeignKeys() {
232
302
  return false;
233
303
  }
@@ -314,6 +384,7 @@ class PostgreSqlPlatform extends knex_1.AbstractSqlPlatform {
314
384
  return new Date(value);
315
385
  }
316
386
  const parsed = (0, postgres_date_1.default)(value);
387
+ /* istanbul ignore next */
317
388
  if (parsed === null) {
318
389
  return value;
319
390
  }
@@ -130,10 +130,13 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
130
130
  let type = col.data_type.toLowerCase() === 'array'
131
131
  ? col.udt_name.replace(/^_(.*)$/, '$1[]')
132
132
  : col.udt_name;
133
+ if (type === 'bpchar') {
134
+ type = 'char';
135
+ }
133
136
  if (type === 'vector' && col.length == null && col.custom_length != null) {
134
137
  col.length = col.custom_length;
135
138
  }
136
- if (col.length != null && !type.endsWith(`(${col.length})`)) {
139
+ if (col.length != null && !type.endsWith(`(${col.length})`) && !['text', 'date'].includes(type)) {
137
140
  type += `(${col.length})`;
138
141
  }
139
142
  if (type === 'numeric' && col.numeric_precision != null && col.numeric_scale != null) {
@@ -203,6 +206,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
203
206
  if (match) {
204
207
  return match[1];
205
208
  }
209
+ /* istanbul ignore next */
206
210
  switch (value) {
207
211
  case 'r': return 'RESTRICT';
208
212
  case 'c': return 'CASCADE';
@@ -530,6 +534,7 @@ class PostgreSqlSchemaHelper extends knex_1.SchemaHelper {
530
534
  return -1;
531
535
  case 'interval':
532
536
  case 'time':
537
+ case 'timestamp':
533
538
  case 'timestamptz':
534
539
  return this.platform.getDefaultDateTimeLength();
535
540
  }
package/README.md CHANGED
@@ -143,7 +143,7 @@ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit m
143
143
  - [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
144
144
  - [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
145
145
  - [Property Validation](https://mikro-orm.io/docs/property-validation)
146
- - [Lifecycle Hooks](https://mikro-orm.io/docs/lifecycle-hooks)
146
+ - [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
147
147
  - [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
148
148
  - [Schema Generator](https://mikro-orm.io/docs/schema-generator)
149
149
  - [Entity Generator](https://mikro-orm.io/docs/entity-generator)
@@ -163,6 +163,7 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
163
163
  - [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
164
164
  - [Accounts.js REST and GraphQL authentication + SQLite](https://github.com/darkbasic/mikro-orm-accounts-example)
165
165
  - [Nest + Shopify + PostgreSQL + GraphQL](https://github.com/Cloudshelf/Shopify_CSConnector)
166
+ - [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
166
167
 
167
168
  ### JavaScript Examples
168
169
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/postgresql",
3
- "version": "6.3.5-dev.2",
3
+ "version": "6.3.5-dev.21",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -58,7 +58,7 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "6.3.5-dev.2",
61
+ "@mikro-orm/knex": "6.3.5-dev.21",
62
62
  "pg": "8.12.0",
63
63
  "postgres-array": "3.0.2",
64
64
  "postgres-date": "2.1.0",
@@ -68,6 +68,6 @@
68
68
  "@mikro-orm/core": "^6.3.4"
69
69
  },
70
70
  "peerDependencies": {
71
- "@mikro-orm/core": "6.3.5-dev.2"
71
+ "@mikro-orm/core": "6.3.5-dev.21"
72
72
  }
73
73
  }
@@ -9,7 +9,7 @@ class FullTextType extends core_1.Type {
9
9
  this.regconfig = regconfig;
10
10
  }
11
11
  compareAsType() {
12
- return 'string';
12
+ return 'any';
13
13
  }
14
14
  getColumnType() {
15
15
  return 'tsvector';