@mikro-orm/knex 7.0.0-dev.8 → 7.0.0-dev.80

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 (55) hide show
  1. package/AbstractSqlConnection.d.ts +11 -5
  2. package/AbstractSqlConnection.js +78 -32
  3. package/AbstractSqlDriver.d.ts +9 -5
  4. package/AbstractSqlDriver.js +274 -226
  5. package/AbstractSqlPlatform.js +5 -5
  6. package/PivotCollectionPersister.d.ts +3 -2
  7. package/PivotCollectionPersister.js +12 -21
  8. package/README.md +3 -2
  9. package/SqlEntityManager.d.ts +9 -2
  10. package/SqlEntityManager.js +2 -2
  11. package/dialects/mssql/MsSqlNativeQueryBuilder.d.ts +2 -0
  12. package/dialects/mssql/MsSqlNativeQueryBuilder.js +44 -3
  13. package/dialects/mysql/MySqlExceptionConverter.d.ts +3 -3
  14. package/dialects/mysql/MySqlExceptionConverter.js +4 -5
  15. package/dialects/mysql/MySqlSchemaHelper.js +2 -2
  16. package/dialects/postgresql/PostgreSqlTableCompiler.d.ts +1 -0
  17. package/dialects/postgresql/PostgreSqlTableCompiler.js +1 -0
  18. package/dialects/sqlite/BaseSqliteConnection.d.ts +3 -2
  19. package/dialects/sqlite/BaseSqliteConnection.js +2 -8
  20. package/dialects/sqlite/BaseSqlitePlatform.js +1 -2
  21. package/dialects/sqlite/SqliteExceptionConverter.d.ts +2 -2
  22. package/dialects/sqlite/SqliteExceptionConverter.js +6 -4
  23. package/dialects/sqlite/SqliteSchemaHelper.js +5 -6
  24. package/index.d.ts +1 -1
  25. package/index.js +1 -1
  26. package/package.json +5 -5
  27. package/query/ArrayCriteriaNode.d.ts +1 -0
  28. package/query/ArrayCriteriaNode.js +3 -0
  29. package/query/CriteriaNode.d.ts +4 -2
  30. package/query/CriteriaNode.js +11 -6
  31. package/query/CriteriaNodeFactory.js +12 -7
  32. package/query/NativeQueryBuilder.js +1 -1
  33. package/query/ObjectCriteriaNode.d.ts +1 -0
  34. package/query/ObjectCriteriaNode.js +39 -10
  35. package/query/QueryBuilder.d.ts +59 -7
  36. package/query/QueryBuilder.js +177 -53
  37. package/query/QueryBuilderHelper.d.ts +1 -1
  38. package/query/QueryBuilderHelper.js +18 -11
  39. package/query/ScalarCriteriaNode.d.ts +3 -3
  40. package/query/ScalarCriteriaNode.js +9 -7
  41. package/query/index.d.ts +1 -0
  42. package/query/index.js +1 -0
  43. package/query/raw.d.ts +59 -0
  44. package/query/raw.js +68 -0
  45. package/query/rawKnex.d.ts +58 -0
  46. package/query/rawKnex.js +72 -0
  47. package/schema/DatabaseSchema.js +25 -4
  48. package/schema/DatabaseTable.d.ts +5 -4
  49. package/schema/DatabaseTable.js +68 -34
  50. package/schema/SchemaComparator.js +4 -4
  51. package/schema/SchemaHelper.d.ts +2 -0
  52. package/schema/SchemaHelper.js +14 -10
  53. package/schema/SqlSchemaGenerator.d.ts +13 -6
  54. package/schema/SqlSchemaGenerator.js +40 -19
  55. package/typings.d.ts +85 -3
@@ -21,12 +21,12 @@ export class AbstractSqlPlatform extends Platform {
21
21
  lookupExtensions(orm) {
22
22
  SqlSchemaGenerator.register(orm);
23
23
  }
24
- /* v8 ignore next 3: kept for type inference only */
24
+ /* v8 ignore next: kept for type inference only */
25
25
  getSchemaGenerator(driver, em) {
26
26
  return new SqlSchemaGenerator(em ?? driver);
27
27
  }
28
- /* v8 ignore next 4 */
29
28
  /** @internal */
29
+ /* v8 ignore next */
30
30
  createNativeQueryBuilder() {
31
31
  return new NativeQueryBuilder(this);
32
32
  }
@@ -43,13 +43,13 @@ export class AbstractSqlPlatform extends Platform {
43
43
  return 'rollback';
44
44
  }
45
45
  getSavepointSQL(savepointName) {
46
- return `savepoint ${savepointName}`;
46
+ return `savepoint ${this.quoteIdentifier(savepointName)}`;
47
47
  }
48
48
  getRollbackToSavepointSQL(savepointName) {
49
- return `rollback to savepoint ${savepointName}`;
49
+ return `rollback to savepoint ${this.quoteIdentifier(savepointName)}`;
50
50
  }
51
51
  getReleaseSavepointSQL(savepointName) {
52
- return `release savepoint ${savepointName}`;
52
+ return `release savepoint ${this.quoteIdentifier(savepointName)}`;
53
53
  }
54
54
  quoteValue(value) {
55
55
  if (isRaw(value)) {
@@ -1,16 +1,17 @@
1
- import { type EntityMetadata, type EntityProperty, type Primary, type Transaction } from '@mikro-orm/core';
1
+ import { type Dictionary, type EntityMetadata, type EntityProperty, type Primary, type Transaction } from '@mikro-orm/core';
2
2
  import { type AbstractSqlDriver } from './AbstractSqlDriver.js';
3
3
  export declare class PivotCollectionPersister<Entity extends object> {
4
4
  private readonly meta;
5
5
  private readonly driver;
6
6
  private readonly ctx?;
7
7
  private readonly schema?;
8
+ private readonly loggerContext?;
8
9
  private readonly platform;
9
10
  private readonly inserts;
10
11
  private readonly deletes;
11
12
  private readonly batchSize;
12
13
  private order;
13
- constructor(meta: EntityMetadata<Entity>, driver: AbstractSqlDriver, ctx?: Transaction | undefined, schema?: string | undefined);
14
+ constructor(meta: EntityMetadata<Entity>, driver: AbstractSqlDriver, ctx?: Transaction | undefined, schema?: string | undefined, loggerContext?: Dictionary | undefined);
14
15
  enqueueUpdate(prop: EntityProperty<Entity>, insertDiff: Primary<Entity>[][], deleteDiff: Primary<Entity>[][] | boolean, pks: Primary<Entity>[]): void;
15
16
  private enqueueInsert;
16
17
  private enqueueDelete;
@@ -1,4 +1,3 @@
1
- import { Utils, } from '@mikro-orm/core';
2
1
  class InsertStatement {
3
2
  keys;
4
3
  data;
@@ -38,16 +37,18 @@ export class PivotCollectionPersister {
38
37
  driver;
39
38
  ctx;
40
39
  schema;
40
+ loggerContext;
41
41
  platform;
42
42
  inserts = new Map();
43
43
  deletes = new Map();
44
44
  batchSize;
45
45
  order = 0;
46
- constructor(meta, driver, ctx, schema) {
46
+ constructor(meta, driver, ctx, schema, loggerContext) {
47
47
  this.meta = meta;
48
48
  this.driver = driver;
49
49
  this.ctx = ctx;
50
50
  this.schema = schema;
51
+ this.loggerContext = loggerContext;
51
52
  this.platform = this.driver.getPlatform();
52
53
  this.batchSize = this.driver.config.get('batchSize');
53
54
  }
@@ -99,6 +100,7 @@ export class PivotCollectionPersister {
99
100
  await this.driver.nativeDelete(this.meta.className, cond, {
100
101
  ctx: this.ctx,
101
102
  schema: this.schema,
103
+ loggerContext: this.loggerContext,
102
104
  });
103
105
  }
104
106
  }
@@ -110,26 +112,15 @@ export class PivotCollectionPersister {
110
112
  items[insert.order] = insert.getData();
111
113
  }
112
114
  items = items.filter(i => i);
113
- if (this.platform.allowsMultiInsert()) {
114
- for (let i = 0; i < items.length; i += this.batchSize) {
115
- const chunk = items.slice(i, i + this.batchSize);
116
- await this.driver.nativeInsertMany(this.meta.className, chunk, {
117
- ctx: this.ctx,
118
- schema: this.schema,
119
- convertCustomTypes: false,
120
- processCollections: false,
121
- });
122
- }
123
- /* v8 ignore start */
124
- }
125
- else {
126
- await Utils.runSerial(items, item => {
127
- return this.driver.createQueryBuilder(this.meta.className, this.ctx, 'write')
128
- .withSchema(this.schema)
129
- .insert(item)
130
- .execute('run', false);
115
+ for (let i = 0; i < items.length; i += this.batchSize) {
116
+ const chunk = items.slice(i, i + this.batchSize);
117
+ await this.driver.nativeInsertMany(this.meta.className, chunk, {
118
+ ctx: this.ctx,
119
+ schema: this.schema,
120
+ convertCustomTypes: false,
121
+ processCollections: false,
122
+ loggerContext: this.loggerContext,
131
123
  });
132
124
  }
133
- /* v8 ignore stop */
134
125
  }
135
126
  }
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
  [![Chat on discord](https://img.shields.io/discord/1214904142443839538?label=discord&color=blue)](https://discord.gg/w8bjxFHS7X)
12
12
  [![Downloads](https://img.shields.io/npm/dm/@mikro-orm/core.svg)](https://www.npmjs.com/package/@mikro-orm/core)
13
13
  [![Coverage Status](https://img.shields.io/coveralls/mikro-orm/mikro-orm.svg)](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
14
- [![Maintainability](https://api.codeclimate.com/v1/badges/27999651d3adc47cfa40/maintainability)](https://codeclimate.com/github/mikro-orm/mikro-orm/maintainability)
15
14
  [![Build Status](https://github.com/mikro-orm/mikro-orm/workflows/tests/badge.svg?branch=master)](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
- - [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
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).
@@ -1,8 +1,13 @@
1
- import { EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions, type RawQueryFragment } from '@mikro-orm/core';
1
+ import { type EntitySchemaWithMeta, EntityManager, type AnyEntity, type ConnectionType, type EntityData, type EntityName, type EntityRepository, type GetRepository, type QueryResult, type FilterQuery, type LoggingOptions, type RawQueryFragment } from '@mikro-orm/core';
2
2
  import type { AbstractSqlDriver } from './AbstractSqlDriver.js';
3
3
  import type { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
4
4
  import type { QueryBuilder } from './query/QueryBuilder.js';
5
5
  import type { SqlEntityRepository } from './SqlEntityRepository.js';
6
+ import type { Kysely } from 'kysely';
7
+ import type { InferKyselyDB } from './typings.js';
8
+ export interface GetKyselyOptions {
9
+ type?: ConnectionType;
10
+ }
6
11
  /**
7
12
  * @inheritDoc
8
13
  */
@@ -18,8 +23,10 @@ export declare class SqlEntityManager<Driver extends AbstractSqlDriver = Abstrac
18
23
  /**
19
24
  * Returns configured Kysely instance.
20
25
  */
21
- getKysely(type?: ConnectionType): import("kysely").Kysely<any>;
26
+ getKysely<TDB = undefined, TOptions extends GetKyselyOptions = GetKyselyOptions>(options?: TOptions): Kysely<TDB extends undefined ? InferKyselyDB<EntitiesFromManager<this>, TOptions> : TDB>;
22
27
  execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: any[], method?: 'all' | 'get' | 'run', loggerContext?: LoggingOptions): Promise<T>;
23
28
  getRepository<T extends object, U extends EntityRepository<T> = SqlEntityRepository<T>>(entityName: EntityName<T>): GetRepository<T, U>;
24
29
  protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
25
30
  }
31
+ type EntitiesFromManager<TEntityManager extends EntityManager<any>> = NonNullable<TEntityManager['~entities']> extends any[] ? (Extract<NonNullable<TEntityManager['~entities']>[number], EntitySchemaWithMeta>) : never;
32
+ export {};
@@ -19,8 +19,8 @@ export class SqlEntityManager extends EntityManager {
19
19
  /**
20
20
  * Returns configured Kysely instance.
21
21
  */
22
- getKysely(type) {
23
- return this.getConnection(type).getClient();
22
+ getKysely(options = {}) {
23
+ return this.getConnection(options.type).getClient();
24
24
  }
25
25
  async execute(query, params = [], method = 'all', loggerContext) {
26
26
  return this.getDriver().execute(query, params, method, this.getContext(false).getTransactionContext(), loggerContext);
@@ -5,6 +5,8 @@ export declare class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
5
5
  sql: string;
6
6
  params: unknown[];
7
7
  };
8
+ protected compileInsert(): void;
9
+ private appendOutputTable;
8
10
  private compileUpsert;
9
11
  protected compileSelect(): void;
10
12
  protected addLockClause(): void;
@@ -12,6 +12,10 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
12
12
  if (this.options.flags?.has(QueryFlag.IDENTITY_INSERT)) {
13
13
  this.parts.push(`set identity_insert ${this.getTableName()} on;`);
14
14
  }
15
+ const { prefix, suffix } = this.appendOutputTable();
16
+ if (prefix) {
17
+ this.parts.push(prefix);
18
+ }
15
19
  if (this.options.comment) {
16
20
  this.parts.push(...this.options.comment.map(comment => `/* ${comment} */`));
17
21
  }
@@ -37,7 +41,11 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
37
41
  this.compileTruncate();
38
42
  break;
39
43
  }
40
- if ([QueryType.INSERT, QueryType.UPDATE, QueryType.DELETE].includes(this.type)) {
44
+ if (suffix) {
45
+ this.parts[this.parts.length - 1] += ';';
46
+ this.parts.push(suffix);
47
+ }
48
+ else if ([QueryType.INSERT, QueryType.UPDATE, QueryType.DELETE].includes(this.type)) {
41
49
  this.parts[this.parts.length - 1] += '; select @@rowcount;';
42
50
  }
43
51
  }
@@ -46,6 +54,37 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
46
54
  }
47
55
  return this.combineParts();
48
56
  }
57
+ compileInsert() {
58
+ if (!this.options.data) {
59
+ throw new Error('No data provided');
60
+ }
61
+ this.parts.push('insert');
62
+ this.addHintComment();
63
+ this.parts.push(`into ${this.getTableName()}`);
64
+ if (Object.keys(this.options.data).length === 0) {
65
+ this.addOutputClause('inserted');
66
+ this.parts.push('default values');
67
+ return;
68
+ }
69
+ const parts = this.processInsertData();
70
+ if (this.options.flags?.has(QueryFlag.OUTPUT_TABLE)) {
71
+ this.parts[this.parts.length - 2] += ' into #out ';
72
+ }
73
+ this.parts.push(parts.join(', '));
74
+ }
75
+ appendOutputTable() {
76
+ if (!this.options.flags?.has(QueryFlag.OUTPUT_TABLE)) {
77
+ return { prefix: '', suffix: '' };
78
+ }
79
+ const returningFields = this.options.returning;
80
+ const selections = returningFields
81
+ .map(field => `[t].${this.platform.quoteIdentifier(field)}`)
82
+ .join(',');
83
+ return {
84
+ prefix: `select top(0) ${selections} into #out from ${this.getTableName()} as t left join ${this.getTableName()} on 0 = 1;`,
85
+ suffix: `select ${selections} from #out as t; drop table #out`,
86
+ };
87
+ }
49
88
  compileUpsert() {
50
89
  const clause = this.options.onConflict;
51
90
  const dataAsArray = Utils.asArray(this.options.data);
@@ -82,7 +121,9 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
82
121
  }
83
122
  this.parts.push('then update set');
84
123
  if (!clause.merge || Array.isArray(clause.merge)) {
85
- const parts = keys.map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
124
+ const parts = (clause.merge || keys)
125
+ .filter(field => !Array.isArray(clause.fields) || !clause.fields.includes(field))
126
+ .map((column) => `${this.quote(column)} = tsource.${this.quote(column)}`);
86
127
  this.parts.push(parts.join(', '));
87
128
  }
88
129
  else if (typeof clause.merge === 'object') {
@@ -127,7 +168,7 @@ export class MsSqlNativeQueryBuilder extends NativeQueryBuilder {
127
168
  this.parts.push(`order by ${this.options.orderBy}`);
128
169
  }
129
170
  if (this.options.offset != null) {
130
- /* v8 ignore next 3 */
171
+ /* v8 ignore next */
131
172
  if (!this.options.orderBy) {
132
173
  throw new Error('Order by clause is required for pagination');
133
174
  }
@@ -1,9 +1,9 @@
1
1
  import { ExceptionConverter, type Dictionary, type DriverException } from '@mikro-orm/core';
2
2
  export declare class MySqlExceptionConverter extends ExceptionConverter {
3
3
  /**
4
- * @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
5
- * @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
6
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
4
+ * @see http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
5
+ * @see http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
6
+ * @see https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
7
7
  */
8
8
  convertException(exception: Error & Dictionary): DriverException;
9
9
  }
@@ -1,12 +1,12 @@
1
1
  import { DeadlockException, LockWaitTimeoutException, TableExistsException, TableNotFoundException, ForeignKeyConstraintViolationException, UniqueConstraintViolationException, InvalidFieldNameException, NonUniqueFieldNameException, SyntaxErrorException, ConnectionException, NotNullConstraintViolationException, ExceptionConverter, CheckConstraintViolationException, } from '@mikro-orm/core';
2
2
  export class MySqlExceptionConverter extends ExceptionConverter {
3
3
  /**
4
- * @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
5
- * @link http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
6
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
4
+ * @see http://dev.mysql.com/doc/refman/5.7/en/error-messages-client.html
5
+ * @see http://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html
6
+ * @see https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractMySQLDriver.php
7
7
  */
8
8
  convertException(exception) {
9
- /* v8 ignore start */
9
+ /* v8 ignore next */
10
10
  switch (exception.errno) {
11
11
  case 1213:
12
12
  return new DeadlockException(exception);
@@ -75,7 +75,6 @@ export class MySqlExceptionConverter extends ExceptionConverter {
75
75
  case 1566:
76
76
  return new NotNullConstraintViolationException(exception);
77
77
  }
78
- /* v8 ignore stop */
79
78
  return super.convertException(exception);
80
79
  }
81
80
  }
@@ -78,7 +78,7 @@ export class MySqlSchemaHelper extends SchemaHelper {
78
78
  return ret;
79
79
  }
80
80
  getCreateIndexSQL(tableName, index, partialExpression = false) {
81
- /* v8 ignore next 3 */
81
+ /* v8 ignore next */
82
82
  if (index.expression && !partialExpression) {
83
83
  return index.expression;
84
84
  }
@@ -146,7 +146,7 @@ export class MySqlSchemaHelper extends SchemaHelper {
146
146
  return ret;
147
147
  }
148
148
  async getAllChecks(connection, tables) {
149
- /* v8 ignore next 3 */
149
+ /* v8 ignore next */
150
150
  if (!(await this.supportsCheckConstraints(connection))) {
151
151
  return {};
152
152
  }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,6 @@
1
1
  import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
2
2
  export declare abstract class BaseSqliteConnection extends AbstractSqlConnection {
3
- connect(): Promise<void>;
4
- getClientUrl(): string;
3
+ connect(options?: {
4
+ skipOnConnect?: boolean;
5
+ }): Promise<void>;
5
6
  }
@@ -1,14 +1,8 @@
1
- import { dirname } from 'node:path';
2
1
  import { CompiledQuery } from 'kysely';
3
- import { Utils } from '@mikro-orm/core';
4
2
  import { AbstractSqlConnection } from '../../AbstractSqlConnection.js';
5
3
  export class BaseSqliteConnection extends AbstractSqlConnection {
6
- async connect() {
7
- await super.connect();
8
- Utils.ensureDir(dirname(this.config.get('dbName')));
4
+ async connect(options) {
5
+ await super.connect(options);
9
6
  await this.client.executeQuery(CompiledQuery.raw('pragma foreign_keys = on'));
10
7
  }
11
- getClientUrl() {
12
- return '';
13
- }
14
8
  }
@@ -1,4 +1,3 @@
1
- import { Utils } from '@mikro-orm/core';
2
1
  import { AbstractSqlPlatform } from '../../AbstractSqlPlatform.js';
3
2
  import { SqliteNativeQueryBuilder } from './SqliteNativeQueryBuilder.js';
4
3
  import { SqliteSchemaHelper } from './SqliteSchemaHelper.js';
@@ -29,7 +28,7 @@ export class BaseSqlitePlatform extends AbstractSqlPlatform {
29
28
  return ['begin'];
30
29
  }
31
30
  getEnumTypeDeclarationSQL(column) {
32
- if (column.items?.every(item => Utils.isString(item))) {
31
+ if (column.items?.every(item => typeof item === 'string')) {
33
32
  return 'text';
34
33
  }
35
34
  /* v8 ignore next */
@@ -2,8 +2,8 @@ import { ExceptionConverter, type Dictionary, type DriverException } from '@mikr
2
2
  export declare class SqliteExceptionConverter extends ExceptionConverter {
3
3
  /**
4
4
  * @inheritDoc
5
- * @link http://www.sqlite.org/c3ref/c_abort.html
6
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractSQLiteDriver.php
5
+ * @see http://www.sqlite.org/c3ref/c_abort.html
6
+ * @see https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractSQLiteDriver.php
7
7
  */
8
8
  convertException(exception: Error & Dictionary): DriverException;
9
9
  }
@@ -2,11 +2,11 @@ import { ConnectionException, ExceptionConverter, InvalidFieldNameException, Loc
2
2
  export class SqliteExceptionConverter extends ExceptionConverter {
3
3
  /**
4
4
  * @inheritDoc
5
- * @link http://www.sqlite.org/c3ref/c_abort.html
6
- * @link https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractSQLiteDriver.php
5
+ * @see http://www.sqlite.org/c3ref/c_abort.html
6
+ * @see https://github.com/doctrine/dbal/blob/master/src/Driver/AbstractSQLiteDriver.php
7
7
  */
8
8
  convertException(exception) {
9
- /* v8 ignore start */
9
+ /* v8 ignore next */
10
10
  if (exception.message.includes('database is locked')) {
11
11
  return new LockWaitTimeoutException(exception);
12
12
  }
@@ -19,6 +19,7 @@ export class SqliteExceptionConverter extends ExceptionConverter {
19
19
  if (exception.message.includes('may not be NULL') || exception.message.includes('NOT NULL constraint failed')) {
20
20
  return new NotNullConstraintViolationException(exception);
21
21
  }
22
+ /* v8 ignore next */
22
23
  if (exception.message.includes('CHECK constraint failed')) {
23
24
  return new CheckConstraintViolationException(exception);
24
25
  }
@@ -37,16 +38,17 @@ export class SqliteExceptionConverter extends ExceptionConverter {
37
38
  if (exception.message.includes('syntax error')) {
38
39
  return new SyntaxErrorException(exception);
39
40
  }
41
+ /* v8 ignore next */
40
42
  if (exception.message.includes('attempt to write a readonly database')) {
41
43
  return new ReadOnlyException(exception);
42
44
  }
45
+ /* v8 ignore next */
43
46
  if (exception.message.includes('unable to open database file')) {
44
47
  return new ConnectionException(exception);
45
48
  }
46
49
  if (exception.message.includes('FOREIGN KEY constraint failed')) {
47
50
  return new ForeignKeyConstraintViolationException(exception);
48
51
  }
49
- /* v8 ignore stop */
50
52
  return super.convertException(exception);
51
53
  }
52
54
  }
@@ -114,7 +114,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
114
114
  }).join(';\n');
115
115
  }
116
116
  getCreateIndexSQL(tableName, index) {
117
- /* v8 ignore next 3 */
117
+ /* v8 ignore next */
118
118
  if (index.expression) {
119
119
  return index.expression;
120
120
  }
@@ -134,7 +134,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
134
134
  const constraints = [];
135
135
  // extract all columns definitions
136
136
  let columnsDef = sql.replaceAll('\n', '').match(new RegExp(`create table [\`"']?.*?[\`"']? \\((.*)\\)`, 'i'))?.[1];
137
- /* v8 ignore start */
137
+ /* v8 ignore next */
138
138
  if (columnsDef) {
139
139
  if (columnsDef.includes(', constraint ')) {
140
140
  constraints.push(...columnsDef.substring(columnsDef.indexOf(', constraint') + 2).split(', '));
@@ -150,7 +150,6 @@ export class SqliteSchemaHelper extends SchemaHelper {
150
150
  }
151
151
  }
152
152
  }
153
- /* v8 ignore stop */
154
153
  return { columns, constraints };
155
154
  }
156
155
  async getColumns(connection, tableName, schemaName) {
@@ -167,7 +166,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
167
166
  if (col.hidden > 1) {
168
167
  /* v8 ignore next */
169
168
  const storage = col.hidden === 2 ? 'virtual' : 'stored';
170
- const re = `(generated always)? as \\((.*)\\)( ${storage})?$`;
169
+ const re = new RegExp(`(generated always)? as \\((.*)\\)( ${storage})?$`, 'i');
171
170
  const match = columnDefinitions[col.name].definition.match(re);
172
171
  if (match) {
173
172
  generated = `${match[2]} ${storage}`;
@@ -194,7 +193,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
194
193
  // check constraints are defined as (note that last closing paren is missing):
195
194
  // `type` text check (`type` in ('local', 'global')
196
195
  const match = item.match(/[`["']([^`\]"']+)[`\]"'] text check \(.* \((.*)\)/i);
197
- /* v8 ignore next 3 */
196
+ /* v8 ignore next */
198
197
  if (match) {
199
198
  o[match[1]] = match[2].split(',').map((item) => item.trim().match(/^\(?'(.*)'/)[1]);
200
199
  }
@@ -321,7 +320,7 @@ export class SqliteSchemaHelper extends SchemaHelper {
321
320
  for (const index of Object.values(diff.changedIndexes)) {
322
321
  this.append(ret, this.dropIndex(diff.name, index));
323
322
  }
324
- /* v8 ignore next 3 */
323
+ /* v8 ignore next */
325
324
  if (!safe && Object.values(diff.removedColumns).length > 0) {
326
325
  this.append(ret, this.getDropColumnsSQL(tableName, Object.values(diff.removedColumns), schemaName));
327
326
  }
package/index.d.ts CHANGED
@@ -2,7 +2,6 @@
2
2
  * @packageDocumentation
3
3
  * @module knex
4
4
  */
5
- /** @ignore */
6
5
  export { Kysely } from 'kysely';
7
6
  export * from '@mikro-orm/core';
8
7
  export * from './AbstractSqlConnection.js';
@@ -11,6 +10,7 @@ export * from './AbstractSqlPlatform.js';
11
10
  export * from './SqlEntityManager.js';
12
11
  export * from './SqlEntityRepository.js';
13
12
  export * from './query/index.js';
13
+ export { raw } from './query/index.js';
14
14
  export * from './schema/index.js';
15
15
  export * from './dialects/index.js';
16
16
  export * from './typings.js';
package/index.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * @packageDocumentation
3
3
  * @module knex
4
4
  */
5
- /** @ignore */
6
5
  export { Kysely } from 'kysely';
7
6
  export * from '@mikro-orm/core';
8
7
  export * from './AbstractSqlConnection.js';
@@ -11,6 +10,7 @@ export * from './AbstractSqlPlatform.js';
11
10
  export * from './SqlEntityManager.js';
12
11
  export * from './SqlEntityRepository.js';
13
12
  export * from './query/index.js';
13
+ export { raw } from './query/index.js';
14
14
  export * from './schema/index.js';
15
15
  export * from './dialects/index.js';
16
16
  export * from './typings.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "7.0.0-dev.8",
3
+ "version": "7.0.0-dev.80",
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
  "type": "module",
6
6
  "exports": {
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "homepage": "https://mikro-orm.io",
40
40
  "engines": {
41
- "node": ">= 22.11.0"
41
+ "node": ">= 22.17.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "yarn clean && yarn compile && yarn copy",
@@ -50,13 +50,13 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "kysely": "https://pkg.pr.new/kysely-org/kysely/kysely@2b7007e",
53
+ "kysely": "0.28.8",
54
54
  "sqlstring": "2.3.3"
55
55
  },
56
56
  "devDependencies": {
57
- "@mikro-orm/core": "^6.4.9"
57
+ "@mikro-orm/core": "^6.6.1"
58
58
  },
59
59
  "peerDependencies": {
60
- "@mikro-orm/core": "7.0.0-dev.8"
60
+ "@mikro-orm/core": "7.0.0-dev.80"
61
61
  }
62
62
  }
@@ -7,4 +7,5 @@ export declare class ArrayCriteriaNode<T extends object> extends CriteriaNode<T>
7
7
  process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
8
8
  unwrap(): any;
9
9
  willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): any;
10
+ isStrict(): boolean;
10
11
  }
@@ -18,4 +18,7 @@ export class ArrayCriteriaNode extends CriteriaNode {
18
18
  return node.willAutoJoin(qb, alias, options);
19
19
  });
20
20
  }
21
+ isStrict() {
22
+ return this.strict || this.payload.some((node) => node.isStrict());
23
+ }
21
24
  }
@@ -11,20 +11,22 @@ export declare class CriteriaNode<T extends object> implements ICriteriaNode<T>
11
11
  readonly entityName: string;
12
12
  readonly parent?: ICriteriaNode<T> | undefined;
13
13
  readonly key?: EntityKey<T> | undefined;
14
+ readonly strict: boolean;
14
15
  payload: any;
15
16
  prop?: EntityProperty<T>;
16
17
  index?: number;
17
- constructor(metadata: MetadataStorage, entityName: string, parent?: ICriteriaNode<T> | undefined, key?: EntityKey<T> | undefined, validate?: boolean);
18
+ constructor(metadata: MetadataStorage, entityName: string, parent?: ICriteriaNode<T> | undefined, key?: EntityKey<T> | undefined, validate?: boolean, strict?: boolean);
18
19
  process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
19
20
  unwrap(): any;
20
21
  shouldInline(payload: any): boolean;
21
22
  willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
22
23
  shouldRename(payload: any): boolean;
23
- renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
24
+ renameFieldToPK<T>(qb: IQueryBuilder<T>, ownerAlias?: string): string;
24
25
  getPath(addIndex?: boolean): string;
25
26
  private isPivotJoin;
26
27
  getPivotPath(path: string): string;
27
28
  aliased(field: string, alias?: string): string;
29
+ isStrict(): boolean;
28
30
  /** @ignore */
29
31
  [inspect.custom](): string;
30
32
  }