@mikro-orm/better-sqlite 6.0.0-dev.6 → 6.0.0-dev.60

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.
@@ -3,6 +3,7 @@ import { AbstractSqlConnection } from '@mikro-orm/knex';
3
3
  export declare class BetterSqliteConnection extends AbstractSqlConnection {
4
4
  static readonly RUN_QUERY_RE: RegExp;
5
5
  static readonly RUN_QUERY_RETURNING: RegExp;
6
+ createKnex(): void;
6
7
  connect(): Promise<void>;
7
8
  getDefaultClientUrl(): string;
8
9
  getClientUrl(): string;
@@ -6,10 +6,14 @@ const path_1 = require("path");
6
6
  const knex_1 = require("@mikro-orm/knex");
7
7
  const core_1 = require("@mikro-orm/core");
8
8
  class BetterSqliteConnection extends knex_1.AbstractSqlConnection {
9
- async connect() {
10
- await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(this.config.get('dbName')));
9
+ createKnex() {
11
10
  this.getPatchedDialect();
12
11
  this.client = this.createKnexClient('better-sqlite3');
12
+ this.connected = true;
13
+ }
14
+ async connect() {
15
+ this.createKnex();
16
+ await (0, fs_extra_1.ensureDir)((0, path_1.dirname)(this.config.get('dbName')));
13
17
  await this.client.raw('pragma foreign_keys = on');
14
18
  }
15
19
  getDefaultClientUrl() {
@@ -107,8 +111,8 @@ class BetterSqliteConnection extends knex_1.AbstractSqlConnection {
107
111
  // no need for temp tables if we just add a column
108
112
  if (addColumnQuery) {
109
113
  const onUpdate = foreignInfo.onUpdate ? ` on update ${foreignInfo.onUpdate}` : '';
110
- const onDelete = foreignInfo.onDelete ? ` on delete ${foreignInfo.onDelete}` : '';
111
- addColumnQuery.sql += ` constraint ${keyName} references ${inTable} (${references})${onUpdate}${onDelete}`;
114
+ const deleteRule = foreignInfo.deleteRule ? ` on delete ${foreignInfo.deleteRule}` : '';
115
+ addColumnQuery.sql += ` constraint ${keyName} references ${inTable} (${references})${onUpdate}${deleteRule}`;
112
116
  return;
113
117
  }
114
118
  // eslint-disable-next-line @typescript-eslint/no-this-alias
@@ -146,6 +150,6 @@ class BetterSqliteConnection extends knex_1.AbstractSqlConnection {
146
150
  }
147
151
  }
148
152
  }
149
- exports.BetterSqliteConnection = BetterSqliteConnection;
150
153
  BetterSqliteConnection.RUN_QUERY_RE = /^insert into|^update|^delete|^truncate/;
151
- BetterSqliteConnection.RUN_QUERY_RETURNING = /^insert into .* returning .*/;
154
+ BetterSqliteConnection.RUN_QUERY_RETURNING = /^insert into ([\s\S])* returning .*/;
155
+ exports.BetterSqliteConnection = BetterSqliteConnection;
@@ -1,11 +1,19 @@
1
1
  import { MikroORM } from '@mikro-orm/core';
2
- import type { Options } from '@mikro-orm/core';
2
+ import type { Options, IDatabaseDriver } from '@mikro-orm/core';
3
3
  import { BetterSqliteDriver } from './BetterSqliteDriver';
4
4
  /**
5
5
  * @inheritDoc
6
6
  */
7
7
  export declare class BetterSqliteMikroORM extends MikroORM<BetterSqliteDriver> {
8
8
  private static DRIVER;
9
+ /**
10
+ * @inheritDoc
11
+ */
12
+ static init<D extends IDatabaseDriver = BetterSqliteDriver>(options?: Options<D>): Promise<MikroORM<D>>;
13
+ /**
14
+ * @inheritDoc
15
+ */
16
+ static initSync<D extends IDatabaseDriver = BetterSqliteDriver>(options: Options<D>): MikroORM<D>;
9
17
  }
10
18
  export type BetterSqliteOptions = Options<BetterSqliteDriver>;
11
19
  export declare function defineBetterSqliteConfig(options: BetterSqliteOptions): Options<BetterSqliteDriver>;
@@ -7,9 +7,21 @@ const BetterSqliteDriver_1 = require("./BetterSqliteDriver");
7
7
  * @inheritDoc
8
8
  */
9
9
  class BetterSqliteMikroORM extends core_1.MikroORM {
10
+ /**
11
+ * @inheritDoc
12
+ */
13
+ static async init(options) {
14
+ return super.init(options);
15
+ }
16
+ /**
17
+ * @inheritDoc
18
+ */
19
+ static initSync(options) {
20
+ return super.initSync(options);
21
+ }
10
22
  }
11
- exports.BetterSqliteMikroORM = BetterSqliteMikroORM;
12
23
  BetterSqliteMikroORM.DRIVER = BetterSqliteDriver_1.BetterSqliteDriver;
24
+ exports.BetterSqliteMikroORM = BetterSqliteMikroORM;
13
25
  /* istanbul ignore next */
14
26
  function defineBetterSqliteConfig(options) {
15
27
  return (0, core_1.defineConfig)({ driver: BetterSqliteDriver_1.BetterSqliteDriver, ...options });
@@ -86,9 +86,9 @@ class BetterSqlitePlatform extends knex_1.AbstractSqlPlatform {
86
86
  getSearchJsonPropertyKey(path, type, aliased) {
87
87
  const [a, ...b] = path;
88
88
  if (aliased) {
89
- return (0, core_1.expr)(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.join('.')}')`);
89
+ return (0, core_1.raw)(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.join('.')}')`);
90
90
  }
91
- return `json_extract(${this.quoteIdentifier(a)}, '$.${b.join('.')}')`;
91
+ return (0, core_1.raw)(`json_extract(${this.quoteIdentifier(a)}, '$.${b.join('.')}')`);
92
92
  }
93
93
  getIndexName(tableName, columns, type) {
94
94
  if (type === 'primary') {
@@ -1,5 +1,5 @@
1
1
  import type { Connection, Dictionary } from '@mikro-orm/core';
2
- import type { AbstractSqlConnection, Index, Check } from '@mikro-orm/knex';
2
+ import type { AbstractSqlConnection, IndexDef, CheckDef } from '@mikro-orm/knex';
3
3
  import { SchemaHelper } from '@mikro-orm/knex';
4
4
  export declare class BetterSqliteSchemaHelper extends SchemaHelper {
5
5
  disableForeignKeysSQL(): string;
@@ -7,10 +7,10 @@ export declare class BetterSqliteSchemaHelper extends SchemaHelper {
7
7
  supportsSchemaConstraints(): boolean;
8
8
  getListTablesSQL(): string;
9
9
  getColumns(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<any[]>;
10
- getEnumDefinitions(connection: AbstractSqlConnection, checks: Check[], tableName: string, schemaName: string): Promise<Dictionary<string[]>>;
11
- getPrimaryKeys(connection: AbstractSqlConnection, indexes: Index[] | undefined, tableName: string, schemaName?: string): Promise<string[]>;
12
- getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Index[]>;
13
- getChecks(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<Check[]>;
10
+ getEnumDefinitions(connection: AbstractSqlConnection, checks: CheckDef[], tableName: string, schemaName: string): Promise<Dictionary<string[]>>;
11
+ getPrimaryKeys(connection: AbstractSqlConnection, indexes: IndexDef[] | undefined, tableName: string, schemaName?: string): Promise<string[]>;
12
+ getIndexes(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<IndexDef[]>;
13
+ getChecks(connection: AbstractSqlConnection, tableName: string, schemaName?: string): Promise<CheckDef[]>;
14
14
  getForeignKeysSQL(tableName: string): string;
15
15
  mapForeignKeys(fks: any[], tableName: string): Dictionary;
16
16
  databaseExists(connection: Connection, name: string): Promise<boolean>;
package/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
  <a href="https://mikro-orm.io"><img src="https://raw.githubusercontent.com/mikro-orm/mikro-orm/master/docs/static/img/logo-readme.svg?sanitize=true" alt="MikroORM" /></a>
3
3
  </h1>
4
4
 
5
- TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/)
6
- and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL,
7
- MariaDB, PostgreSQL and SQLite databases.
5
+ TypeScript ORM for Node.js based on Data Mapper, [Unit of Work](https://mikro-orm.io/docs/unit-of-work/) and [Identity Map](https://mikro-orm.io/docs/identity-map/) patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
8
6
 
9
- > Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Nextras Orm](https://nextras.org/orm/).
7
+ > Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
10
8
 
11
9
  [![NPM version](https://img.shields.io/npm/v/@mikro-orm/core.svg)](https://www.npmjs.com/package/@mikro-orm/core)
12
10
  [![NPM dev version](https://img.shields.io/npm/v/@mikro-orm/core/next.svg)](https://www.npmjs.com/package/@mikro-orm/core)
@@ -31,13 +29,9 @@ So what benefits does it bring to us?
31
29
 
32
30
  ### Implicit Transactions
33
31
 
34
- First and most important implication of having Unit of Work is that it allows handling
35
- transactions automatically.
32
+ First and most important implication of having Unit of Work is that it allows handling transactions automatically.
36
33
 
37
- When you call `em.flush()`, all computed changes are queried inside a database
38
- transaction (if supported by given driver). This means that you can control the boundaries
39
- of transactions simply by calling `em.persistLater()` and once all your changes
40
- are ready, calling `flush()` will run them inside a transaction.
34
+ When you call `em.flush()`, all computed changes are queried inside a database transaction (if supported by given driver). This means that you can control the boundaries of transactions simply by calling `em.persistLater()` and once all your changes are ready, calling `flush()` will run them inside a transaction.
41
35
 
42
36
  > You can also control the transaction boundaries manually via `em.transactional(cb)`.
43
37
 
@@ -55,9 +49,7 @@ await em.flush();
55
49
 
56
50
  ### ChangeSet based persistence
57
51
 
58
- MikroORM allows you to implement your domain/business logic directly in the entities.
59
- To maintain always valid entities, you can use constructors to mark required properties.
60
- Let's define the `User` entity used in previous example:
52
+ MikroORM allows you to implement your domain/business logic directly in the entities. To maintain always valid entities, you can use constructors to mark required properties. Let's define the `User` entity used in previous example:
61
53
 
62
54
  ```typescript
63
55
  @Entity()
@@ -69,10 +61,10 @@ export class User {
69
61
  @Property()
70
62
  name!: string;
71
63
 
72
- @OneToOne()
64
+ @OneToOne(() => Address)
73
65
  address?: Address;
74
66
 
75
- @ManyToMany()
67
+ @ManyToMany(() => Car)
76
68
  cars = new Collection<Car>(this);
77
69
 
78
70
  constructor(name: string) {
@@ -95,7 +87,9 @@ then call `em.flush()`. This will trigger computing of change sets. Only entitie
95
87
  no transaction will be started.
96
88
 
97
89
  ```typescript
98
- const user = await em.findOneOrFail(User, 1, ['cars', 'address']);
90
+ const user = await em.findOneOrFail(User, 1, {
91
+ populate: ['cars', 'address.city'],
92
+ });
99
93
  user.title = 'Mr.';
100
94
  user.address.street = '10 Downing Street'; // address is 1:1 relation of Address entity
101
95
  user.cars.getItems().forEach(car => car.forSale = true); // cars is 1:m collection of Car entities
@@ -110,53 +104,49 @@ await em.flush();
110
104
 
111
105
  ```sql
112
106
  begin;
113
- update user set title = 'Mr.' where id = 1;
114
- update user_address set street = '10 Downing Street' where id = 123;
115
- update car set for_sale = true where id = 1;
116
- update car set for_sale = true where id = 2;
117
- update car set for_sale = true where id = 3;
118
- insert into car (brand, owner) values ('VW', 1);
107
+ update "user" set "title" = 'Mr.' where "id" = 1;
108
+ update "user_address" set "street" = '10 Downing Street' where "id" = 123;
109
+ update "car"
110
+ set "for_sale" = case
111
+ when ("id" = 1) then true
112
+ when ("id" = 2) then true
113
+ when ("id" = 3) then true
114
+ else "for_sale" end
115
+ where "id" in (1, 2, 3)
116
+ insert into "car" ("brand", "owner") values ('VW', 1);
119
117
  commit;
120
118
  ```
121
119
 
122
- ### Only One Instance of Entity
120
+ ### Identity Map
123
121
 
124
- Thanks to Identity Map, you will always have only one instance of given entity in one context.
125
- This allows for some optimizations (skipping loading of already loaded entities), as well as
126
- comparison by identity (`ent1 === ent2`).
122
+ Thanks to Identity Map, you will always have only one instance of given entity in one context. This allows for some optimizations (skipping loading of already loaded entities), as well as comparison by identity (`ent1 === ent2`).
127
123
 
128
124
  ## 📖 Documentation
129
125
 
130
- MikroORM v4 documentation, included in this repo in the root directory, is built with
131
- [Jekyll](https://jekyllrb.com/) and publicly hosted on GitHub Pages at https://mikro-orm.io.
132
-
133
- There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages
134
- (via `semantic-release`).
126
+ MikroORM documentation, included in this repo in the root directory, is built with [Docusaurus](https://docusaurus.io) and publicly hosted on GitHub Pages at https://mikro-orm.io.
135
127
 
136
- > You can browse MikroORM v3 docs at [https://mikro-orm.io/docs/3.6/installation](https://mikro-orm.io/docs/3.6/installation).
137
-
138
- > To upgrade to v4, please see the [upgrading guide](https://mikro-orm.io/docs/upgrading-v3-to-v4).
128
+ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages (via `semantic-release`).
139
129
 
140
130
  ## ✨ Core Features
141
131
 
142
- - [Clean and Simple Entity Definition](https://mikro-orm.io/docs/defining-entities/)
143
- - [Identity Map](https://mikro-orm.io/docs/identity-map/)
144
- - [Entity References](https://mikro-orm.io/docs/entity-references/)
145
- - [Using Entity Constructors](https://mikro-orm.io/docs/using-entity-constructors/)
146
- - [Modelling Relationships](https://mikro-orm.io/docs/relationships/)
147
- - [Collections](https://mikro-orm.io/docs/collections/)
148
- - [Unit of Work](https://mikro-orm.io/docs/unit-of-work/)
149
- - [Transactions](https://mikro-orm.io/docs/transactions/)
150
- - [Cascading persist and remove](https://mikro-orm.io/docs/cascading/)
151
- - [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys/)
152
- - [Filters](https://mikro-orm.io/docs/filters/)
153
- - [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder/)
154
- - [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate/)
155
- - [Property Validation](https://mikro-orm.io/docs/property-validation/)
156
- - [Lifecycle Hooks](https://mikro-orm.io/docs/lifecycle-hooks/)
157
- - [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js/)
158
- - [Schema Generator](https://mikro-orm.io/docs/schema-generator/)
159
- - [Entity Generator](https://mikro-orm.io/docs/entity-generator/)
132
+ - [Clean and Simple Entity Definition](https://mikro-orm.io/docs/defining-entities)
133
+ - [Identity Map](https://mikro-orm.io/docs/identity-map)
134
+ - [Entity References](https://mikro-orm.io/docs/entity-references)
135
+ - [Using Entity Constructors](https://mikro-orm.io/docs/entity-constructors)
136
+ - [Modelling Relationships](https://mikro-orm.io/docs/relationships)
137
+ - [Collections](https://mikro-orm.io/docs/collections)
138
+ - [Unit of Work](https://mikro-orm.io/docs/unit-of-work)
139
+ - [Transactions](https://mikro-orm.io/docs/transactions)
140
+ - [Cascading persist and remove](https://mikro-orm.io/docs/cascading)
141
+ - [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
142
+ - [Filters](https://mikro-orm.io/docs/filters)
143
+ - [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
144
+ - [Preloading Deeply Nested Structures via populate](https://mikro-orm.io/docs/nested-populate)
145
+ - [Property Validation](https://mikro-orm.io/docs/property-validation)
146
+ - [Lifecycle Hooks](https://mikro-orm.io/docs/lifecycle-hooks)
147
+ - [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
148
+ - [Schema Generator](https://mikro-orm.io/docs/schema-generator)
149
+ - [Entity Generator](https://mikro-orm.io/docs/entity-generator)
160
150
 
161
151
  ## 📦 Example Integrations
162
152
 
@@ -173,27 +163,14 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
173
163
  - [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
174
164
 
175
165
  ### JavaScript Examples
176
- - [Express + MongoDB](https://github.com/mikro-orm/express-js-example-app)
177
166
 
178
- ## Articles
179
-
180
- - Introducing MikroORM, TypeScript data-mapper ORM with Identity Map
181
- - on [medium.com](https://medium.com/dailyjs/introducing-mikro-orm-typescript-data-mapper-orm-with-identity-map-9ba58d049e02)
182
- - on [dev.to](https://dev.to/b4nan/introducing-mikroorm-typescript-data-mapper-orm-with-identity-map-pc8)
183
- - Handling transactions and concurrency in MikroORM
184
- - on [medium.com](https://medium.com/dailyjs/handling-transactions-and-concurrency-in-mikro-orm-ba80d0a65805)
185
- - on [dev.to](https://dev.to/b4nan/handling-transactions-and-concurrency-in-mikroorm-2cfj)
186
- - MikroORM 3: Knex.js, CLI, Schema Updates, Entity Generator and more…
187
- - on [medium.com](https://medium.com/dailyjs/mikro-orm-3-knex-js-cli-schema-updates-entity-generator-and-more-e51ecbbc508c)
188
- - on [dev.to](https://dev.to/b4nan/mikroorm-3-knex-js-cli-schema-updates-entity-generator-and-more-3g56)
167
+ - [Express + MongoDB](https://github.com/mikro-orm/express-js-example-app)
189
168
 
190
169
  ## 🚀 Quick Start
191
170
 
192
171
  First install the module via `yarn` or `npm` and do not forget to install the database driver as well:
193
172
 
194
- > Since v4, you should install the driver package, but not the db connector itself,
195
- > e.g. install `@mikro-orm/sqlite`, but not `sqlite3` as that is already included
196
- > in the driver package.
173
+ > Since v4, you should install the driver package, but not the db connector itself, e.g. install `@mikro-orm/sqlite`, but not `sqlite3` as that is already included in the driver package.
197
174
 
198
175
  ```sh
199
176
  yarn add @mikro-orm/core @mikro-orm/mongodb # for mongo
@@ -213,8 +190,7 @@ npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
213
190
  npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
214
191
  ```
215
192
 
216
- Next you will need to enable support for [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
217
- as well as `esModuleInterop` in `tsconfig.json` via:
193
+ Next, if you want to use decorators for your entity definition, you will need to enable support for [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) as well as `esModuleInterop` in `tsconfig.json` via:
218
194
 
219
195
  ```json
220
196
  "experimentalDecorators": true,
@@ -222,11 +198,11 @@ as well as `esModuleInterop` in `tsconfig.json` via:
222
198
  "esModuleInterop": true,
223
199
  ```
224
200
 
201
+ Alternatively, you can use [`EntitySchema`](https://mikro-orm.io/docs/entity-schema).
202
+
225
203
  Then call `MikroORM.init` as part of bootstrapping your app:
226
204
 
227
- > To access driver specific methods like `em.createQueryBuilder()` we need to specify
228
- > the driver type when calling `MikroORM.init()`. Alternatively we can cast the
229
- > `orm.em` to `EntityManager` exported from the driver package:
205
+ > To access driver specific methods like `em.createQueryBuilder()` we need to specify the driver type when calling `MikroORM.init()`. Alternatively we can cast the `orm.em` to `EntityManager` exported from the driver package:
230
206
  >
231
207
  > ```ts
232
208
  > import { EntityManager } from '@mikro-orm/postgresql';
@@ -245,14 +221,11 @@ const orm = await MikroORM.init<PostgreSqlDriver>({
245
221
  console.log(orm.em); // access EntityManager via `em` property
246
222
  ```
247
223
 
248
- There are more ways to configure your entities, take a look at
249
- [installation page](https://mikro-orm.io/docs/installation/).
224
+ There are more ways to configure your entities, take a look at [installation page](https://mikro-orm.io/docs/installation/).
250
225
 
251
226
  > Read more about all the possible configuration options in [Advanced Configuration](https://mikro-orm.io/docs/configuration) section.
252
227
 
253
- Then you will need to fork entity manager for each request so their
254
- [identity maps](https://mikro-orm.io/docs/identity-map/) will not collide.
255
- To do so, use the `RequestContext` helper:
228
+ Then you will need to fork entity manager for each request so their [identity maps](https://mikro-orm.io/docs/identity-map/) will not collide. To do so, use the `RequestContext` helper:
256
229
 
257
230
  ```typescript
258
231
  const app = express();
@@ -262,15 +235,11 @@ app.use((req, res, next) => {
262
235
  });
263
236
  ```
264
237
 
265
- > You should register this middleware as the last one just before request handlers and before
266
- > any of your custom middleware that is using the ORM. There might be issues when you register
267
- > it before request processing middleware like `queryParser` or `bodyParser`, so definitely
268
- > register the context after them.
238
+ > You should register this middleware as the last one just before request handlers and before any of your custom middleware that is using the ORM. There might be issues when you register it before request processing middleware like `queryParser` or `bodyParser`, so definitely register the context after them.
269
239
 
270
240
  More info about `RequestContext` is described [here](https://mikro-orm.io/docs/identity-map/#request-context).
271
241
 
272
- Now you can start defining your entities (in one of the `entities` folders). This is how
273
- simple entity can look like in mongo driver:
242
+ Now you can start defining your entities (in one of the `entities` folders). This is how simple entity can look like in mongo driver:
274
243
 
275
244
  **`./entities/MongoBook.ts`**
276
245
 
@@ -287,10 +256,10 @@ export class MongoBook {
287
256
  @Property()
288
257
  title: string;
289
258
 
290
- @ManyToOne()
259
+ @ManyToOne(() => Author)
291
260
  author: Author;
292
261
 
293
- @ManyToMany()
262
+ @ManyToMany(() => BookTag)
294
263
  tags = new Collection<BookTag>(this);
295
264
 
296
265
  constructor(title: string, author: Author) {
@@ -331,15 +300,11 @@ export class UuidBook {
331
300
  }
332
301
  ```
333
302
 
334
- More information can be found in
335
- [defining entities section](https://mikro-orm.io/docs/defining-entities/) in docs.
303
+ More information can be found in [defining entities section](https://mikro-orm.io/docs/defining-entities/) in docs.
336
304
 
337
- When you have your entities defined, you can start using ORM either via `EntityManager`
338
- or via `EntityRepository`s.
305
+ When you have your entities defined, you can start using ORM either via `EntityManager` or via `EntityRepository`s.
339
306
 
340
- To save entity state to database, you need to persist it. Persist takes care or deciding
341
- whether to use `insert` or `update` and computes appropriate change-set. Entity references
342
- that are not persisted yet (does not have identifier) will be cascade persisted automatically.
307
+ To save entity state to database, you need to persist it. Persist takes care or deciding whether to use `insert` or `update` and computes appropriate change-set. Entity references that are not persisted yet (does not have identifier) will be cascade persisted automatically.
343
308
 
344
309
  ```typescript
345
310
  // use constructors in your entities for required parameters
@@ -356,13 +321,13 @@ const book3 = new Book('My Life on The Wall, part 3', author);
356
321
  book3.publisher = publisher;
357
322
 
358
323
  // just persist books, author and publisher will be automatically cascade persisted
359
- await orm.em.persistAndFlush([book1, book2, book3]);
324
+ await em.persistAndFlush([book1, book2, book3]);
360
325
  ```
361
326
 
362
327
  To fetch entities from database you can use `find()` and `findOne()` of `EntityManager`:
363
328
 
364
329
  ```typescript
365
- const authors = orm.em.find(Author, {});
330
+ const authors = em.find(Author, {}, { populate: ['books'] });
366
331
 
367
332
  for (const author of authors) {
368
333
  console.log(author); // instance of Author entity
@@ -375,16 +340,11 @@ for (const author of authors) {
375
340
  }
376
341
  ```
377
342
 
378
- More convenient way of fetching entities from database is by using `EntityRepository`, that
379
- carries the entity name so you do not have to pass it to every `find` and `findOne` calls:
343
+ More convenient way of fetching entities from database is by using `EntityRepository`, that carries the entity name, so you do not have to pass it to every `find` and `findOne` calls:
380
344
 
381
345
  ```typescript
382
- const booksRepository = orm.em.getRepository(Book);
383
-
384
- // with sorting, limit and offset parameters, populating author references
385
- const books = await booksRepository.find({ author: '...' }, ['author'], { title: QueryOrder.DESC }, 2, 1);
346
+ const booksRepository = em.getRepository(Book);
386
347
 
387
- // or with options object
388
348
  const books = await booksRepository.find({ author: '...' }, {
389
349
  populate: ['author'],
390
350
  limit: 1,
@@ -392,17 +352,14 @@ const books = await booksRepository.find({ author: '...' }, {
392
352
  orderBy: { title: QueryOrder.DESC },
393
353
  });
394
354
 
395
- console.log(books); // Book[]
355
+ console.log(books); // Loaded<Book, 'author'>[]
396
356
  ```
397
357
 
398
- Take a look at docs about [working with `EntityManager`](https://mikro-orm.io/docs/entity-manager/)
399
- or [using `EntityRepository` instead](https://mikro-orm.io/docs/repositories/).
358
+ Take a look at docs about [working with `EntityManager`](https://mikro-orm.io/docs/entity-manager/) or [using `EntityRepository` instead](https://mikro-orm.io/docs/repositories/).
400
359
 
401
360
  ## 🤝 Contributing
402
361
 
403
- Contributions, issues and feature requests are welcome. Please read
404
- [CONTRIBUTING.md](CONTRIBUTING.md)
405
- for details on the process for submitting pull requests to us.
362
+ Contributions, issues and feature requests are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us.
406
363
 
407
364
  ## Authors
408
365
 
package/index.mjs CHANGED
@@ -1,33 +1,207 @@
1
1
  import mod from "./index.js";
2
2
 
3
3
  export default mod;
4
+ export const ALIAS_REPLACEMENT = mod.ALIAS_REPLACEMENT;
5
+ export const ALIAS_REPLACEMENT_RE = mod.ALIAS_REPLACEMENT_RE;
6
+ export const ARRAY_OPERATORS = mod.ARRAY_OPERATORS;
7
+ export const AbstractNamingStrategy = mod.AbstractNamingStrategy;
8
+ export const AbstractSchemaGenerator = mod.AbstractSchemaGenerator;
4
9
  export const AbstractSqlConnection = mod.AbstractSqlConnection;
5
10
  export const AbstractSqlDriver = mod.AbstractSqlDriver;
6
11
  export const AbstractSqlPlatform = mod.AbstractSqlPlatform;
12
+ export const AfterCreate = mod.AfterCreate;
13
+ export const AfterDelete = mod.AfterDelete;
14
+ export const AfterUpdate = mod.AfterUpdate;
15
+ export const ArrayCollection = mod.ArrayCollection;
7
16
  export const ArrayCriteriaNode = mod.ArrayCriteriaNode;
17
+ export const ArrayType = mod.ArrayType;
18
+ export const BaseEntity = mod.BaseEntity;
19
+ export const BeforeCreate = mod.BeforeCreate;
20
+ export const BeforeDelete = mod.BeforeDelete;
21
+ export const BeforeUpdate = mod.BeforeUpdate;
8
22
  export const BetterSqliteConnection = mod.BetterSqliteConnection;
9
23
  export const BetterSqliteDriver = mod.BetterSqliteDriver;
10
24
  export const BetterSqliteExceptionConverter = mod.BetterSqliteExceptionConverter;
11
25
  export const BetterSqlitePlatform = mod.BetterSqlitePlatform;
12
26
  export const BetterSqliteSchemaHelper = mod.BetterSqliteSchemaHelper;
27
+ export const BigIntType = mod.BigIntType;
28
+ export const BlobType = mod.BlobType;
29
+ export const BooleanType = mod.BooleanType;
30
+ export const Cascade = mod.Cascade;
31
+ export const ChangeSet = mod.ChangeSet;
32
+ export const ChangeSetComputer = mod.ChangeSetComputer;
33
+ export const ChangeSetPersister = mod.ChangeSetPersister;
34
+ export const ChangeSetType = mod.ChangeSetType;
35
+ export const Check = mod.Check;
36
+ export const CheckConstraintViolationException = mod.CheckConstraintViolationException;
37
+ export const Collection = mod.Collection;
38
+ export const CommitOrderCalculator = mod.CommitOrderCalculator;
39
+ export const Configuration = mod.Configuration;
40
+ export const ConfigurationLoader = mod.ConfigurationLoader;
41
+ export const Connection = mod.Connection;
42
+ export const ConnectionException = mod.ConnectionException;
43
+ export const ConstraintViolationException = mod.ConstraintViolationException;
44
+ export const CreateRequestContext = mod.CreateRequestContext;
13
45
  export const CriteriaNode = mod.CriteriaNode;
14
46
  export const CriteriaNodeFactory = mod.CriteriaNodeFactory;
47
+ export const Cursor = mod.Cursor;
48
+ export const DatabaseDriver = mod.DatabaseDriver;
49
+ export const DatabaseObjectExistsException = mod.DatabaseObjectExistsException;
50
+ export const DatabaseObjectNotFoundException = mod.DatabaseObjectNotFoundException;
15
51
  export const DatabaseSchema = mod.DatabaseSchema;
16
52
  export const DatabaseTable = mod.DatabaseTable;
53
+ export const DateTimeType = mod.DateTimeType;
54
+ export const DateType = mod.DateType;
55
+ export const DeadlockException = mod.DeadlockException;
56
+ export const DecimalType = mod.DecimalType;
57
+ export const DefaultLogger = mod.DefaultLogger;
58
+ export const DoubleType = mod.DoubleType;
59
+ export const DriverException = mod.DriverException;
60
+ export const EagerProps = mod.EagerProps;
61
+ export const Embeddable = mod.Embeddable;
62
+ export const Embedded = mod.Embedded;
63
+ export const EnsureRequestContext = mod.EnsureRequestContext;
64
+ export const Entity = mod.Entity;
65
+ export const EntityAssigner = mod.EntityAssigner;
66
+ export const EntityCaseNamingStrategy = mod.EntityCaseNamingStrategy;
67
+ export const EntityComparator = mod.EntityComparator;
68
+ export const EntityFactory = mod.EntityFactory;
69
+ export const EntityHelper = mod.EntityHelper;
70
+ export const EntityIdentifier = mod.EntityIdentifier;
71
+ export const EntityLoader = mod.EntityLoader;
17
72
  export const EntityManager = mod.EntityManager;
73
+ export const EntityManagerType = mod.EntityManagerType;
74
+ export const EntityMetadata = mod.EntityMetadata;
18
75
  export const EntityRepository = mod.EntityRepository;
76
+ export const EntityRepositoryType = mod.EntityRepositoryType;
77
+ export const EntitySchema = mod.EntitySchema;
78
+ export const EntitySerializer = mod.EntitySerializer;
79
+ export const EntityTransformer = mod.EntityTransformer;
80
+ export const EntityValidator = mod.EntityValidator;
81
+ export const Enum = mod.Enum;
82
+ export const EnumArrayType = mod.EnumArrayType;
83
+ export const EnumType = mod.EnumType;
84
+ export const EventManager = mod.EventManager;
85
+ export const EventType = mod.EventType;
86
+ export const EventTypeMap = mod.EventTypeMap;
87
+ export const ExceptionConverter = mod.ExceptionConverter;
88
+ export const FileCacheAdapter = mod.FileCacheAdapter;
89
+ export const Filter = mod.Filter;
90
+ export const FloatType = mod.FloatType;
91
+ export const FlushMode = mod.FlushMode;
92
+ export const ForeignKeyConstraintViolationException = mod.ForeignKeyConstraintViolationException;
93
+ export const Formula = mod.Formula;
94
+ export const GeneratedCacheAdapter = mod.GeneratedCacheAdapter;
95
+ export const GroupOperator = mod.GroupOperator;
96
+ export const HiddenProps = mod.HiddenProps;
97
+ export const Hydrator = mod.Hydrator;
98
+ export const IdentityMap = mod.IdentityMap;
99
+ export const Index = mod.Index;
100
+ export const IntegerType = mod.IntegerType;
101
+ export const InvalidFieldNameException = mod.InvalidFieldNameException;
102
+ export const IsolationLevel = mod.IsolationLevel;
103
+ export const JsonProperty = mod.JsonProperty;
104
+ export const JsonType = mod.JsonType;
19
105
  export const Knex = mod.Knex;
106
+ export const LoadStrategy = mod.LoadStrategy;
107
+ export const LockMode = mod.LockMode;
108
+ export const LockWaitTimeoutException = mod.LockWaitTimeoutException;
109
+ export const ManyToMany = mod.ManyToMany;
110
+ export const ManyToOne = mod.ManyToOne;
111
+ export const MediumIntType = mod.MediumIntType;
112
+ export const MemoryCacheAdapter = mod.MemoryCacheAdapter;
113
+ export const MetadataDiscovery = mod.MetadataDiscovery;
114
+ export const MetadataError = mod.MetadataError;
115
+ export const MetadataProvider = mod.MetadataProvider;
116
+ export const MetadataStorage = mod.MetadataStorage;
117
+ export const MetadataValidator = mod.MetadataValidator;
20
118
  export const MikroORM = mod.MikroORM;
119
+ export const MongoNamingStrategy = mod.MongoNamingStrategy;
21
120
  export const MonkeyPatchable = mod.MonkeyPatchable;
121
+ export const NodeState = mod.NodeState;
122
+ export const NonUniqueFieldNameException = mod.NonUniqueFieldNameException;
123
+ export const NotFoundError = mod.NotFoundError;
124
+ export const NotNullConstraintViolationException = mod.NotNullConstraintViolationException;
125
+ export const NullCacheAdapter = mod.NullCacheAdapter;
126
+ export const NullHighlighter = mod.NullHighlighter;
127
+ export const ObjectBindingPattern = mod.ObjectBindingPattern;
22
128
  export const ObjectCriteriaNode = mod.ObjectCriteriaNode;
129
+ export const ObjectHydrator = mod.ObjectHydrator;
130
+ export const OnInit = mod.OnInit;
131
+ export const OnLoad = mod.OnLoad;
132
+ export const OneToMany = mod.OneToMany;
133
+ export const OneToOne = mod.OneToOne;
134
+ export const OptimisticLockError = mod.OptimisticLockError;
135
+ export const OptionalProps = mod.OptionalProps;
136
+ export const PlainObject = mod.PlainObject;
137
+ export const Platform = mod.Platform;
138
+ export const PopulateHint = mod.PopulateHint;
139
+ export const PrimaryKey = mod.PrimaryKey;
140
+ export const PrimaryKeyProp = mod.PrimaryKeyProp;
141
+ export const Property = mod.Property;
23
142
  export const QueryBuilder = mod.QueryBuilder;
24
143
  export const QueryBuilderHelper = mod.QueryBuilderHelper;
144
+ export const QueryFlag = mod.QueryFlag;
145
+ export const QueryHelper = mod.QueryHelper;
146
+ export const QueryOperator = mod.QueryOperator;
147
+ export const QueryOrder = mod.QueryOrder;
148
+ export const QueryOrderNumeric = mod.QueryOrderNumeric;
25
149
  export const QueryType = mod.QueryType;
150
+ export const RawQueryFragment = mod.RawQueryFragment;
151
+ export const ReadOnlyException = mod.ReadOnlyException;
152
+ export const Reference = mod.Reference;
153
+ export const ReferenceKind = mod.ReferenceKind;
154
+ export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
155
+ export const RequestContext = mod.RequestContext;
156
+ export const SCALAR_TYPES = mod.SCALAR_TYPES;
26
157
  export const ScalarCriteriaNode = mod.ScalarCriteriaNode;
27
158
  export const SchemaComparator = mod.SchemaComparator;
28
159
  export const SchemaGenerator = mod.SchemaGenerator;
29
160
  export const SchemaHelper = mod.SchemaHelper;
161
+ export const SerializationContext = mod.SerializationContext;
162
+ export const SerializedPrimaryKey = mod.SerializedPrimaryKey;
163
+ export const ServerException = mod.ServerException;
164
+ export const SimpleLogger = mod.SimpleLogger;
165
+ export const SmallIntType = mod.SmallIntType;
30
166
  export const SqlEntityManager = mod.SqlEntityManager;
31
167
  export const SqlEntityRepository = mod.SqlEntityRepository;
168
+ export const SqlSchemaGenerator = mod.SqlSchemaGenerator;
169
+ export const StringType = mod.StringType;
170
+ export const Subscriber = mod.Subscriber;
171
+ export const SyntaxErrorException = mod.SyntaxErrorException;
172
+ export const TableExistsException = mod.TableExistsException;
173
+ export const TableNotFoundException = mod.TableNotFoundException;
174
+ export const TextType = mod.TextType;
175
+ export const TimeType = mod.TimeType;
176
+ export const TinyIntType = mod.TinyIntType;
177
+ export const TransactionContext = mod.TransactionContext;
178
+ export const TransactionEventBroadcaster = mod.TransactionEventBroadcaster;
179
+ export const Type = mod.Type;
180
+ export const UnderscoreNamingStrategy = mod.UnderscoreNamingStrategy;
181
+ export const Unique = mod.Unique;
182
+ export const UniqueConstraintViolationException = mod.UniqueConstraintViolationException;
183
+ export const UnitOfWork = mod.UnitOfWork;
184
+ export const UnknownType = mod.UnknownType;
185
+ export const Utils = mod.Utils;
186
+ export const UuidType = mod.UuidType;
187
+ export const ValidationError = mod.ValidationError;
188
+ export const WrappedEntity = mod.WrappedEntity;
189
+ export const assign = mod.assign;
190
+ export const colors = mod.colors;
191
+ export const compareArrays = mod.compareArrays;
192
+ export const compareBooleans = mod.compareBooleans;
193
+ export const compareBuffers = mod.compareBuffers;
194
+ export const compareObjects = mod.compareObjects;
32
195
  export const defineConfig = mod.defineConfig;
196
+ export const equals = mod.equals;
197
+ export const helper = mod.helper;
33
198
  export const knex = mod.knex;
199
+ export const parseJsonSafe = mod.parseJsonSafe;
200
+ export const raw = mod.raw;
201
+ export const ref = mod.ref;
202
+ export const rel = mod.rel;
203
+ export const serialize = mod.serialize;
204
+ export const sql = mod.sql;
205
+ export const t = mod.t;
206
+ export const types = mod.types;
207
+ export const wrap = mod.wrap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/better-sqlite",
3
- "version": "6.0.0-dev.6",
3
+ "version": "6.0.0-dev.60",
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,15 +58,15 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "^6.0.0-dev.6",
62
- "better-sqlite3": "8.0.1",
63
- "fs-extra": "11.1.0",
61
+ "@mikro-orm/knex": "~6.0.0-dev.60",
62
+ "better-sqlite3": "8.3.0",
63
+ "fs-extra": "11.1.1",
64
64
  "sqlstring-sqlite": "0.1.1"
65
65
  },
66
66
  "devDependencies": {
67
- "@mikro-orm/core": "^5.5.3"
67
+ "@mikro-orm/core": "^5.6.16"
68
68
  },
69
69
  "peerDependencies": {
70
- "@mikro-orm/core": "~6.0.0-dev.6"
70
+ "@mikro-orm/core": "~6.0.0-dev.60"
71
71
  }
72
72
  }