@mikro-orm/knex 6.6.10-dev.0 → 6.6.10-dev.1

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.
@@ -11,8 +11,10 @@ export declare const MonkeyPatchable: {
11
11
  PostgresDialect: any;
12
12
  PostgresDialectTableCompiler: any;
13
13
  PostgresQueryCompiler: any;
14
+ PostgresColumnCompiler: any;
14
15
  Sqlite3Dialect: any;
15
16
  Sqlite3DialectTableCompiler: any;
17
+ Sqlite3ColumnCompiler: any;
16
18
  BetterSqlite3Dialect: any;
17
19
  TableCompiler: any;
18
20
  };
@@ -29,12 +29,16 @@ const pg_tablecompiler_1 = __importDefault(require("knex/lib/dialects/postgres/s
29
29
  // @ts-ignore
30
30
  const pg_querycompiler_1 = __importDefault(require("knex/lib/dialects/postgres/query/pg-querycompiler"));
31
31
  // @ts-ignore
32
+ const pg_columncompiler_1 = __importDefault(require("knex/lib/dialects/postgres/schema/pg-columncompiler"));
33
+ // @ts-ignore
32
34
  const sqlite3_1 = __importDefault(require("knex/lib/dialects/sqlite3"));
33
35
  // @ts-ignore
34
36
  const better_sqlite3_1 = __importDefault(require("knex/lib/dialects/better-sqlite3"));
35
37
  // @ts-ignore
36
38
  const sqlite_tablecompiler_1 = __importDefault(require("knex/lib/dialects/sqlite3/schema/sqlite-tablecompiler"));
37
39
  // @ts-ignore
40
+ const sqlite_columncompiler_1 = __importDefault(require("knex/lib/dialects/sqlite3/schema/sqlite-columncompiler"));
41
+ // @ts-ignore
38
42
  const tablecompiler_1 = __importDefault(require("knex/lib/schema/tablecompiler"));
39
43
  // These specific portions of knex are overridden by the different
40
44
  // database packages. We need to be sure the knex files they get to
@@ -53,8 +57,10 @@ exports.MonkeyPatchable = {
53
57
  PostgresDialect: postgres_1.default,
54
58
  PostgresDialectTableCompiler: pg_tablecompiler_1.default,
55
59
  PostgresQueryCompiler: pg_querycompiler_1.default,
60
+ PostgresColumnCompiler: pg_columncompiler_1.default,
56
61
  Sqlite3Dialect: sqlite3_1.default,
57
62
  Sqlite3DialectTableCompiler: sqlite_tablecompiler_1.default,
63
+ Sqlite3ColumnCompiler: sqlite_columncompiler_1.default,
58
64
  BetterSqlite3Dialect: better_sqlite3_1.default,
59
65
  TableCompiler: tablecompiler_1.default,
60
66
  };
@@ -4,7 +4,7 @@ exports.MsSqlColumnCompiler = void 0;
4
4
  const MonkeyPatchable_1 = require("../../MonkeyPatchable");
5
5
  class MsSqlColumnCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlColumnCompiler {
6
6
  enu(allowed) {
7
- return `nvarchar(100) check (${this.formatter.wrap(this.args[0])} in ('${(allowed.join("', '"))}'))`;
7
+ return `nvarchar(100) check (${this.formatter.wrap(this.args[0])} in (${allowed.map(v => `'${String(v).replace(/'/g, "''")}'`).join(', ')}))`;
8
8
  }
9
9
  }
10
10
  exports.MsSqlColumnCompiler = MsSqlColumnCompiler;
@@ -0,0 +1,4 @@
1
+ import { MonkeyPatchable } from '../../MonkeyPatchable';
2
+ export declare class PostgreSqlColumnCompiler extends MonkeyPatchable.PostgresColumnCompiler {
3
+ enu(this: any, allowed: unknown[], options: any): any;
4
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PostgreSqlColumnCompiler = void 0;
4
+ const MonkeyPatchable_1 = require("../../MonkeyPatchable");
5
+ class PostgreSqlColumnCompiler extends MonkeyPatchable_1.MonkeyPatchable.PostgresColumnCompiler {
6
+ enu(allowed, options) {
7
+ options = options || {};
8
+ if (options.useNative) {
9
+ return super.enu(allowed, options);
10
+ }
11
+ const values = allowed.map(v => `'${String(v).replace(/'/g, "''")}'`).join(', ');
12
+ return `text check (${this.formatter.wrap(this.args[0])} in (${values}))`;
13
+ }
14
+ }
15
+ exports.PostgreSqlColumnCompiler = PostgreSqlColumnCompiler;
@@ -4,4 +4,5 @@ export declare class PostgreSqlKnexDialect extends MonkeyPatchable.PostgresDiale
4
4
  ormConfig: Configuration;
5
5
  tableCompiler(): any;
6
6
  queryCompiler(): any;
7
+ columnCompiler(): any;
7
8
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PostgreSqlKnexDialect = void 0;
4
4
  const PostgreSqlTableCompiler_1 = require("./PostgreSqlTableCompiler");
5
5
  const PostgreSqlQueryCompiler_1 = require("./PostgreSqlQueryCompiler");
6
+ const PostgreSqlColumnCompiler_1 = require("./PostgreSqlColumnCompiler");
6
7
  const MonkeyPatchable_1 = require("../../MonkeyPatchable");
7
8
  class PostgreSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.PostgresDialect {
8
9
  ormConfig;
@@ -16,5 +17,9 @@ class PostgreSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.PostgresDi
16
17
  // eslint-disable-next-line prefer-rest-params
17
18
  return new PostgreSqlQueryCompiler_1.PostgreSqlQueryCompiler(this, ...arguments);
18
19
  }
20
+ columnCompiler() {
21
+ // eslint-disable-next-line prefer-rest-params
22
+ return new PostgreSqlColumnCompiler_1.PostgreSqlColumnCompiler(this, ...arguments);
23
+ }
19
24
  }
20
25
  exports.PostgreSqlKnexDialect = PostgreSqlKnexDialect;
@@ -92,7 +92,9 @@ class BaseSqliteSchemaHelper extends SchemaHelper_1.SchemaHelper {
92
92
  const match = item.match(/[`["']([^`\]"']+)[`\]"'] text check \(.* \((.*)\)/i);
93
93
  /* istanbul ignore else */
94
94
  if (match) {
95
- o[match[1]] = match[2].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)[1]);
95
+ o[match[1]] = match[2]
96
+ .split(/,(?=\s*'(?:[^']|'')*'(?:\s*\)|$))/)
97
+ .map((item) => item.trim().match(/^\(?'((?:[^']|'')*)'/)[1].replace(/''/g, "'"));
96
98
  }
97
99
  return o;
98
100
  }, {});
@@ -2,4 +2,5 @@ import { MonkeyPatchable } from '../../MonkeyPatchable';
2
2
  export declare class BetterSqliteKnexDialect extends MonkeyPatchable.BetterSqlite3Dialect {
3
3
  _driver(): any;
4
4
  tableCompiler(): any;
5
+ columnCompiler(): any;
5
6
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BetterSqliteKnexDialect = void 0;
4
4
  const SqliteTableCompiler_1 = require("./SqliteTableCompiler");
5
+ const SqliteColumnCompiler_1 = require("./SqliteColumnCompiler");
5
6
  const MonkeyPatchable_1 = require("../../MonkeyPatchable");
6
7
  class BetterSqliteKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.BetterSqlite3Dialect {
7
8
  _driver() {
@@ -11,5 +12,9 @@ class BetterSqliteKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.BetterSq
11
12
  // eslint-disable-next-line prefer-rest-params
12
13
  return new SqliteTableCompiler_1.SqliteTableCompiler(this, ...arguments);
13
14
  }
15
+ columnCompiler() {
16
+ // eslint-disable-next-line prefer-rest-params
17
+ return new SqliteColumnCompiler_1.SqliteColumnCompiler(this, ...arguments);
18
+ }
14
19
  }
15
20
  exports.BetterSqliteKnexDialect = BetterSqliteKnexDialect;
@@ -5,6 +5,7 @@ export declare class LibSqlKnexDialect extends MonkeyPatchable.BetterSqlite3Dial
5
5
  _query(this: any, connection: any, obj: any): Promise<any>;
6
6
  acquireRawConnection(this: any): Promise<any>;
7
7
  tableCompiler(): any;
8
+ columnCompiler(): any;
8
9
  validateConnection(connection: any): boolean;
9
10
  private getCallMethod;
10
11
  private isRunQuery;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LibSqlKnexDialect = void 0;
4
4
  const SqliteTableCompiler_1 = require("./SqliteTableCompiler");
5
+ const SqliteColumnCompiler_1 = require("./SqliteColumnCompiler");
5
6
  const MonkeyPatchable_1 = require("../../MonkeyPatchable");
6
7
  class LibSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.BetterSqlite3Dialect {
7
8
  get driverName() {
@@ -41,6 +42,10 @@ class LibSqlKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.BetterSqlite3D
41
42
  // eslint-disable-next-line prefer-rest-params
42
43
  return new SqliteTableCompiler_1.SqliteTableCompiler(this, ...arguments);
43
44
  }
45
+ columnCompiler() {
46
+ // eslint-disable-next-line prefer-rest-params
47
+ return new SqliteColumnCompiler_1.SqliteColumnCompiler(this, ...arguments);
48
+ }
44
49
  validateConnection(connection) {
45
50
  if (connection.memory) {
46
51
  return true;
@@ -0,0 +1,4 @@
1
+ import { MonkeyPatchable } from '../../MonkeyPatchable';
2
+ export declare class SqliteColumnCompiler extends MonkeyPatchable.Sqlite3ColumnCompiler {
3
+ enu(this: any, allowed: unknown[]): string;
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SqliteColumnCompiler = void 0;
4
+ const MonkeyPatchable_1 = require("../../MonkeyPatchable");
5
+ class SqliteColumnCompiler extends MonkeyPatchable_1.MonkeyPatchable.Sqlite3ColumnCompiler {
6
+ enu(allowed) {
7
+ const values = allowed.map(v => `'${String(v).replace(/'/g, "''")}'`).join(', ');
8
+ return `text check (${this.formatter.wrap(this.args[0])} in (${values}))`;
9
+ }
10
+ }
11
+ exports.SqliteColumnCompiler = SqliteColumnCompiler;
@@ -1,6 +1,7 @@
1
1
  import { MonkeyPatchable } from '../../MonkeyPatchable';
2
2
  export declare class SqliteKnexDialect extends MonkeyPatchable.Sqlite3Dialect {
3
3
  tableCompiler(): any;
4
+ columnCompiler(): any;
4
5
  processResponse(obj: any, runner: any): any;
5
6
  _query(connection: any, obj: any): Promise<unknown>;
6
7
  private getCallMethod;
@@ -2,12 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SqliteKnexDialect = void 0;
4
4
  const SqliteTableCompiler_1 = require("./SqliteTableCompiler");
5
+ const SqliteColumnCompiler_1 = require("./SqliteColumnCompiler");
5
6
  const MonkeyPatchable_1 = require("../../MonkeyPatchable");
6
7
  class SqliteKnexDialect extends MonkeyPatchable_1.MonkeyPatchable.Sqlite3Dialect {
7
8
  tableCompiler() {
8
9
  // eslint-disable-next-line prefer-rest-params
9
10
  return new SqliteTableCompiler_1.SqliteTableCompiler(this, ...arguments);
10
11
  }
12
+ columnCompiler() {
13
+ // eslint-disable-next-line prefer-rest-params
14
+ return new SqliteColumnCompiler_1.SqliteColumnCompiler(this, ...arguments);
15
+ }
11
16
  processResponse(obj, runner) {
12
17
  if (obj.method === 'raw' && this.isRunQuery(obj.sql)) {
13
18
  return obj.response ?? obj.context;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.6.10-dev.0",
3
+ "version": "6.6.10-dev.1",
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",
@@ -66,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.6.9"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.6.10-dev.0",
69
+ "@mikro-orm/core": "6.6.10-dev.1",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -559,7 +559,7 @@ class QueryBuilder {
559
559
  const qb = this.getQueryBase(processVirtualEntity);
560
560
  const schema = this.getSchema(this.mainAlias);
561
561
  const type = this.type ?? enums_1.QueryType.SELECT;
562
- qb.__raw = true; // tag it as there is now way to check via `instanceof`
562
+ core_1.RawQueryFragment.markRaw(qb);
563
563
  core_1.Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(type, this._cond, qb), this._cond && !this._onConflict);
564
564
  core_1.Utils.runIfNotEmpty(() => qb.groupBy(this.prepareFields(this._groupBy, 'groupBy', schema)), this._groupBy);
565
565
  core_1.Utils.runIfNotEmpty(() => this.helper.appendQueryCondition(type, this._having, qb, undefined, 'having'), this._having);
@@ -1393,7 +1393,7 @@ class QueryBuilder {
1393
1393
  // multiple sub-queries are needed to get around mysql limitations with order by + limit + where in + group by (o.O)
1394
1394
  // https://stackoverflow.com/questions/17892762/mysql-this-version-of-mysql-doesnt-yet-support-limit-in-all-any-some-subqu
1395
1395
  const subSubQuery = this.getKnex().select(pks).from(knexQuery);
1396
- subSubQuery.__raw = true; // tag it as there is now way to check via `instanceof`
1396
+ core_1.RawQueryFragment.markRaw(subSubQuery);
1397
1397
  this._limit = undefined;
1398
1398
  this._offset = undefined;
1399
1399
  if (this._fields.some(f => core_1.RawQueryFragment.isKnownFragment(f))) {
@@ -1441,7 +1441,7 @@ class QueryBuilder {
1441
1441
  // wrap one more time to get around MySQL limitations
1442
1442
  // https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause
1443
1443
  const subSubQuery = this.getKnex().select(this.prepareFields(meta.primaryKeys)).from(subQuery.as(this.mainAlias.aliasName));
1444
- subSubQuery.__raw = true; // tag it as there is now way to check via `instanceof`
1444
+ core_1.RawQueryFragment.markRaw(subSubQuery);
1445
1445
  const method = this.flags.has(core_1.QueryFlag.UPDATE_SUB_QUERY) ? 'update' : 'delete';
1446
1446
  this._cond = {}; // otherwise we would trigger validation error
1447
1447
  this._joins = {}; // included in the subquery