@mikro-orm/better-sqlite 6.0.0-dev.8 → 6.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.
- package/BetterSqliteConnection.d.ts +1 -0
- package/BetterSqliteConnection.js +10 -6
- package/BetterSqliteMikroORM.d.ts +9 -1
- package/BetterSqliteMikroORM.js +13 -1
- package/BetterSqlitePlatform.d.ts +0 -1
- package/BetterSqlitePlatform.js +0 -7
- package/README.md +64 -107
- package/index.mjs +19 -6
- package/package.json +8 -8
|
@@ -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
|
-
|
|
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
|
|
111
|
-
addColumnQuery.sql += ` constraint ${keyName} references ${inTable} (${references})${onUpdate}${
|
|
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
|
|
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>;
|
package/BetterSqliteMikroORM.js
CHANGED
|
@@ -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 });
|
|
@@ -49,7 +49,6 @@ export declare class BetterSqlitePlatform extends AbstractSqlPlatform {
|
|
|
49
49
|
processDateProperty(value: unknown): string | number | Date;
|
|
50
50
|
quoteVersionValue(value: Date | number, prop: EntityProperty): Date | string | number;
|
|
51
51
|
quoteValue(value: any): string;
|
|
52
|
-
getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean): string;
|
|
53
52
|
getIndexName(tableName: string, columns: string[], type: 'index' | 'unique' | 'foreign' | 'primary' | 'sequence'): string;
|
|
54
53
|
getDefaultPrimaryName(tableName: string, columns: string[]): string;
|
|
55
54
|
supportsDownMigrations(): boolean;
|
package/BetterSqlitePlatform.js
CHANGED
|
@@ -83,13 +83,6 @@ class BetterSqlitePlatform extends knex_1.AbstractSqlPlatform {
|
|
|
83
83
|
}
|
|
84
84
|
return (0, sqlstring_sqlite_1.escape)(value, true, this.timezone);
|
|
85
85
|
}
|
|
86
|
-
getSearchJsonPropertyKey(path, type, aliased) {
|
|
87
|
-
const [a, ...b] = path;
|
|
88
|
-
if (aliased) {
|
|
89
|
-
return (0, core_1.expr)(alias => `json_extract(${this.quoteIdentifier(`${alias}.${a}`)}, '$.${b.join('.')}')`);
|
|
90
|
-
}
|
|
91
|
-
return `json_extract(${this.quoteIdentifier(a)}, '$.${b.join('.')}')`;
|
|
92
|
-
}
|
|
93
86
|
getIndexName(tableName, columns, type) {
|
|
94
87
|
if (type === 'primary') {
|
|
95
88
|
return this.getDefaultPrimaryName(tableName, columns);
|
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 [
|
|
7
|
+
> Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
|
|
10
8
|
|
|
11
9
|
[](https://www.npmjs.com/package/@mikro-orm/core)
|
|
12
10
|
[](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,
|
|
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/index.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
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;
|
|
4
6
|
export const ARRAY_OPERATORS = mod.ARRAY_OPERATORS;
|
|
5
7
|
export const AbstractNamingStrategy = mod.AbstractNamingStrategy;
|
|
6
8
|
export const AbstractSchemaGenerator = mod.AbstractSchemaGenerator;
|
|
@@ -10,6 +12,7 @@ export const AbstractSqlPlatform = mod.AbstractSqlPlatform;
|
|
|
10
12
|
export const AfterCreate = mod.AfterCreate;
|
|
11
13
|
export const AfterDelete = mod.AfterDelete;
|
|
12
14
|
export const AfterUpdate = mod.AfterUpdate;
|
|
15
|
+
export const AfterUpsert = mod.AfterUpsert;
|
|
13
16
|
export const ArrayCollection = mod.ArrayCollection;
|
|
14
17
|
export const ArrayCriteriaNode = mod.ArrayCriteriaNode;
|
|
15
18
|
export const ArrayType = mod.ArrayType;
|
|
@@ -17,6 +20,7 @@ export const BaseEntity = mod.BaseEntity;
|
|
|
17
20
|
export const BeforeCreate = mod.BeforeCreate;
|
|
18
21
|
export const BeforeDelete = mod.BeforeDelete;
|
|
19
22
|
export const BeforeUpdate = mod.BeforeUpdate;
|
|
23
|
+
export const BeforeUpsert = mod.BeforeUpsert;
|
|
20
24
|
export const BetterSqliteConnection = mod.BetterSqliteConnection;
|
|
21
25
|
export const BetterSqliteDriver = mod.BetterSqliteDriver;
|
|
22
26
|
export const BetterSqliteExceptionConverter = mod.BetterSqliteExceptionConverter;
|
|
@@ -39,8 +43,10 @@ export const ConfigurationLoader = mod.ConfigurationLoader;
|
|
|
39
43
|
export const Connection = mod.Connection;
|
|
40
44
|
export const ConnectionException = mod.ConnectionException;
|
|
41
45
|
export const ConstraintViolationException = mod.ConstraintViolationException;
|
|
46
|
+
export const CreateRequestContext = mod.CreateRequestContext;
|
|
42
47
|
export const CriteriaNode = mod.CriteriaNode;
|
|
43
48
|
export const CriteriaNodeFactory = mod.CriteriaNodeFactory;
|
|
49
|
+
export const Cursor = mod.Cursor;
|
|
44
50
|
export const DatabaseDriver = mod.DatabaseDriver;
|
|
45
51
|
export const DatabaseObjectExistsException = mod.DatabaseObjectExistsException;
|
|
46
52
|
export const DatabaseObjectNotFoundException = mod.DatabaseObjectNotFoundException;
|
|
@@ -53,8 +59,10 @@ export const DecimalType = mod.DecimalType;
|
|
|
53
59
|
export const DefaultLogger = mod.DefaultLogger;
|
|
54
60
|
export const DoubleType = mod.DoubleType;
|
|
55
61
|
export const DriverException = mod.DriverException;
|
|
62
|
+
export const EagerProps = mod.EagerProps;
|
|
56
63
|
export const Embeddable = mod.Embeddable;
|
|
57
64
|
export const Embedded = mod.Embedded;
|
|
65
|
+
export const EnsureRequestContext = mod.EnsureRequestContext;
|
|
58
66
|
export const Entity = mod.Entity;
|
|
59
67
|
export const EntityAssigner = mod.EntityAssigner;
|
|
60
68
|
export const EntityCaseNamingStrategy = mod.EntityCaseNamingStrategy;
|
|
@@ -77,6 +85,7 @@ export const EnumArrayType = mod.EnumArrayType;
|
|
|
77
85
|
export const EnumType = mod.EnumType;
|
|
78
86
|
export const EventManager = mod.EventManager;
|
|
79
87
|
export const EventType = mod.EventType;
|
|
88
|
+
export const EventTypeMap = mod.EventTypeMap;
|
|
80
89
|
export const ExceptionConverter = mod.ExceptionConverter;
|
|
81
90
|
export const FileCacheAdapter = mod.FileCacheAdapter;
|
|
82
91
|
export const Filter = mod.Filter;
|
|
@@ -84,14 +93,15 @@ export const FloatType = mod.FloatType;
|
|
|
84
93
|
export const FlushMode = mod.FlushMode;
|
|
85
94
|
export const ForeignKeyConstraintViolationException = mod.ForeignKeyConstraintViolationException;
|
|
86
95
|
export const Formula = mod.Formula;
|
|
96
|
+
export const GeneratedCacheAdapter = mod.GeneratedCacheAdapter;
|
|
87
97
|
export const GroupOperator = mod.GroupOperator;
|
|
98
|
+
export const HiddenProps = mod.HiddenProps;
|
|
88
99
|
export const Hydrator = mod.Hydrator;
|
|
89
100
|
export const IdentityMap = mod.IdentityMap;
|
|
90
101
|
export const Index = mod.Index;
|
|
91
102
|
export const IntegerType = mod.IntegerType;
|
|
92
103
|
export const InvalidFieldNameException = mod.InvalidFieldNameException;
|
|
93
104
|
export const IsolationLevel = mod.IsolationLevel;
|
|
94
|
-
export const JavaScriptMetadataProvider = mod.JavaScriptMetadataProvider;
|
|
95
105
|
export const JsonProperty = mod.JsonProperty;
|
|
96
106
|
export const JsonType = mod.JsonType;
|
|
97
107
|
export const Knex = mod.Knex;
|
|
@@ -130,7 +140,6 @@ export const Platform = mod.Platform;
|
|
|
130
140
|
export const PopulateHint = mod.PopulateHint;
|
|
131
141
|
export const PrimaryKey = mod.PrimaryKey;
|
|
132
142
|
export const PrimaryKeyProp = mod.PrimaryKeyProp;
|
|
133
|
-
export const PrimaryKeyType = mod.PrimaryKeyType;
|
|
134
143
|
export const Property = mod.Property;
|
|
135
144
|
export const QueryBuilder = mod.QueryBuilder;
|
|
136
145
|
export const QueryBuilderHelper = mod.QueryBuilderHelper;
|
|
@@ -140,13 +149,16 @@ export const QueryOperator = mod.QueryOperator;
|
|
|
140
149
|
export const QueryOrder = mod.QueryOrder;
|
|
141
150
|
export const QueryOrderNumeric = mod.QueryOrderNumeric;
|
|
142
151
|
export const QueryType = mod.QueryType;
|
|
152
|
+
export const RawQueryFragment = mod.RawQueryFragment;
|
|
143
153
|
export const ReadOnlyException = mod.ReadOnlyException;
|
|
154
|
+
export const Ref = mod.Ref;
|
|
144
155
|
export const Reference = mod.Reference;
|
|
145
|
-
export const
|
|
156
|
+
export const ReferenceKind = mod.ReferenceKind;
|
|
146
157
|
export const ReflectMetadataProvider = mod.ReflectMetadataProvider;
|
|
147
158
|
export const RequestContext = mod.RequestContext;
|
|
148
159
|
export const SCALAR_TYPES = mod.SCALAR_TYPES;
|
|
149
160
|
export const ScalarCriteriaNode = mod.ScalarCriteriaNode;
|
|
161
|
+
export const ScalarReference = mod.ScalarReference;
|
|
150
162
|
export const SchemaComparator = mod.SchemaComparator;
|
|
151
163
|
export const SchemaGenerator = mod.SchemaGenerator;
|
|
152
164
|
export const SchemaHelper = mod.SchemaHelper;
|
|
@@ -159,7 +171,6 @@ export const SqlEntityManager = mod.SqlEntityManager;
|
|
|
159
171
|
export const SqlEntityRepository = mod.SqlEntityRepository;
|
|
160
172
|
export const SqlSchemaGenerator = mod.SqlSchemaGenerator;
|
|
161
173
|
export const StringType = mod.StringType;
|
|
162
|
-
export const Subscriber = mod.Subscriber;
|
|
163
174
|
export const SyntaxErrorException = mod.SyntaxErrorException;
|
|
164
175
|
export const TableExistsException = mod.TableExistsException;
|
|
165
176
|
export const TableNotFoundException = mod.TableNotFoundException;
|
|
@@ -174,7 +185,6 @@ export const Unique = mod.Unique;
|
|
|
174
185
|
export const UniqueConstraintViolationException = mod.UniqueConstraintViolationException;
|
|
175
186
|
export const UnitOfWork = mod.UnitOfWork;
|
|
176
187
|
export const UnknownType = mod.UnknownType;
|
|
177
|
-
export const UseRequestContext = mod.UseRequestContext;
|
|
178
188
|
export const Utils = mod.Utils;
|
|
179
189
|
export const UuidType = mod.UuidType;
|
|
180
190
|
export const ValidationError = mod.ValidationError;
|
|
@@ -187,11 +197,14 @@ export const compareBuffers = mod.compareBuffers;
|
|
|
187
197
|
export const compareObjects = mod.compareObjects;
|
|
188
198
|
export const defineConfig = mod.defineConfig;
|
|
189
199
|
export const equals = mod.equals;
|
|
190
|
-
export const expr = mod.expr;
|
|
191
200
|
export const helper = mod.helper;
|
|
192
201
|
export const knex = mod.knex;
|
|
202
|
+
export const parseJsonSafe = mod.parseJsonSafe;
|
|
203
|
+
export const raw = mod.raw;
|
|
193
204
|
export const ref = mod.ref;
|
|
205
|
+
export const rel = mod.rel;
|
|
194
206
|
export const serialize = mod.serialize;
|
|
207
|
+
export const sql = mod.sql;
|
|
195
208
|
export const t = mod.t;
|
|
196
209
|
export const types = mod.types;
|
|
197
210
|
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.
|
|
3
|
+
"version": "6.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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -50,23 +50,23 @@
|
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "yarn clean && yarn compile && yarn copy && yarn run -T gen-esm-wrapper index.js index.mjs",
|
|
53
|
-
"clean": "rimraf ./dist",
|
|
54
|
-
"compile": "tsc -p tsconfig.build.json",
|
|
53
|
+
"clean": "yarn run -T rimraf ./dist",
|
|
54
|
+
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
55
55
|
"copy": "node ../../scripts/copy.mjs"
|
|
56
56
|
},
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@mikro-orm/knex": "
|
|
62
|
-
"better-sqlite3": "8.0
|
|
63
|
-
"fs-extra": "11.1.
|
|
61
|
+
"@mikro-orm/knex": "~6.0.0-dev.80",
|
|
62
|
+
"better-sqlite3": "8.4.0",
|
|
63
|
+
"fs-extra": "11.1.1",
|
|
64
64
|
"sqlstring-sqlite": "0.1.1"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@mikro-orm/core": "^5.
|
|
67
|
+
"@mikro-orm/core": "^5.7.10"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"@mikro-orm/core": "~6.0.0-dev.
|
|
70
|
+
"@mikro-orm/core": "~6.0.0-dev.80"
|
|
71
71
|
}
|
|
72
72
|
}
|