@mikro-orm/oracledb 7.0.0-dev.316

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/README.md ADDED
@@ -0,0 +1,391 @@
1
+ <h1 align="center">
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
+ </h1>
4
+
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, SQLite (including libSQL), MSSQL and Oracle databases.
6
+
7
+ > Heavily inspired by [Doctrine](https://www.doctrine-project.org/) and [Hibernate](https://hibernate.org/).
8
+
9
+ [![NPM version](https://img.shields.io/npm/v/@mikro-orm/core.svg)](https://npmx.dev/package/@mikro-orm/core)
10
+ [![NPM dev version](https://img.shields.io/npm/v/@mikro-orm/core/next.svg)](https://npmx.dev/package/@mikro-orm/core)
11
+ [![Chat on discord](https://img.shields.io/discord/1214904142443839538?label=discord&color=blue)](https://discord.gg/w8bjxFHS7X)
12
+ [![Downloads](https://img.shields.io/npm/dm/@mikro-orm/core.svg)](https://npmx.dev/package/@mikro-orm/core)
13
+ [![Coverage Status](https://img.shields.io/coveralls/mikro-orm/mikro-orm.svg)](https://coveralls.io/r/mikro-orm/mikro-orm?branch=master)
14
+ [![Build Status](https://github.com/mikro-orm/mikro-orm/workflows/tests/badge.svg?branch=master)](https://github.com/mikro-orm/mikro-orm/actions?workflow=tests)
15
+
16
+ ## 🤔 Unit of What?
17
+
18
+ You might be asking: _What the hell is Unit of Work and why should I care about it?_
19
+
20
+ > Unit of Work maintains a list of objects (_entities_) affected by a business transaction
21
+ > and coordinates the writing out of changes. [(Martin Fowler)](https://www.martinfowler.com/eaaCatalog/unitOfWork.html)
22
+
23
+ > Identity Map ensures that each object (_entity_) gets loaded only once by keeping every
24
+ > loaded object in a map. Looks up objects using the map when referring to them.
25
+ > [(Martin Fowler)](https://www.martinfowler.com/eaaCatalog/identityMap.html)
26
+
27
+ So what benefits does it bring to us?
28
+
29
+ ### Implicit Transactions
30
+
31
+ First and most important implication of having Unit of Work is that it allows handling transactions automatically.
32
+
33
+ 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.
34
+
35
+ > You can also control the transaction boundaries manually via `em.transactional(cb)`.
36
+
37
+ ```typescript
38
+ const user = await em.findOneOrFail(User, 1);
39
+ user.email = 'foo@bar.com';
40
+ const car = new Car();
41
+ user.cars.add(car);
42
+
43
+ // thanks to bi-directional cascading we only need to persist user entity
44
+ // flushing will create a transaction, insert new car and update user with new email
45
+ // as user entity is managed, calling flush() is enough
46
+ await em.flush();
47
+ ```
48
+
49
+ ### ChangeSet based persistence
50
+
51
+ 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:
52
+
53
+ ```typescript
54
+ @Entity()
55
+ export class User {
56
+
57
+ @PrimaryKey()
58
+ id!: number;
59
+
60
+ @Property()
61
+ name!: string;
62
+
63
+ @OneToOne(() => Address)
64
+ address?: Address;
65
+
66
+ @ManyToMany(() => Car)
67
+ cars = new Collection<Car>(this);
68
+
69
+ constructor(name: string) {
70
+ this.name = name;
71
+ }
72
+
73
+ }
74
+ ```
75
+
76
+ Now to create new instance of the `User` entity, we are forced to provide the `name`:
77
+
78
+ ```typescript
79
+ const user = new User('John Doe'); // name is required to create new user instance
80
+ user.address = new Address('10 Downing Street'); // address is optional
81
+ ```
82
+
83
+ Once your entities are loaded, make a number of synchronous actions on your entities,
84
+ then call `em.flush()`. This will trigger computing of change sets. Only entities
85
+ (and properties) that were changed will generate database queries, if there are no changes,
86
+ no transaction will be started.
87
+
88
+ ```typescript
89
+ const user = await em.findOneOrFail(User, 1, {
90
+ populate: ['cars', 'address.city'],
91
+ });
92
+ user.title = 'Mr.';
93
+ user.address.street = '10 Downing Street'; // address is 1:1 relation of Address entity
94
+ user.cars.getItems().forEach(car => car.forSale = true); // cars is 1:m collection of Car entities
95
+ const car = new Car('VW');
96
+ user.cars.add(car);
97
+
98
+ // now we can flush all changes done to managed entities
99
+ await em.flush();
100
+ ```
101
+
102
+ `em.flush()` will then execute these queries from the example above:
103
+
104
+ ```sql
105
+ begin;
106
+ update "user" set "title" = 'Mr.' where "id" = 1;
107
+ update "user_address" set "street" = '10 Downing Street' where "id" = 123;
108
+ update "car"
109
+ set "for_sale" = case
110
+ when ("id" = 1) then true
111
+ when ("id" = 2) then true
112
+ when ("id" = 3) then true
113
+ else "for_sale" end
114
+ where "id" in (1, 2, 3)
115
+ insert into "car" ("brand", "owner") values ('VW', 1);
116
+ commit;
117
+ ```
118
+
119
+ ### Identity Map
120
+
121
+ 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`).
122
+
123
+ ## 📖 Documentation
124
+
125
+ 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.
126
+
127
+ There is also auto-generated [CHANGELOG.md](CHANGELOG.md) file based on commit messages (via `semantic-release`).
128
+
129
+ ## ✨ Core Features
130
+
131
+ - [Clean and Simple Entity Definition](https://mikro-orm.io/docs/defining-entities)
132
+ - [Identity Map](https://mikro-orm.io/docs/identity-map)
133
+ - [Entity References](https://mikro-orm.io/docs/entity-references)
134
+ - [Using Entity Constructors](https://mikro-orm.io/docs/entity-constructors)
135
+ - [Modelling Relationships](https://mikro-orm.io/docs/relationships)
136
+ - [Collections](https://mikro-orm.io/docs/collections)
137
+ - [Unit of Work](https://mikro-orm.io/docs/unit-of-work)
138
+ - [Transactions](https://mikro-orm.io/docs/transactions)
139
+ - [Cascading persist and remove](https://mikro-orm.io/docs/cascading)
140
+ - [Composite and Foreign Keys as Primary Key](https://mikro-orm.io/docs/composite-keys)
141
+ - [Filters](https://mikro-orm.io/docs/filters)
142
+ - [Using `QueryBuilder`](https://mikro-orm.io/docs/query-builder)
143
+ - [Populating relations](https://mikro-orm.io/docs/populating-relations)
144
+ - [Property Validation](https://mikro-orm.io/docs/property-validation)
145
+ - [Lifecycle Hooks](https://mikro-orm.io/docs/events#hooks)
146
+ - [Vanilla JS Support](https://mikro-orm.io/docs/usage-with-js)
147
+ - [Schema Generator](https://mikro-orm.io/docs/schema-generator)
148
+ - [Entity Generator](https://mikro-orm.io/docs/entity-generator)
149
+
150
+ ## 📦 Example Integrations
151
+
152
+ You can find example integrations for some popular frameworks in the [`mikro-orm-examples` repository](https://github.com/mikro-orm/mikro-orm-examples):
153
+
154
+ ### TypeScript Examples
155
+
156
+ - [Express + MongoDB](https://github.com/mikro-orm/express-ts-example-app)
157
+ - [Nest + MySQL](https://github.com/mikro-orm/nestjs-example-app)
158
+ - [RealWorld example app (Nest + MySQL)](https://github.com/mikro-orm/nestjs-realworld-example-app)
159
+ - [Koa + SQLite](https://github.com/mikro-orm/koa-ts-example-app)
160
+ - [GraphQL + PostgreSQL](https://github.com/driescroons/mikro-orm-graphql-example)
161
+ - [Inversify + PostgreSQL](https://github.com/PodaruDragos/inversify-example-app)
162
+ - [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
163
+ - [Accounts.js REST and GraphQL authentication + SQLite](https://github.com/darkbasic/mikro-orm-accounts-example)
164
+ - [Nest + Shopify + PostgreSQL + GraphQL](https://github.com/Cloudshelf/Shopify_CSConnector)
165
+ - [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
166
+ - [Electron.js + PostgreSQL](https://github.com/adnanlah/electron-mikro-orm-example-app)
167
+
168
+ ### JavaScript Examples
169
+
170
+ - [Express + SQLite](https://github.com/mikro-orm/express-js-example-app)
171
+
172
+ ## 🚀 Quick Start
173
+
174
+ First install the module via `yarn` or `npm` and do not forget to install the database driver as well:
175
+
176
+ > 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.
177
+
178
+ ```sh
179
+ yarn add @mikro-orm/core @mikro-orm/mongodb # for mongo
180
+ yarn add @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
181
+ yarn add @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
182
+ yarn add @mikro-orm/core @mikro-orm/postgresql # for postgresql
183
+ yarn add @mikro-orm/core @mikro-orm/mssql # for mssql
184
+ yarn add @mikro-orm/core @mikro-orm/oracledb # for oracle
185
+ yarn add @mikro-orm/core @mikro-orm/sqlite # for sqlite
186
+ yarn add @mikro-orm/core @mikro-orm/libsql # for libsql
187
+ ```
188
+
189
+ or
190
+
191
+ ```sh
192
+ npm i -s @mikro-orm/core @mikro-orm/mongodb # for mongo
193
+ npm i -s @mikro-orm/core @mikro-orm/mysql # for mysql/mariadb
194
+ npm i -s @mikro-orm/core @mikro-orm/mariadb # for mysql/mariadb
195
+ npm i -s @mikro-orm/core @mikro-orm/postgresql # for postgresql
196
+ npm i -s @mikro-orm/core @mikro-orm/mssql # for mssql
197
+ npm i -s @mikro-orm/core @mikro-orm/sqlite # for sqlite
198
+ npm i -s @mikro-orm/core @mikro-orm/libsql # for libsql
199
+ ```
200
+
201
+ 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:
202
+
203
+ ```json
204
+ "experimentalDecorators": true,
205
+ "emitDecoratorMetadata": true,
206
+ "esModuleInterop": true,
207
+ ```
208
+
209
+ Alternatively, you can use [`EntitySchema`](https://mikro-orm.io/docs/entity-schema).
210
+
211
+ Then call `MikroORM.init` as part of bootstrapping your app:
212
+
213
+ > 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:
214
+ >
215
+ > ```ts
216
+ > import { EntityManager } from '@mikro-orm/postgresql';
217
+ > const em = orm.em as EntityManager;
218
+ > const qb = em.createQueryBuilder(...);
219
+ > ```
220
+
221
+ ```typescript
222
+ import type { PostgreSqlDriver } from '@mikro-orm/postgresql'; // or any other SQL driver package
223
+
224
+ const orm = await MikroORM.init<PostgreSqlDriver>({
225
+ entities: ['./dist/entities'], // path to your JS entities (dist), relative to `baseDir`
226
+ dbName: 'my-db-name',
227
+ type: 'postgresql',
228
+ });
229
+ console.log(orm.em); // access EntityManager via `em` property
230
+ ```
231
+
232
+ There are more ways to configure your entities, take a look at [installation page](https://mikro-orm.io/docs/installation/).
233
+
234
+ > Read more about all the possible configuration options in [Advanced Configuration](https://mikro-orm.io/docs/configuration) section.
235
+
236
+ 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:
237
+
238
+ ```typescript
239
+ const app = express();
240
+
241
+ app.use((req, res, next) => {
242
+ RequestContext.create(orm.em, next);
243
+ });
244
+ ```
245
+
246
+ > 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.
247
+
248
+ More info about `RequestContext` is described [here](https://mikro-orm.io/docs/identity-map/#request-context).
249
+
250
+ Now you can start defining your entities (in one of the `entities` folders). This is how simple entity can look like in mongo driver:
251
+
252
+ **`./entities/MongoBook.ts`**
253
+
254
+ ```typescript
255
+ @Entity()
256
+ export class MongoBook {
257
+
258
+ @PrimaryKey()
259
+ _id: ObjectID;
260
+
261
+ @SerializedPrimaryKey()
262
+ id: string;
263
+
264
+ @Property()
265
+ title: string;
266
+
267
+ @ManyToOne(() => Author)
268
+ author: Author;
269
+
270
+ @ManyToMany(() => BookTag)
271
+ tags = new Collection<BookTag>(this);
272
+
273
+ constructor(title: string, author: Author) {
274
+ this.title = title;
275
+ this.author = author;
276
+ }
277
+
278
+ }
279
+ ```
280
+
281
+ For SQL drivers, you can use `id: number` PK:
282
+
283
+ **`./entities/SqlBook.ts`**
284
+
285
+ ```typescript
286
+ @Entity()
287
+ export class SqlBook {
288
+
289
+ @PrimaryKey()
290
+ id: number;
291
+
292
+ }
293
+ ```
294
+
295
+ Or if you want to use UUID primary keys:
296
+
297
+ **`./entities/UuidBook.ts`**
298
+
299
+ ```typescript
300
+ import { randomUUID } from 'node:crypto';
301
+
302
+ @Entity()
303
+ export class UuidBook {
304
+
305
+ @PrimaryKey()
306
+ uuid = randomUUID();
307
+
308
+ }
309
+ ```
310
+
311
+ More information can be found in [defining entities section](https://mikro-orm.io/docs/defining-entities/) in docs.
312
+
313
+ When you have your entities defined, you can start using ORM either via `EntityManager` or via `EntityRepository`s.
314
+
315
+ 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.
316
+
317
+ ```typescript
318
+ // use constructors in your entities for required parameters
319
+ const author = new Author('Jon Snow', 'snow@wall.st');
320
+ author.born = new Date();
321
+
322
+ const publisher = new Publisher('7K publisher');
323
+
324
+ const book1 = new Book('My Life on The Wall, part 1', author);
325
+ book1.publisher = publisher;
326
+ const book2 = new Book('My Life on The Wall, part 2', author);
327
+ book2.publisher = publisher;
328
+ const book3 = new Book('My Life on The Wall, part 3', author);
329
+ book3.publisher = publisher;
330
+
331
+ // just persist books, author and publisher will be automatically cascade persisted
332
+ await em.persistAndFlush([book1, book2, book3]);
333
+ ```
334
+
335
+ To fetch entities from database you can use `find()` and `findOne()` of `EntityManager`:
336
+
337
+ ```typescript
338
+ const authors = em.find(Author, {}, { populate: ['books'] });
339
+
340
+ for (const author of authors) {
341
+ console.log(author); // instance of Author entity
342
+ console.log(author.name); // Jon Snow
343
+
344
+ for (const book of author.books) { // iterating books collection
345
+ console.log(book); // instance of Book entity
346
+ console.log(book.title); // My Life on The Wall, part 1/2/3
347
+ }
348
+ }
349
+ ```
350
+
351
+ 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:
352
+
353
+ ```typescript
354
+ const booksRepository = em.getRepository(Book);
355
+
356
+ const books = await booksRepository.find({ author: '...' }, {
357
+ populate: ['author'],
358
+ limit: 1,
359
+ offset: 2,
360
+ orderBy: { title: QueryOrder.DESC },
361
+ });
362
+
363
+ console.log(books); // Loaded<Book, 'author'>[]
364
+ ```
365
+
366
+ 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/).
367
+
368
+ ## 🤝 Contributing
369
+
370
+ Contributions, issues and feature requests are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for submitting pull requests to us.
371
+
372
+ ## Authors
373
+
374
+ 👤 **Martin Adámek**
375
+
376
+ - Twitter: [@B4nan](https://twitter.com/B4nan)
377
+ - Github: [@b4nan](https://github.com/b4nan)
378
+
379
+ See also the list of contributors who [participated](https://github.com/mikro-orm/mikro-orm/contributors) in this project.
380
+
381
+ ## Show Your Support
382
+
383
+ Please ⭐️ this repository if this project helped you!
384
+
385
+ > If you'd like to support my open-source work, consider sponsoring me directly at [github.com/sponsors/b4nan](https://github.com/sponsors/b4nan).
386
+
387
+ ## 📝 License
388
+
389
+ Copyright © 2018 [Martin Adámek](https://github.com/b4nan).
390
+
391
+ This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details.
package/index.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export * from '@mikro-orm/sql';
2
+ export * from './OracleConnection.js';
3
+ export * from './OracleDriver.js';
4
+ export * from './OraclePlatform.js';
5
+ export * from './OracleQueryBuilder.js';
6
+ export * from './OracleSchemaHelper.js';
7
+ export * from './OracleSchemaGenerator.js';
8
+ export * from './OracleExceptionConverter.js';
9
+ export type { OracleOptions as Options } from './OracleMikroORM.js';
10
+ export { OracleMikroORM as MikroORM, defineOracleConfig as defineConfig } from './OracleMikroORM.js';
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from '@mikro-orm/sql';
2
+ export * from './OracleConnection.js';
3
+ export * from './OracleDriver.js';
4
+ export * from './OraclePlatform.js';
5
+ export * from './OracleQueryBuilder.js';
6
+ export * from './OracleSchemaHelper.js';
7
+ export * from './OracleSchemaGenerator.js';
8
+ export * from './OracleExceptionConverter.js';
9
+ export { OracleMikroORM as MikroORM, defineOracleConfig as defineConfig } from './OracleMikroORM.js';
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@mikro-orm/oracledb",
3
+ "version": "7.0.0-dev.316",
4
+ "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL, SQLite, MSSQL and Oracle databases.",
5
+ "keywords": [
6
+ "data-mapper",
7
+ "ddd",
8
+ "entity",
9
+ "identity-map",
10
+ "javascript",
11
+ "js",
12
+ "mikro-orm",
13
+ "oracle",
14
+ "oracledb",
15
+ "orm",
16
+ "ts",
17
+ "typescript",
18
+ "unit-of-work"
19
+ ],
20
+ "homepage": "https://mikro-orm.io",
21
+ "bugs": {
22
+ "url": "https://github.com/mikro-orm/mikro-orm/issues"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Martin Adámek",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
29
+ },
30
+ "type": "module",
31
+ "exports": {
32
+ "./package.json": "./package.json",
33
+ ".": "./index.js"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "yarn clean && yarn compile && yarn copy",
40
+ "clean": "yarn run -T rimraf ./dist",
41
+ "compile": "yarn run -T tsc -p tsconfig.build.json",
42
+ "copy": "node ../../scripts/copy.mjs"
43
+ },
44
+ "dependencies": {
45
+ "@mikro-orm/sql": "7.0.0-dev.316",
46
+ "kysely": "0.28.11",
47
+ "oracledb": "6.10.0"
48
+ },
49
+ "devDependencies": {
50
+ "@mikro-orm/core": "^6.6.9"
51
+ },
52
+ "peerDependencies": {
53
+ "@mikro-orm/core": "7.0.0-dev.316"
54
+ },
55
+ "engines": {
56
+ "node": ">= 22.17.0"
57
+ }
58
+ }