@mikro-orm/knex 7.0.0-dev.0 → 7.0.0-dev.2

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.
Files changed (79) hide show
  1. package/AbstractSqlConnection.d.ts +2 -2
  2. package/AbstractSqlConnection.js +25 -25
  3. package/AbstractSqlDriver.d.ts +9 -7
  4. package/AbstractSqlDriver.js +175 -180
  5. package/AbstractSqlPlatform.d.ts +4 -4
  6. package/AbstractSqlPlatform.js +17 -21
  7. package/PivotCollectionPersister.d.ts +1 -1
  8. package/PivotCollectionPersister.js +5 -8
  9. package/SqlEntityManager.d.ts +4 -3
  10. package/SqlEntityManager.js +2 -6
  11. package/SqlEntityRepository.d.ts +2 -2
  12. package/SqlEntityRepository.js +2 -6
  13. package/dialects/index.d.ts +4 -4
  14. package/dialects/index.js +4 -20
  15. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +1 -1
  16. package/dialects/mssql/MsSqlNativeQueryBuilder.js +21 -25
  17. package/dialects/mssql/index.d.ts +1 -1
  18. package/dialects/mssql/index.js +1 -17
  19. package/dialects/mysql/MySqlExceptionConverter.js +16 -19
  20. package/dialects/mysql/MySqlNativeQueryBuilder.d.ts +1 -1
  21. package/dialects/mysql/MySqlNativeQueryBuilder.js +13 -17
  22. package/dialects/mysql/MySqlPlatform.d.ts +10 -6
  23. package/dialects/mysql/MySqlPlatform.js +30 -20
  24. package/dialects/mysql/MySqlSchemaHelper.d.ts +5 -5
  25. package/dialects/mysql/MySqlSchemaHelper.js +8 -12
  26. package/dialects/mysql/index.d.ts +4 -4
  27. package/dialects/mysql/index.js +4 -20
  28. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.d.ts +1 -1
  29. package/dialects/postgresql/PostgreSqlNativeQueryBuilder.js +2 -6
  30. package/dialects/postgresql/index.d.ts +1 -1
  31. package/dialects/postgresql/index.js +1 -17
  32. package/dialects/sqlite/BaseSqliteConnection.d.ts +1 -1
  33. package/dialects/sqlite/BaseSqliteConnection.js +7 -11
  34. package/dialects/sqlite/BaseSqlitePlatform.d.ts +4 -4
  35. package/dialects/sqlite/BaseSqlitePlatform.js +11 -15
  36. package/dialects/sqlite/SqliteExceptionConverter.js +16 -19
  37. package/dialects/sqlite/SqliteNativeQueryBuilder.d.ts +1 -1
  38. package/dialects/sqlite/SqliteNativeQueryBuilder.js +2 -6
  39. package/dialects/sqlite/SqliteSchemaHelper.d.ts +5 -5
  40. package/dialects/sqlite/SqliteSchemaHelper.js +22 -26
  41. package/dialects/sqlite/index.d.ts +5 -5
  42. package/dialects/sqlite/index.js +5 -21
  43. package/index.d.ts +11 -11
  44. package/index.js +13 -34
  45. package/package.json +6 -15
  46. package/query/ArrayCriteriaNode.d.ts +2 -2
  47. package/query/ArrayCriteriaNode.js +2 -6
  48. package/query/CriteriaNode.d.ts +1 -1
  49. package/query/CriteriaNode.js +26 -30
  50. package/query/CriteriaNodeFactory.d.ts +1 -1
  51. package/query/CriteriaNodeFactory.js +17 -21
  52. package/query/NativeQueryBuilder.d.ts +2 -2
  53. package/query/NativeQueryBuilder.js +33 -37
  54. package/query/ObjectCriteriaNode.d.ts +2 -2
  55. package/query/ObjectCriteriaNode.js +37 -41
  56. package/query/QueryBuilder.d.ts +7 -7
  57. package/query/QueryBuilder.js +172 -176
  58. package/query/QueryBuilderHelper.d.ts +4 -4
  59. package/query/QueryBuilderHelper.js +84 -88
  60. package/query/ScalarCriteriaNode.d.ts +2 -2
  61. package/query/ScalarCriteriaNode.js +12 -16
  62. package/query/enums.js +4 -7
  63. package/query/index.d.ts +9 -9
  64. package/query/index.js +9 -25
  65. package/schema/DatabaseSchema.d.ts +3 -3
  66. package/schema/DatabaseSchema.js +7 -11
  67. package/schema/DatabaseTable.d.ts +3 -3
  68. package/schema/DatabaseTable.js +26 -30
  69. package/schema/SchemaComparator.d.ts +4 -4
  70. package/schema/SchemaComparator.js +15 -19
  71. package/schema/SchemaHelper.d.ts +5 -5
  72. package/schema/SchemaHelper.js +22 -26
  73. package/schema/SqlSchemaGenerator.d.ts +4 -4
  74. package/schema/SqlSchemaGenerator.js +18 -21
  75. package/schema/index.d.ts +5 -5
  76. package/schema/index.js +5 -21
  77. package/typings.d.ts +5 -4
  78. package/typings.js +1 -2
  79. package/index.mjs +0 -232
@@ -1,27 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MySqlPlatform = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const MySqlSchemaHelper_1 = require("./MySqlSchemaHelper");
6
- const MySqlExceptionConverter_1 = require("./MySqlExceptionConverter");
7
- const AbstractSqlPlatform_1 = require("../../AbstractSqlPlatform");
8
- const MySqlNativeQueryBuilder_1 = require("./MySqlNativeQueryBuilder");
9
- class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
10
- schemaHelper = new MySqlSchemaHelper_1.MySqlSchemaHelper(this);
11
- exceptionConverter = new MySqlExceptionConverter_1.MySqlExceptionConverter();
1
+ import { Utils, QueryOrder, DecimalType, DoubleType, } from '@mikro-orm/core';
2
+ import { MySqlSchemaHelper } from './MySqlSchemaHelper.js';
3
+ import { MySqlExceptionConverter } from './MySqlExceptionConverter.js';
4
+ import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
5
+ import { MySqlNativeQueryBuilder } from './MySqlNativeQueryBuilder.js';
6
+ export class MySqlPlatform extends AbstractSqlPlatform {
7
+ schemaHelper = new MySqlSchemaHelper(this);
8
+ exceptionConverter = new MySqlExceptionConverter();
12
9
  ORDER_BY_NULLS_TRANSLATE = {
13
- [core_1.QueryOrder.asc_nulls_first]: 'is not null',
14
- [core_1.QueryOrder.asc_nulls_last]: 'is null',
15
- [core_1.QueryOrder.desc_nulls_first]: 'is not null',
16
- [core_1.QueryOrder.desc_nulls_last]: 'is null',
10
+ [QueryOrder.asc_nulls_first]: 'is not null',
11
+ [QueryOrder.asc_nulls_last]: 'is null',
12
+ [QueryOrder.desc_nulls_first]: 'is not null',
13
+ [QueryOrder.desc_nulls_last]: 'is null',
17
14
  };
18
15
  /** @internal */
19
16
  createNativeQueryBuilder() {
20
- return new MySqlNativeQueryBuilder_1.MySqlNativeQueryBuilder(this);
17
+ return new MySqlNativeQueryBuilder(this);
21
18
  }
22
19
  getDefaultCharset() {
23
20
  return 'utf8mb4';
24
21
  }
22
+ getBeginTransactionSQL(options) {
23
+ if (options?.isolationLevel || options?.readOnly) {
24
+ const parts = [];
25
+ if (options.isolationLevel) {
26
+ parts.push(`isolation level ${options.isolationLevel}`);
27
+ }
28
+ if (options.readOnly) {
29
+ parts.push('read only');
30
+ }
31
+ const sql = `set transaction ${parts.join(', ')}`;
32
+ return [sql, 'begin'];
33
+ }
34
+ return ['begin'];
35
+ }
25
36
  convertJsonToDatabaseValue(value, context) {
26
37
  if (context?.mode === 'query') {
27
38
  return value;
@@ -55,7 +66,7 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
55
66
  return super.getDefaultMappedType(type);
56
67
  }
57
68
  isNumericColumn(mappedType) {
58
- return super.isNumericColumn(mappedType) || [core_1.DecimalType, core_1.DoubleType].some(t => mappedType instanceof t);
69
+ return super.isNumericColumn(mappedType) || [DecimalType, DoubleType].some(t => mappedType instanceof t);
59
70
  }
60
71
  supportsUnsigned() {
61
72
  return true;
@@ -70,7 +81,7 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
70
81
  }
71
82
  const indexName = super.getIndexName(tableName, columns, type);
72
83
  if (indexName.length > 64) {
73
- return `${indexName.substring(0, 56 - type.length)}_${core_1.Utils.hash(indexName, 5)}_${type}`;
84
+ return `${indexName.substring(0, 56 - type.length)}_${Utils.hash(indexName, 5)}_${type}`;
74
85
  }
75
86
  return indexName;
76
87
  }
@@ -84,7 +95,7 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
84
95
  return `match(:column:) against (:query in boolean mode)`;
85
96
  }
86
97
  getFullTextIndexExpression(indexName, schemaName, tableName, columns) {
87
- /* istanbul ignore next */
98
+ /* v8 ignore next */
88
99
  const quotedTableName = this.quoteIdentifier(schemaName ? `${schemaName}.${tableName}` : tableName);
89
100
  const quotedColumnNames = columns.map(c => this.quoteIdentifier(c.name));
90
101
  const quotedIndexName = this.quoteIdentifier(indexName);
@@ -103,4 +114,3 @@ class MySqlPlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
103
114
  return 'mysql://root@127.0.0.1:3306';
104
115
  }
105
116
  }
106
- exports.MySqlPlatform = MySqlPlatform;
@@ -1,9 +1,9 @@
1
1
  import { type Dictionary, type Type } from '@mikro-orm/core';
2
- import type { CheckDef, Column, IndexDef, TableDifference, Table, ForeignKey } from '../../typings';
3
- import type { AbstractSqlConnection } from '../../AbstractSqlConnection';
4
- import { SchemaHelper } from '../../schema/SchemaHelper';
5
- import type { DatabaseSchema } from '../../schema/DatabaseSchema';
6
- import type { DatabaseTable } from '../../schema/DatabaseTable';
2
+ import type { CheckDef, Column, IndexDef, TableDifference, Table, ForeignKey } from '../../typings.js';
3
+ import type { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
4
+ import { SchemaHelper } from '../../schema/SchemaHelper.js';
5
+ import type { DatabaseSchema } from '../../schema/DatabaseSchema.js';
6
+ import type { DatabaseTable } from '../../schema/DatabaseTable.js';
7
7
  export declare class MySqlSchemaHelper extends SchemaHelper {
8
8
  private readonly _cache;
9
9
  static readonly DEFAULT_VALUES: {
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MySqlSchemaHelper = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const SchemaHelper_1 = require("../../schema/SchemaHelper");
6
- class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
1
+ import { EnumType, StringType, TextType } from '@mikro-orm/core';
2
+ import { SchemaHelper } from '../../schema/SchemaHelper.js';
3
+ export class MySqlSchemaHelper extends SchemaHelper {
7
4
  _cache = {};
8
5
  static DEFAULT_VALUES = {
9
6
  'now()': ['now()', 'current_timestamp'],
@@ -81,7 +78,7 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
81
78
  return ret;
82
79
  }
83
80
  getCreateIndexSQL(tableName, index, partialExpression = false) {
84
- /* istanbul ignore next */
81
+ /* v8 ignore next 3 */
85
82
  if (index.expression && !partialExpression) {
86
83
  return index.expression;
87
84
  }
@@ -149,8 +146,8 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
149
146
  return ret;
150
147
  }
151
148
  async getAllChecks(connection, tables) {
152
- /* istanbul ignore next */
153
- if (!await this.supportsCheckConstraints(connection)) {
149
+ /* v8 ignore next 3 */
150
+ if (!(await this.supportsCheckConstraints(connection))) {
154
151
  return {};
155
152
  }
156
153
  const sql = this.getChecksSQL(tables);
@@ -184,7 +181,7 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
184
181
  }
185
182
  Object.keys(ret).forEach(key => {
186
183
  const parts = key.split('.');
187
- /* istanbul ignore next */
184
+ /* v8 ignore next */
188
185
  const schemaName = parts.length > 1 ? parts[0] : undefined;
189
186
  ret[key] = this.mapForeignKeys(ret[key], key, schemaName);
190
187
  });
@@ -266,8 +263,7 @@ class MySqlSchemaHelper extends SchemaHelper_1.SchemaHelper {
266
263
  return super.normalizeDefaultValue(defaultValue, length, MySqlSchemaHelper.DEFAULT_VALUES);
267
264
  }
268
265
  wrap(val, type) {
269
- const stringType = type instanceof core_1.StringType || type instanceof core_1.TextType || type instanceof core_1.EnumType;
266
+ const stringType = type instanceof StringType || type instanceof TextType || type instanceof EnumType;
270
267
  return typeof val === 'string' && val.length > 0 && stringType ? this.platform.quoteValue(val) : val;
271
268
  }
272
269
  }
273
- exports.MySqlSchemaHelper = MySqlSchemaHelper;
@@ -1,4 +1,4 @@
1
- export * from './MySqlExceptionConverter';
2
- export * from './MySqlSchemaHelper';
3
- export * from './MySqlPlatform';
4
- export * from './MySqlNativeQueryBuilder';
1
+ export * from './MySqlExceptionConverter.js';
2
+ export * from './MySqlSchemaHelper.js';
3
+ export * from './MySqlPlatform.js';
4
+ export * from './MySqlNativeQueryBuilder.js';
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./MySqlExceptionConverter"), exports);
18
- __exportStar(require("./MySqlSchemaHelper"), exports);
19
- __exportStar(require("./MySqlPlatform"), exports);
20
- __exportStar(require("./MySqlNativeQueryBuilder"), exports);
1
+ export * from './MySqlExceptionConverter.js';
2
+ export * from './MySqlSchemaHelper.js';
3
+ export * from './MySqlPlatform.js';
4
+ export * from './MySqlNativeQueryBuilder.js';
@@ -1,4 +1,4 @@
1
- import { NativeQueryBuilder } from '../../query/NativeQueryBuilder';
1
+ import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
2
2
  /** @internal */
3
3
  export declare class PostgreSqlNativeQueryBuilder extends NativeQueryBuilder {
4
4
  protected compileTruncate(): void;
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PostgreSqlNativeQueryBuilder = void 0;
4
- const NativeQueryBuilder_1 = require("../../query/NativeQueryBuilder");
1
+ import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
5
2
  /** @internal */
6
- class PostgreSqlNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
3
+ export class PostgreSqlNativeQueryBuilder extends NativeQueryBuilder {
7
4
  compileTruncate() {
8
5
  super.compileTruncate();
9
6
  this.parts.push('restart identity cascade');
10
7
  }
11
8
  }
12
- exports.PostgreSqlNativeQueryBuilder = PostgreSqlNativeQueryBuilder;
@@ -1 +1 @@
1
- export * from './PostgreSqlNativeQueryBuilder';
1
+ export * from './PostgreSqlNativeQueryBuilder.js';
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./PostgreSqlNativeQueryBuilder"), exports);
1
+ export * from './PostgreSqlNativeQueryBuilder.js';
@@ -1,4 +1,4 @@
1
- import { AbstractSqlConnection } from '../../AbstractSqlConnection';
1
+ import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
2
2
  export declare abstract class BaseSqliteConnection extends AbstractSqlConnection {
3
3
  connect(): Promise<void>;
4
4
  getClientUrl(): string;
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseSqliteConnection = void 0;
4
- const node_path_1 = require("node:path");
5
- const fs_extra_1 = require("fs-extra");
6
- const kysely_1 = require("kysely");
7
- const AbstractSqlConnection_1 = require("../../AbstractSqlConnection");
8
- class BaseSqliteConnection extends AbstractSqlConnection_1.AbstractSqlConnection {
1
+ import { dirname } from 'node:path';
2
+ import { CompiledQuery } from 'kysely';
3
+ import { Utils } from '@mikro-orm/core';
4
+ import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
5
+ export class BaseSqliteConnection extends AbstractSqlConnection {
9
6
  async connect() {
10
7
  await super.connect();
11
- await (0, fs_extra_1.ensureDir)((0, node_path_1.dirname)(this.config.get('dbName')));
12
- await this.client.executeQuery(kysely_1.CompiledQuery.raw('pragma foreign_keys = on'));
8
+ Utils.ensureDir(dirname(this.config.get('dbName')));
9
+ await this.client.executeQuery(CompiledQuery.raw('pragma foreign_keys = on'));
13
10
  }
14
11
  getClientUrl() {
15
12
  return '';
16
13
  }
17
14
  }
18
- exports.BaseSqliteConnection = BaseSqliteConnection;
@@ -1,8 +1,8 @@
1
1
  import { type EntityProperty, type IsolationLevel } from '@mikro-orm/core';
2
- import { AbstractSqlPlatform } from '../../AbstractSqlPlatform';
3
- import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder';
4
- import { SqliteSchemaHelper } from './SqliteSchemaHelper';
5
- import { SqliteExceptionConverter } from './SqliteExceptionConverter';
2
+ import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
3
+ import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
4
+ import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
5
+ import { SqliteExceptionConverter } from './SqliteExceptionConverter.js';
6
6
  export declare abstract class BaseSqlitePlatform extends AbstractSqlPlatform {
7
7
  protected readonly schemaHelper: SqliteSchemaHelper;
8
8
  protected readonly exceptionConverter: SqliteExceptionConverter;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseSqlitePlatform = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const AbstractSqlPlatform_1 = require("../../AbstractSqlPlatform");
6
- const SqliteNativeQueryBuilder_1 = require("./SqliteNativeQueryBuilder");
7
- const SqliteSchemaHelper_1 = require("./SqliteSchemaHelper");
8
- const SqliteExceptionConverter_1 = require("./SqliteExceptionConverter");
9
- class BaseSqlitePlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
10
- schemaHelper = new SqliteSchemaHelper_1.SqliteSchemaHelper(this);
11
- exceptionConverter = new SqliteExceptionConverter_1.SqliteExceptionConverter();
1
+ import { Utils } from '@mikro-orm/core';
2
+ import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
3
+ import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
4
+ import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
5
+ import { SqliteExceptionConverter } from './SqliteExceptionConverter.js';
6
+ export class BaseSqlitePlatform extends AbstractSqlPlatform {
7
+ schemaHelper = new SqliteSchemaHelper(this);
8
+ exceptionConverter = new SqliteExceptionConverter();
12
9
  /** @internal */
13
10
  createNativeQueryBuilder() {
14
- return new SqliteNativeQueryBuilder_1.SqliteNativeQueryBuilder(this);
11
+ return new SqliteNativeQueryBuilder(this);
15
12
  }
16
13
  usesDefaultKeyword() {
17
14
  return false;
@@ -32,10 +29,10 @@ class BaseSqlitePlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
32
29
  return ['begin'];
33
30
  }
34
31
  getEnumTypeDeclarationSQL(column) {
35
- if (column.items?.every(item => core_1.Utils.isString(item))) {
32
+ if (column.items?.every(item => Utils.isString(item))) {
36
33
  return 'text';
37
34
  }
38
- /* istanbul ignore next */
35
+ /* v8 ignore next */
39
36
  return this.getTinyIntTypeDeclarationSQL(column);
40
37
  }
41
38
  getTinyIntTypeDeclarationSQL(column) {
@@ -110,4 +107,3 @@ class BaseSqlitePlatform extends AbstractSqlPlatform_1.AbstractSqlPlatform {
110
107
  return super.quoteValue(value);
111
108
  }
112
109
  }
113
- exports.BaseSqlitePlatform = BaseSqlitePlatform;
@@ -1,55 +1,52 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqliteExceptionConverter = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- class SqliteExceptionConverter extends core_1.ExceptionConverter {
6
- /* istanbul ignore next */
1
+ import { ConnectionException, ExceptionConverter, InvalidFieldNameException, LockWaitTimeoutException, NonUniqueFieldNameException, CheckConstraintViolationException, NotNullConstraintViolationException, ReadOnlyException, SyntaxErrorException, TableExistsException, TableNotFoundException, UniqueConstraintViolationException, ForeignKeyConstraintViolationException, } from '@mikro-orm/core';
2
+ export class SqliteExceptionConverter extends ExceptionConverter {
7
3
  /**
8
4
  * @inheritDoc
9
5
  * @link http://www.sqlite.org/c3ref/c_abort.html
10
6
  * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractSQLiteDriver.php
11
7
  */
12
8
  convertException(exception) {
9
+ /* v8 ignore start */
13
10
  if (exception.message.includes('database is locked')) {
14
- return new core_1.LockWaitTimeoutException(exception);
11
+ return new LockWaitTimeoutException(exception);
15
12
  }
16
13
  if (exception.message.includes('must be unique') ||
17
14
  exception.message.includes('is not unique') ||
18
15
  exception.message.includes('are not unique') ||
19
16
  exception.message.includes('UNIQUE constraint failed')) {
20
- return new core_1.UniqueConstraintViolationException(exception);
17
+ return new UniqueConstraintViolationException(exception);
21
18
  }
22
19
  if (exception.message.includes('may not be NULL') || exception.message.includes('NOT NULL constraint failed')) {
23
- return new core_1.NotNullConstraintViolationException(exception);
20
+ return new NotNullConstraintViolationException(exception);
24
21
  }
25
22
  if (exception.message.includes('CHECK constraint failed')) {
26
- return new core_1.CheckConstraintViolationException(exception);
23
+ return new CheckConstraintViolationException(exception);
27
24
  }
28
25
  if (exception.message.includes('no such table:')) {
29
- return new core_1.TableNotFoundException(exception);
26
+ return new TableNotFoundException(exception);
30
27
  }
31
28
  if (exception.message.includes('already exists')) {
32
- return new core_1.TableExistsException(exception);
29
+ return new TableExistsException(exception);
33
30
  }
34
31
  if (exception.message.includes('no such column:')) {
35
- return new core_1.InvalidFieldNameException(exception);
32
+ return new InvalidFieldNameException(exception);
36
33
  }
37
34
  if (exception.message.includes('ambiguous column name')) {
38
- return new core_1.NonUniqueFieldNameException(exception);
35
+ return new NonUniqueFieldNameException(exception);
39
36
  }
40
37
  if (exception.message.includes('syntax error')) {
41
- return new core_1.SyntaxErrorException(exception);
38
+ return new SyntaxErrorException(exception);
42
39
  }
43
40
  if (exception.message.includes('attempt to write a readonly database')) {
44
- return new core_1.ReadOnlyException(exception);
41
+ return new ReadOnlyException(exception);
45
42
  }
46
43
  if (exception.message.includes('unable to open database file')) {
47
- return new core_1.ConnectionException(exception);
44
+ return new ConnectionException(exception);
48
45
  }
49
46
  if (exception.message.includes('FOREIGN KEY constraint failed')) {
50
- return new core_1.ForeignKeyConstraintViolationException(exception);
47
+ return new ForeignKeyConstraintViolationException(exception);
51
48
  }
49
+ /* v8 ignore stop */
52
50
  return super.convertException(exception);
53
51
  }
54
52
  }
55
- exports.SqliteExceptionConverter = SqliteExceptionConverter;
@@ -1,4 +1,4 @@
1
- import { NativeQueryBuilder } from '../../query/NativeQueryBuilder';
1
+ import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
2
2
  /** @internal */
3
3
  export declare class SqliteNativeQueryBuilder extends NativeQueryBuilder {
4
4
  protected compileTruncate(): void;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqliteNativeQueryBuilder = void 0;
4
- const NativeQueryBuilder_1 = require("../../query/NativeQueryBuilder");
1
+ import { NativeQueryBuilder } from '../../query/NativeQueryBuilder.js';
5
2
  /** @internal */
6
- class SqliteNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
3
+ export class SqliteNativeQueryBuilder extends NativeQueryBuilder {
7
4
  compileTruncate() {
8
5
  const sql = `delete from ${this.getTableName()}`;
9
6
  this.parts.push(sql);
@@ -12,4 +9,3 @@ class SqliteNativeQueryBuilder extends NativeQueryBuilder_1.NativeQueryBuilder {
12
9
  return; // not supported
13
10
  }
14
11
  }
15
- exports.SqliteNativeQueryBuilder = SqliteNativeQueryBuilder;
@@ -1,9 +1,9 @@
1
1
  import { type Connection } from '@mikro-orm/core';
2
- import type { AbstractSqlConnection } from '../../AbstractSqlConnection';
3
- import { SchemaHelper } from '../../schema/SchemaHelper';
4
- import type { Column, IndexDef, Table, TableDifference } from '../../typings';
5
- import type { DatabaseTable } from '../../schema/DatabaseTable';
6
- import type { DatabaseSchema } from '../../schema/DatabaseSchema';
2
+ import type { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
3
+ import { SchemaHelper } from '../../schema/SchemaHelper.js';
4
+ import type { Column, IndexDef, Table, TableDifference } from '../../typings.js';
5
+ import type { DatabaseTable } from '../../schema/DatabaseTable.js';
6
+ import type { DatabaseSchema } from '../../schema/DatabaseSchema.js';
7
7
  export declare class SqliteSchemaHelper extends SchemaHelper {
8
8
  disableForeignKeysSQL(): string;
9
9
  enableForeignKeysSQL(): string;
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SqliteSchemaHelper = void 0;
4
- const core_1 = require("@mikro-orm/core");
5
- const SchemaHelper_1 = require("../../schema/SchemaHelper");
6
- class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
1
+ import { Utils } from '@mikro-orm/core';
2
+ import { SchemaHelper } from '../../schema/SchemaHelper.js';
3
+ export class SqliteSchemaHelper extends SchemaHelper {
7
4
  disableForeignKeysSQL() {
8
5
  return 'pragma foreign_keys = off;';
9
6
  }
@@ -21,7 +18,7 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
21
18
  if (name === ':memory:') {
22
19
  return '';
23
20
  }
24
- /* istanbul ignore next */
21
+ /* v8 ignore next */
25
22
  return `drop database if exists ${this.quote(name)}`;
26
23
  }
27
24
  async loadInformationSchema(schema, connection, tables, schemas) {
@@ -88,11 +85,11 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
88
85
  col.push(`check (${checks[check].expression})`);
89
86
  checks.splice(check, 1);
90
87
  }
91
- core_1.Utils.runIfNotEmpty(() => col.push('null'), column.nullable);
92
- core_1.Utils.runIfNotEmpty(() => col.push('not null'), !column.nullable && !column.generated);
93
- core_1.Utils.runIfNotEmpty(() => col.push('primary key'), column.primary);
94
- core_1.Utils.runIfNotEmpty(() => col.push('autoincrement'), column.autoincrement);
95
- core_1.Utils.runIfNotEmpty(() => col.push(`default ${column.default}`), useDefault);
88
+ Utils.runIfNotEmpty(() => col.push('null'), column.nullable);
89
+ Utils.runIfNotEmpty(() => col.push('not null'), !column.nullable && !column.generated);
90
+ Utils.runIfNotEmpty(() => col.push('primary key'), column.primary);
91
+ Utils.runIfNotEmpty(() => col.push('autoincrement'), column.autoincrement);
92
+ Utils.runIfNotEmpty(() => col.push(`default ${column.default}`), useDefault);
96
93
  return col.join(' ');
97
94
  }
98
95
  getAddColumnsSQL(table, columns, diff) {
@@ -110,14 +107,14 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
110
107
  return '';
111
108
  }
112
109
  getDropColumnsSQL(tableName, columns, schemaName) {
113
- /* istanbul ignore next */
110
+ /* v8 ignore next */
114
111
  const name = this.quote((schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName);
115
112
  return columns.map(column => {
116
113
  return `alter table ${name} drop column ${this.quote(column.name)}`;
117
114
  }).join(';\n');
118
115
  }
119
116
  getCreateIndexSQL(tableName, index) {
120
- /* istanbul ignore next */
117
+ /* v8 ignore next 3 */
121
118
  if (index.expression) {
122
119
  return index.expression;
123
120
  }
@@ -137,7 +134,7 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
137
134
  const constraints = [];
138
135
  // extract all columns definitions
139
136
  let columnsDef = sql.replaceAll('\n', '').match(new RegExp(`create table [\`"']?.*?[\`"']? \\((.*)\\)`, 'i'))?.[1];
140
- /* istanbul ignore else */
137
+ /* v8 ignore start */
141
138
  if (columnsDef) {
142
139
  if (columnsDef.includes(', constraint ')) {
143
140
  constraints.push(...columnsDef.substring(columnsDef.indexOf(', constraint') + 2).split(', '));
@@ -147,13 +144,13 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
147
144
  const col = cols[i];
148
145
  const re = ` *, *[\`"']?${col.name}[\`"']? (.*)`;
149
146
  const columnDef = columnsDef.match(new RegExp(re, 'i'));
150
- /* istanbul ignore else */
151
147
  if (columnDef) {
152
148
  columns[col.name] = { name: col.name, definition: columnDef[1] };
153
149
  columnsDef = columnsDef.substring(0, columnDef.index);
154
150
  }
155
151
  }
156
152
  }
153
+ /* v8 ignore stop */
157
154
  return { columns, constraints };
158
155
  }
159
156
  async getColumns(connection, tableName, schemaName) {
@@ -168,7 +165,7 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
168
165
  const mappedType = connection.getPlatform().getMappedType(col.type);
169
166
  let generated;
170
167
  if (col.hidden > 1) {
171
- /* istanbul ignore next */
168
+ /* v8 ignore next */
172
169
  const storage = col.hidden === 2 ? 'virtual' : 'stored';
173
170
  const re = `(generated always)? as \\((.*)\\)( ${storage})?$`;
174
171
  const match = columnDefinitions[col.name].definition.match(re);
@@ -192,12 +189,12 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
192
189
  async getEnumDefinitions(connection, tableName) {
193
190
  const sql = `select sql from sqlite_master where type = ? and name = ?`;
194
191
  const tableDefinition = await connection.execute(sql, ['table', tableName], 'get');
195
- const checkConstraints = [...tableDefinition.sql.match(/[`["'][^`\]"']+[`\]"'] text check \(.*?\)/gi) ?? []];
192
+ const checkConstraints = [...(tableDefinition.sql.match(/[`["'][^`\]"']+[`\]"'] text check \(.*?\)/gi) ?? [])];
196
193
  return checkConstraints.reduce((o, item) => {
197
194
  // check constraints are defined as (note that last closing paren is missing):
198
195
  // `type` text check (`type` in ('local', 'global')
199
196
  const match = item.match(/[`["']([^`\]"']+)[`\]"'] text check \(.* \((.*)\)/i);
200
- /* istanbul ignore else */
197
+ /* v8 ignore next 3 */
201
198
  if (match) {
202
199
  o[match[1]] = match[2].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)[1]);
203
200
  }
@@ -312,10 +309,10 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
312
309
  alterTable(diff, safe) {
313
310
  const ret = [];
314
311
  const [schemaName, tableName] = this.splitTableName(diff.name);
315
- if (core_1.Utils.hasObjectKeys(diff.removedChecks)
316
- || core_1.Utils.hasObjectKeys(diff.changedChecks)
317
- || core_1.Utils.hasObjectKeys(diff.changedForeignKeys)
318
- || core_1.Utils.hasObjectKeys(diff.changedColumns)) {
312
+ if (Utils.hasObjectKeys(diff.removedChecks)
313
+ || Utils.hasObjectKeys(diff.changedChecks)
314
+ || Utils.hasObjectKeys(diff.changedForeignKeys)
315
+ || Utils.hasObjectKeys(diff.changedColumns)) {
319
316
  return this.getAlterTempTableSQL(diff);
320
317
  }
321
318
  for (const index of Object.values(diff.removedIndexes)) {
@@ -324,14 +321,14 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
324
321
  for (const index of Object.values(diff.changedIndexes)) {
325
322
  this.append(ret, this.dropIndex(diff.name, index));
326
323
  }
327
- /* istanbul ignore else */
324
+ /* v8 ignore next 3 */
328
325
  if (!safe && Object.values(diff.removedColumns).length > 0) {
329
326
  this.append(ret, this.getDropColumnsSQL(tableName, Object.values(diff.removedColumns), schemaName));
330
327
  }
331
328
  if (Object.values(diff.addedColumns).length > 0) {
332
329
  this.append(ret, this.getAddColumnsSQL(diff.toTable, Object.values(diff.addedColumns), diff));
333
330
  }
334
- if (core_1.Utils.hasObjectKeys(diff.addedForeignKeys) || core_1.Utils.hasObjectKeys(diff.addedChecks)) {
331
+ if (Utils.hasObjectKeys(diff.addedForeignKeys) || Utils.hasObjectKeys(diff.addedChecks)) {
335
332
  return this.getAlterTempTableSQL(diff);
336
333
  }
337
334
  for (const [oldColumnName, column] of Object.entries(diff.renamedColumns)) {
@@ -381,4 +378,3 @@ class SqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
381
378
  return sql;
382
379
  }
383
380
  }
384
- exports.SqliteSchemaHelper = SqliteSchemaHelper;
@@ -1,5 +1,5 @@
1
- export * from './BaseSqliteConnection';
2
- export * from './BaseSqlitePlatform';
3
- export * from './SqliteSchemaHelper';
4
- export * from './SqliteNativeQueryBuilder';
5
- export * from './SqliteExceptionConverter';
1
+ export * from './BaseSqliteConnection.js';
2
+ export * from './BaseSqlitePlatform.js';
3
+ export * from './SqliteSchemaHelper.js';
4
+ export * from './SqliteNativeQueryBuilder.js';
5
+ export * from './SqliteExceptionConverter.js';
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./BaseSqliteConnection"), exports);
18
- __exportStar(require("./BaseSqlitePlatform"), exports);
19
- __exportStar(require("./SqliteSchemaHelper"), exports);
20
- __exportStar(require("./SqliteNativeQueryBuilder"), exports);
21
- __exportStar(require("./SqliteExceptionConverter"), exports);
1
+ export * from './BaseSqliteConnection.js';
2
+ export * from './BaseSqlitePlatform.js';
3
+ export * from './SqliteSchemaHelper.js';
4
+ export * from './SqliteNativeQueryBuilder.js';
5
+ export * from './SqliteExceptionConverter.js';