@mikro-orm/better-sqlite 6.0.0-dev.46 → 6.0.0-dev.47
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.
- package/BetterSqliteConnection.js +3 -2
- package/BetterSqliteMikroORM.d.ts +4 -0
- package/BetterSqliteMikroORM.js +7 -1
- package/README.md +63 -106
- package/package.json +5 -5
|
@@ -11,6 +11,7 @@ class BetterSqliteConnection extends knex_1.AbstractSqlConnection {
|
|
|
11
11
|
this.getPatchedDialect();
|
|
12
12
|
this.client = this.createKnexClient('better-sqlite3');
|
|
13
13
|
await this.client.raw('pragma foreign_keys = on');
|
|
14
|
+
this.connected = true;
|
|
14
15
|
}
|
|
15
16
|
getDefaultClientUrl() {
|
|
16
17
|
return '';
|
|
@@ -146,6 +147,6 @@ class BetterSqliteConnection extends knex_1.AbstractSqlConnection {
|
|
|
146
147
|
}
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
|
-
exports.BetterSqliteConnection = BetterSqliteConnection;
|
|
150
150
|
BetterSqliteConnection.RUN_QUERY_RE = /^insert into|^update|^delete|^truncate/;
|
|
151
|
-
BetterSqliteConnection.RUN_QUERY_RETURNING = /^insert into
|
|
151
|
+
BetterSqliteConnection.RUN_QUERY_RETURNING = /^insert into ([\s\S])* returning .*/;
|
|
152
|
+
exports.BetterSqliteConnection = BetterSqliteConnection;
|
|
@@ -10,6 +10,10 @@ export declare class BetterSqliteMikroORM extends MikroORM<BetterSqliteDriver> {
|
|
|
10
10
|
* @inheritDoc
|
|
11
11
|
*/
|
|
12
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>;
|
|
13
17
|
}
|
|
14
18
|
export type BetterSqliteOptions = Options<BetterSqliteDriver>;
|
|
15
19
|
export declare function defineBetterSqliteConfig(options: BetterSqliteOptions): Options<BetterSqliteDriver>;
|
package/BetterSqliteMikroORM.js
CHANGED
|
@@ -13,9 +13,15 @@ class BetterSqliteMikroORM extends core_1.MikroORM {
|
|
|
13
13
|
static async init(options) {
|
|
14
14
|
return super.init(options);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
static initSync(options) {
|
|
20
|
+
return super.initSync(options);
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
|
-
exports.BetterSqliteMikroORM = BetterSqliteMikroORM;
|
|
18
23
|
BetterSqliteMikroORM.DRIVER = BetterSqliteDriver_1.BetterSqliteDriver;
|
|
24
|
+
exports.BetterSqliteMikroORM = BetterSqliteMikroORM;
|
|
19
25
|
/* istanbul ignore next */
|
|
20
26
|
function defineBetterSqliteConfig(options) {
|
|
21
27
|
return (0, core_1.defineConfig)({ driver: BetterSqliteDriver_1.BetterSqliteDriver, ...options });
|
package/README.md
CHANGED
|
@@ -2,9 +2,7 @@
|
|
|
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
7
|
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Nextras Orm](https://nextras.org/orm/).
|
|
10
8
|
|
|
@@ -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,
|
|
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
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
###
|
|
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
|
|
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
|
-
|
|
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/
|
|
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
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/better-sqlite",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.47",
|
|
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.
|
|
62
|
-
"better-sqlite3": "8.
|
|
61
|
+
"@mikro-orm/knex": "~6.0.0-dev.47",
|
|
62
|
+
"better-sqlite3": "8.2.0",
|
|
63
63
|
"fs-extra": "11.1.0",
|
|
64
64
|
"sqlstring-sqlite": "0.1.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@mikro-orm/core": "^5.6.
|
|
67
|
+
"@mikro-orm/core": "^5.6.15"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
70
|
+
"@mikro-orm/core": "~6.0.0-dev.47"
|
|
71
71
|
}
|
|
72
72
|
}
|