typeorm 0.3.26-dev.01dddfe → 0.3.26-dev.17cf837

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +15 -1113
  2. package/browser/cache/RedisQueryResultCache.d.ts +13 -0
  3. package/browser/cache/RedisQueryResultCache.js +105 -38
  4. package/browser/cache/RedisQueryResultCache.js.map +1 -1
  5. package/browser/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1 -1
  6. package/browser/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
  7. package/browser/driver/cockroachdb/CockroachDriver.js +2 -2
  8. package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
  9. package/browser/driver/cockroachdb/CockroachQueryRunner.js +4 -4
  10. package/browser/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  11. package/browser/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  12. package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  13. package/browser/driver/mysql/MysqlDriver.js +3 -1
  14. package/browser/driver/mysql/MysqlDriver.js.map +1 -1
  15. package/browser/driver/mysql/MysqlQueryRunner.js +3 -3
  16. package/browser/driver/mysql/MysqlQueryRunner.js.map +1 -1
  17. package/browser/driver/oracle/OracleQueryRunner.js +1 -1
  18. package/browser/driver/oracle/OracleQueryRunner.js.map +1 -1
  19. package/browser/driver/postgres/PostgresDriver.js +2 -2
  20. package/browser/driver/postgres/PostgresDriver.js.map +1 -1
  21. package/browser/driver/postgres/PostgresQueryRunner.js +4 -4
  22. package/browser/driver/postgres/PostgresQueryRunner.js.map +1 -1
  23. package/browser/driver/sap/SapConnectionOptions.d.ts +33 -8
  24. package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
  25. package/browser/driver/sap/SapDriver.d.ts +20 -21
  26. package/browser/driver/sap/SapDriver.js +86 -77
  27. package/browser/driver/sap/SapDriver.js.map +1 -1
  28. package/browser/driver/sap/SapQueryRunner.js +37 -26
  29. package/browser/driver/sap/SapQueryRunner.js.map +1 -1
  30. package/browser/driver/spanner/SpannerQueryRunner.js +3 -3
  31. package/browser/driver/spanner/SpannerQueryRunner.js.map +1 -1
  32. package/browser/driver/sqlserver/SqlServerQueryRunner.js +1 -1
  33. package/browser/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  34. package/browser/error/DriverPackageNotInstalledError.js +1 -2
  35. package/browser/error/DriverPackageNotInstalledError.js.map +1 -1
  36. package/browser/metadata-builder/EntityMetadataBuilder.js +8 -1
  37. package/browser/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  38. package/browser/platform/PlatformTools.js +0 -2
  39. package/browser/platform/PlatformTools.js.map +1 -1
  40. package/browser/query-builder/QueryExpressionMap.js +1 -0
  41. package/browser/query-builder/QueryExpressionMap.js.map +1 -1
  42. package/browser/query-builder/SelectQueryBuilder.d.ts +1 -0
  43. package/browser/query-builder/SelectQueryBuilder.js +43 -5
  44. package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
  45. package/cache/RedisQueryResultCache.d.ts +13 -0
  46. package/cache/RedisQueryResultCache.js +105 -38
  47. package/cache/RedisQueryResultCache.js.map +1 -1
  48. package/driver/aurora-mysql/AuroraMysqlQueryRunner.js +1 -1
  49. package/driver/aurora-mysql/AuroraMysqlQueryRunner.js.map +1 -1
  50. package/driver/cockroachdb/CockroachDriver.js +2 -2
  51. package/driver/cockroachdb/CockroachDriver.js.map +1 -1
  52. package/driver/cockroachdb/CockroachQueryRunner.js +4 -4
  53. package/driver/cockroachdb/CockroachQueryRunner.js.map +1 -1
  54. package/driver/mongodb/MongoConnectionOptions.d.ts +9 -9
  55. package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
  56. package/driver/mysql/MysqlDriver.js +3 -1
  57. package/driver/mysql/MysqlDriver.js.map +1 -1
  58. package/driver/mysql/MysqlQueryRunner.js +3 -3
  59. package/driver/mysql/MysqlQueryRunner.js.map +1 -1
  60. package/driver/oracle/OracleQueryRunner.js +1 -1
  61. package/driver/oracle/OracleQueryRunner.js.map +1 -1
  62. package/driver/postgres/PostgresDriver.js +2 -2
  63. package/driver/postgres/PostgresDriver.js.map +1 -1
  64. package/driver/postgres/PostgresQueryRunner.js +4 -4
  65. package/driver/postgres/PostgresQueryRunner.js.map +1 -1
  66. package/driver/sap/SapConnectionOptions.d.ts +33 -8
  67. package/driver/sap/SapConnectionOptions.js.map +1 -1
  68. package/driver/sap/SapDriver.d.ts +20 -21
  69. package/driver/sap/SapDriver.js +86 -77
  70. package/driver/sap/SapDriver.js.map +1 -1
  71. package/driver/sap/SapQueryRunner.js +42 -31
  72. package/driver/sap/SapQueryRunner.js.map +1 -1
  73. package/driver/spanner/SpannerQueryRunner.js +3 -3
  74. package/driver/spanner/SpannerQueryRunner.js.map +1 -1
  75. package/driver/sqlserver/SqlServerQueryRunner.js +1 -1
  76. package/driver/sqlserver/SqlServerQueryRunner.js.map +1 -1
  77. package/error/DriverPackageNotInstalledError.js +1 -2
  78. package/error/DriverPackageNotInstalledError.js.map +1 -1
  79. package/metadata-builder/EntityMetadataBuilder.js +8 -1
  80. package/metadata-builder/EntityMetadataBuilder.js.map +1 -1
  81. package/package.json +1 -1
  82. package/platform/PlatformTools.js +0 -2
  83. package/platform/PlatformTools.js.map +1 -1
  84. package/query-builder/QueryExpressionMap.js +1 -0
  85. package/query-builder/QueryExpressionMap.js.map +1 -1
  86. package/query-builder/SelectQueryBuilder.d.ts +1 -0
  87. package/query-builder/SelectQueryBuilder.js +43 -5
  88. package/query-builder/SelectQueryBuilder.js.map +1 -1
package/README.md CHANGED
@@ -8,31 +8,26 @@
8
8
  </a>
9
9
  <br>
10
10
  <br>
11
- <a href="https://github.com/typeorm/typeorm/actions/workflows/test.yml">
12
- <img src="https://github.com/typeorm/typeorm/actions/workflows/test.yml/badge.svg?branch=master">
13
- </a>
14
- <a href="https://badge.fury.io/js/typeorm">
15
- <img src="https://badge.fury.io/js/typeorm.svg">
16
- </a>
17
- <a href='https://coveralls.io/github/typeorm/typeorm?branch=master'>
18
- <img src='https://coveralls.io/repos/github/typeorm/typeorm/badge.svg?branch=master' alt='Coverage Status' />
19
- </a>
11
+ <a href="https://www.npmjs.com/package/typeorm"><img src="https://img.shields.io/npm/v/typeorm" alt="NPM Version" /></a>
12
+ <a href="https://www.npmjs.com/package/typeorm"><img src="https://img.shields.io/npm/dm/typeorm" alt="NPM Downloads" /></a>
13
+ <a href="https://github.com/typeorm/typeorm/actions/workflows/commit-validation.yml?query=branch%3Amaster"><img src="https://github.com/typeorm/typeorm/actions/workflows/commit-validation.yml/badge.svg?branch=master" alt="Commit Validation"/></a>
14
+ <a href="https://coveralls.io/github/typeorm/typeorm?branch=master"><img src="https://coveralls.io/repos/github/typeorm/typeorm/badge.svg?branch=master" alt="Coverage Status" /></a>
15
+ <a href=""><img src="https://img.shields.io/badge/License-MIT-teal.svg" alt="MIT License" /></a>
20
16
  <br>
21
17
  <br>
22
18
  </div>
23
19
 
24
20
  TypeORM is an [ORM](https://en.wikipedia.org/wiki/Object-relational_mapping)
25
- that can run in NodeJS, Browser, Cordova, PhoneGap, Ionic, React Native, NativeScript, Expo, and Electron platforms
21
+ that can run in Node.js, Browser, Cordova, Ionic, React Native, NativeScript, Expo, and Electron platforms
26
22
  and can be used with TypeScript and JavaScript (ES2021).
27
23
  Its goal is to always support the latest JavaScript features and provide additional features
28
24
  that help you to develop any kind of application that uses databases - from
29
25
  small applications with a few tables to large-scale enterprise applications
30
26
  with multiple databases.
31
27
 
32
- TypeORM supports both [Active Record](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-active-record-pattern) and [Data Mapper](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-data-mapper-pattern) patterns,
33
- unlike all other JavaScript ORMs currently in existence,
34
- which means you can write high-quality, loosely coupled, scalable,
35
- maintainable applications in the most productive way.
28
+ TypeORM supports more databases than any other JS/TS ORM: [Google Spanner](./docs/docs/drivers/google-spanner.md), [Microsoft SqlServer](./docs/docs/drivers/microsoft-sqlserver.md), [MySQL/MariaDB](./docs/docs/drivers/mysql.md), [MongoDB](./docs/docs/drivers/mongodb.md), [Oracle](./docs/docs/drivers/oracle.md), [Postgres](./docs/docs/drivers/postgres.md), [SAP HANA](./docs/docs/drivers/sap.md) and [SQLite](./docs/docs/drivers/sqlite.md), as well we derived databases and different drivers.
29
+
30
+ TypeORM supports both [Active Record](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-active-record-pattern) and [Data Mapper](./docs/docs/guides/1-active-record-data-mapper.md#what-is-the-data-mapper-pattern) patterns, unlike all other JavaScript ORMs currently in existence, which means you can write high-quality, loosely coupled, scalable, maintainable applications in the most productive way.
36
31
 
37
32
  TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate.org/orm/),
38
33
  [Doctrine](http://www.doctrine-project.org/) and [Entity Framework](https://www.asp.net/entity-framework).
@@ -47,7 +42,7 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
47
42
  - Clean object-relational model.
48
43
  - Associations (relations).
49
44
  - Eager and lazy relations.
50
- - Uni-directional, bi-directional, and self-referenced relations.
45
+ - Unidirectional, bidirectional, and self-referenced relations.
51
46
  - Supports multiple inheritance patterns.
52
47
  - Cascades.
53
48
  - Indices.
@@ -69,7 +64,7 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
69
64
  - Schema declaration in models or separate configuration files.
70
65
  - Supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / SAP Hana / sql.js.
71
66
  - Supports MongoDB NoSQL database.
72
- - Works in NodeJS / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
67
+ - Works in Node.js / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
73
68
  - TypeScript and JavaScript support.
74
69
  - ESM and CommonJS support.
75
70
  - Produced code is performant, flexible, clean, and maintainable.
@@ -78,7 +73,7 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
78
73
 
79
74
  And more...
80
75
 
81
- With TypeORM your models look like this:
76
+ With TypeORM, your models look like this:
82
77
 
83
78
  ```javascript
84
79
  import { Entity, PrimaryGeneratedColumn, Column } from "typeorm"
@@ -164,1099 +159,6 @@ const timber = await User.findOneBy({
164
159
  await timber.remove()
165
160
  ```
166
161
 
167
- ## Installation
168
-
169
- 1. Install the npm package:
170
-
171
- `npm install typeorm --save`
172
-
173
- 2. You need to install `reflect-metadata` shim:
174
-
175
- `npm install reflect-metadata --save`
176
-
177
- and import it somewhere in the global place of your app (for example in `app.ts`):
178
-
179
- `import "reflect-metadata"`
180
-
181
- 3. You may need to install node typings:
182
-
183
- `npm install @types/node --save-dev`
184
-
185
- 4. Install a database driver:
186
-
187
- - for **MySQL** or **MariaDB**
188
-
189
- `npm install mysql --save` (you can install `mysql2` instead as well)
190
-
191
- - for **PostgreSQL** or **CockroachDB**
192
-
193
- `npm install pg --save`
194
-
195
- - for **SQLite**
196
-
197
- `npm install sqlite3 --save`
198
-
199
- - for **Microsoft SQL Server**
200
-
201
- `npm install mssql --save`
202
-
203
- - for **sql.js**
204
-
205
- `npm install sql.js --save`
206
-
207
- - for **Oracle**
208
-
209
- `npm install oracledb --save`
210
-
211
- To make the Oracle driver work, you need to follow the installation instructions from
212
- [their](https://github.com/oracle/node-oracledb) site.
213
-
214
- - for **SAP Hana**
215
-
216
- ```
217
- npm install @sap/hana-client
218
- npm install hdb-pool
219
- ```
220
-
221
- _SAP Hana support made possible by the sponsorship of [Neptune Software](https://www.neptune-software.com/)._
222
-
223
- - for **Google Cloud Spanner**
224
-
225
- ```
226
- npm install @google-cloud/spanner --save
227
- ```
228
-
229
- Provide authentication credentials to your application code
230
- by setting the environment variable `GOOGLE_APPLICATION_CREDENTIALS`:
231
-
232
- ```shell
233
- # Linux/macOS
234
- export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"
235
-
236
- # Windows
237
- set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH
238
-
239
- # Replace KEY_PATH with the path of the JSON file that contains your service account key.
240
- ```
241
-
242
- To use Spanner with the emulator you should set `SPANNER_EMULATOR_HOST` environment variable:
243
-
244
- ```shell
245
- # Linux/macOS
246
- export SPANNER_EMULATOR_HOST=localhost:9010
247
-
248
- # Windows
249
- set SPANNER_EMULATOR_HOST=localhost:9010
250
- ```
251
-
252
- - for **MongoDB** (experimental)
253
-
254
- `npm install mongodb@^5.2.0 --save`
255
-
256
- - for **NativeScript**, **react-native** and **Cordova**
257
-
258
- Check [documentation of supported platforms](./docs/docs/help/2-supported-platforms.md)
259
-
260
- Install only _one_ of them, depending on which database you use.
261
-
262
- ##### TypeScript configuration
263
-
264
- Also, make sure you are using TypeScript version **4.5** or higher,
265
- and you have enabled the following settings in `tsconfig.json`:
266
-
267
- ```json
268
- "emitDecoratorMetadata": true,
269
- "experimentalDecorators": true,
270
- ```
271
-
272
- You may also need to enable `es6` in the `lib` section of compiler options, or install `es6-shim` from `@types`.
273
-
274
- ## Quick Start
275
-
276
- The quickest way to get started with TypeORM is to use its CLI commands to generate a starter project.
277
- Quick start works only if you are using TypeORM in a NodeJS application.
278
- If you are using other platforms, proceed to the [step-by-step guide](#step-by-step-guide).
279
-
280
- To create a new project using CLI, run the following command:
281
-
282
- ```shell
283
- npx typeorm init --name MyProject --database postgres
284
- ```
285
-
286
- Where `name` is the name of your project and `database` is the database you'll use.
287
- Database can be one of the following values: `mysql`, `mariadb`, `postgres`, `cockroachdb`, `sqlite`, `mssql`, `sap`, `spanner`, `oracle`, `mongodb`,
288
- `cordova`, `react-native`, `expo`, `nativescript`.
289
-
290
- This command will generate a new project in the `MyProject` directory with the following files:
291
-
292
- ```
293
- MyProject
294
- ├── src // place of your TypeScript code
295
- │ ├── entity // place where your entities (database models) are stored
296
- │ │ └── User.ts // sample entity
297
- │ ├── migration // place where your migrations are stored
298
- │ ├── data-source.ts // data source and all connection configuration
299
- │ └── index.ts // start point of your application
300
- ├── .gitignore // standard gitignore file
301
- ├── package.json // node module dependencies
302
- ├── README.md // simple readme file
303
- └── tsconfig.json // TypeScript compiler options
304
- ```
305
-
306
- > You can also run `typeorm init` on an existing node project, but be careful - it may override some files you already have.
307
-
308
- The next step is to install new project dependencies:
309
-
310
- ```shell
311
- cd MyProject
312
- npm install
313
- ```
314
-
315
- After you have all dependencies installed, edit the `data-source.ts` file and put your own database connection configuration options in there:
316
-
317
- ```ts
318
- export const AppDataSource = new DataSource({
319
- type: "postgres",
320
- host: "localhost",
321
- port: 5432,
322
- username: "test",
323
- password: "test",
324
- database: "test",
325
- synchronize: true,
326
- logging: true,
327
- entities: [Post, Category],
328
- subscribers: [],
329
- migrations: [],
330
- })
331
- ```
332
-
333
- Particularly, most of the time you'll only need to configure
334
- `host`, `username`, `password`, `database` and maybe `port` options.
335
-
336
- Once you finish with configuration and all node modules are installed, you can run your application:
337
-
338
- ```shell
339
- npm start
340
- ```
341
-
342
- That's it, your application should successfully run and insert a new user into the database.
343
- You can continue to work with this project and integrate other modules you need and start
344
- creating more entities.
345
-
346
- > You can generate an ESM project by running
347
- > `npx typeorm init --name MyProject --database postgres --module esm` command.
348
-
349
- > You can generate an even more advanced project with express installed by running
350
- > `npx typeorm init --name MyProject --database mysql --express` command.
351
-
352
- > You can generate a docker-compose file by running
353
- > `npx typeorm init --name MyProject --database postgres --docker` command.
354
-
355
- ## Step-by-Step Guide
356
-
357
- What are you expecting from ORM?
358
- First of all, you are expecting it will create database tables for you
359
- and find / insert / update / delete your data without the pain of
360
- having to write lots of hardly maintainable SQL queries.
361
- This guide will show you how to set up TypeORM from scratch and make it do what you are expecting from an ORM.
362
-
363
- ### Create a model
364
-
365
- Working with a database starts with creating tables.
366
- How do you tell TypeORM to create a database table?
367
- The answer is - through the models.
368
- Your models in your app are your database tables.
369
-
370
- For example, you have a `Photo` model:
371
-
372
- ```javascript
373
- export class Photo {
374
- id: number
375
- name: string
376
- description: string
377
- filename: string
378
- views: number
379
- isPublished: boolean
380
- }
381
- ```
382
-
383
- And you want to store photos in your database.
384
- To store things in the database, first, you need a database table,
385
- and database tables are created from your models.
386
- Not all models, but only those you define as _entities_.
387
-
388
- ### Create an entity
389
-
390
- _Entity_ is your model decorated by an `@Entity` decorator.
391
- A database table will be created for such models.
392
- You work with entities everywhere in TypeORM.
393
- You can load/insert/update/remove and perform other operations with them.
394
-
395
- Let's make our `Photo` model an entity:
396
-
397
- ```javascript
398
- import { Entity } from "typeorm"
399
-
400
- @Entity()
401
- export class Photo {
402
- id: number
403
- name: string
404
- description: string
405
- filename: string
406
- views: number
407
- isPublished: boolean
408
- }
409
- ```
410
-
411
- Now, a database table will be created for the `Photo` entity and we'll be able to work with it anywhere in our app.
412
- We have created a database table, however, what table can exist without columns?
413
- Let's create a few columns in our database table.
414
-
415
- ### Adding table columns
416
-
417
- To add database columns, you simply need to decorate an entity's properties you want to make into a column
418
- with a `@Column` decorator.
419
-
420
- ```javascript
421
- import { Entity, Column } from "typeorm"
422
-
423
- @Entity()
424
- export class Photo {
425
- @Column()
426
- id: number
427
-
428
- @Column()
429
- name: string
430
-
431
- @Column()
432
- description: string
433
-
434
- @Column()
435
- filename: string
436
-
437
- @Column()
438
- views: number
439
-
440
- @Column()
441
- isPublished: boolean
442
- }
443
- ```
444
-
445
- Now `id`, `name`, `description`, `filename`, `views`, and `isPublished` columns will be added to the `photo` table.
446
- Column types in the database are inferred from the property types you used, e.g.
447
- `number` will be converted into `integer`, `string` into `varchar`, `boolean` into `bool`, etc.
448
- But you can use any column type your database supports by explicitly specifying a column type into the `@Column` decorator.
449
-
450
- We generated a database table with columns, but there is one thing left.
451
- Each database table must have a column with a primary key.
452
-
453
- ### Creating a primary column
454
-
455
- Each entity **must** have at least one primary key column.
456
- This is a requirement and you can't avoid it.
457
- To make a column a primary key, you need to use the `@PrimaryColumn` decorator.
458
-
459
- ```javascript
460
- import { Entity, Column, PrimaryColumn } from "typeorm"
461
-
462
- @Entity()
463
- export class Photo {
464
- @PrimaryColumn()
465
- id: number
466
-
467
- @Column()
468
- name: string
469
-
470
- @Column()
471
- description: string
472
-
473
- @Column()
474
- filename: string
475
-
476
- @Column()
477
- views: number
478
-
479
- @Column()
480
- isPublished: boolean
481
- }
482
- ```
483
-
484
- ### Creating an auto-generated column
485
-
486
- Now, let's say you want your id column to be auto-generated (this is known as auto-increment / sequence / serial / generated identity column).
487
- To do that, you need to change the `@PrimaryColumn` decorator to a `@PrimaryGeneratedColumn` decorator:
488
-
489
- ```javascript
490
- import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"
491
-
492
- @Entity()
493
- export class Photo {
494
- @PrimaryGeneratedColumn()
495
- id: number
496
-
497
- @Column()
498
- name: string
499
-
500
- @Column()
501
- description: string
502
-
503
- @Column()
504
- filename: string
505
-
506
- @Column()
507
- views: number
508
-
509
- @Column()
510
- isPublished: boolean
511
- }
512
- ```
513
-
514
- ### Column data types
515
-
516
- Next, let's fix our data types. By default, the string is mapped to a varchar(255)-like type (depending on the database type).
517
- The number is mapped to an integer-like type (depending on the database type).
518
- We don't want all our columns to be limited varchars or integers.
519
- Let's setup the correct data types:
520
-
521
- ```javascript
522
- import { Entity, Column, PrimaryGeneratedColumn } from "typeorm"
523
-
524
- @Entity()
525
- export class Photo {
526
- @PrimaryGeneratedColumn()
527
- id: number
528
-
529
- @Column({
530
- length: 100,
531
- })
532
- name: string
533
-
534
- @Column("text")
535
- description: string
536
-
537
- @Column()
538
- filename: string
539
-
540
- @Column("double")
541
- views: number
542
-
543
- @Column()
544
- isPublished: boolean
545
- }
546
- ```
547
-
548
- Column types are database-specific.
549
- You can set any column type your database supports.
550
- More information on supported column types can be found [here](./docs/docs/entity/1-entities.md#column-types).
551
-
552
- ### Creating a new `DataSource`
553
-
554
- Now, when our entity is created, let's create `index.ts` file and set up our `DataSource` there:
555
-
556
- ```javascript
557
- import "reflect-metadata"
558
- import { DataSource } from "typeorm"
559
- import { Photo } from "./entity/Photo"
560
-
561
- const AppDataSource = new DataSource({
562
- type: "postgres",
563
- host: "localhost",
564
- port: 5432,
565
- username: "root",
566
- password: "admin",
567
- database: "test",
568
- entities: [Photo],
569
- synchronize: true,
570
- logging: false,
571
- })
572
-
573
- // to initialize the initial connection with the database, register all entities
574
- // and "synchronize" database schema, call "initialize()" method of a newly created database
575
- // once in your application bootstrap
576
- AppDataSource.initialize()
577
- .then(() => {
578
- // here you can start to work with your database
579
- })
580
- .catch((error) => console.log(error))
581
- ```
582
-
583
- We are using Postgres in this example, but you can use any other supported database.
584
- To use another database, simply change the `type` in the options to the database type you are using:
585
- `mysql`, `mariadb`, `postgres`, `cockroachdb`, `sqlite`, `mssql`, `oracle`, `sap`, `spanner`, `cordova`, `nativescript`, `react-native`,
586
- `expo`, or `mongodb`.
587
- Also make sure to use your own host, port, username, password, and database settings.
588
-
589
- We added our Photo entity to the list of entities for this data source.
590
- Each entity you are using in your connection must be listed there.
591
-
592
- Setting `synchronize` makes sure your entities will be synced with the database, every time you run the application.
593
-
594
- ### Running the application
595
-
596
- Now if you run your `index.ts`, a connection with the database will be initialized and a database table for your photos will be created.
597
-
598
- ```shell
599
- +-------------+--------------+----------------------------+
600
- | photo |
601
- +-------------+--------------+----------------------------+
602
- | id | int(11) | PRIMARY KEY AUTO_INCREMENT |
603
- | name | varchar(100) | |
604
- | description | text | |
605
- | filename | varchar(255) | |
606
- | views | int(11) | |
607
- | isPublished | boolean | |
608
- +-------------+--------------+----------------------------+
609
- ```
610
-
611
- ### Creating and inserting a photo into the database
612
-
613
- Now let's create a new photo to save it in the database:
614
-
615
- ```javascript
616
- import { Photo } from "./entity/Photo"
617
- import { AppDataSource } from "./index"
618
-
619
- const photo = new Photo()
620
- photo.name = "Me and Bears"
621
- photo.description = "I am near polar bears"
622
- photo.filename = "photo-with-bears.jpg"
623
- photo.views = 1
624
- photo.isPublished = true
625
-
626
- await AppDataSource.manager.save(photo)
627
- console.log("Photo has been saved. Photo id is", photo.id)
628
- ```
629
-
630
- Once your entity is saved it will get a newly generated id.
631
- `save` method returns an instance of the same object you pass to it.
632
- It's not a new copy of the object, it modifies its "id" and returns it.
633
-
634
- ### Using Entity Manager
635
-
636
- We just created a new photo and saved it in the database.
637
- We used `EntityManager` to save it.
638
- Using entity manager you can manipulate any entity in your app.
639
- For example, let's load our saved entity:
640
-
641
- ```javascript
642
- import { Photo } from "./entity/Photo"
643
- import { AppDataSource } from "./index"
644
-
645
- const savedPhotos = await AppDataSource.manager.find(Photo)
646
- console.log("All photos from the db: ", savedPhotos)
647
- ```
648
-
649
- `savedPhotos` will be an array of Photo objects with the data loaded from the database.
650
-
651
- Learn more about EntityManager [here](./docs/docs/working-with-entity-manager/1-working-with-entity-manager.md).
652
-
653
- ### Using Repositories
654
-
655
- Now let's refactor our code and use `Repository` instead of `EntityManager`.
656
- Each entity has its own repository which handles all operations with its entity.
657
- When you deal with entities a lot, Repositories are more convenient to use than EntityManagers:
658
-
659
- ```javascript
660
- import { Photo } from "./entity/Photo"
661
- import { AppDataSource } from "./index"
662
-
663
- const photo = new Photo()
664
- photo.name = "Me and Bears"
665
- photo.description = "I am near polar bears"
666
- photo.filename = "photo-with-bears.jpg"
667
- photo.views = 1
668
- photo.isPublished = true
669
-
670
- const photoRepository = AppDataSource.getRepository(Photo)
671
-
672
- await photoRepository.save(photo)
673
- console.log("Photo has been saved")
674
-
675
- const savedPhotos = await photoRepository.find()
676
- console.log("All photos from the db: ", savedPhotos)
677
- ```
678
-
679
- Learn more about Repository [here](./docs/docs/working-with-entity-manager/2-working-with-repository.md).
680
-
681
- ### Loading from the database
682
-
683
- Let's try more load operations using the Repository:
684
-
685
- ```javascript
686
- import { Photo } from "./entity/Photo"
687
- import { AppDataSource } from "./index"
688
-
689
- const photoRepository = AppDataSource.getRepository(Photo)
690
- const allPhotos = await photoRepository.find()
691
- console.log("All photos from the db: ", allPhotos)
692
-
693
- const firstPhoto = await photoRepository.findOneBy({
694
- id: 1,
695
- })
696
- console.log("First photo from the db: ", firstPhoto)
697
-
698
- const meAndBearsPhoto = await photoRepository.findOneBy({
699
- name: "Me and Bears",
700
- })
701
- console.log("Me and Bears photo from the db: ", meAndBearsPhoto)
702
-
703
- const allViewedPhotos = await photoRepository.findBy({ views: 1 })
704
- console.log("All viewed photos: ", allViewedPhotos)
705
-
706
- const allPublishedPhotos = await photoRepository.findBy({ isPublished: true })
707
- console.log("All published photos: ", allPublishedPhotos)
708
-
709
- const [photos, photosCount] = await photoRepository.findAndCount()
710
- console.log("All photos: ", photos)
711
- console.log("Photos count: ", photosCount)
712
- ```
713
-
714
- ### Updating in the database
715
-
716
- Now let's load a single photo from the database, update it and save it:
717
-
718
- ```javascript
719
- import { Photo } from "./entity/Photo"
720
- import { AppDataSource } from "./index"
721
-
722
- const photoRepository = AppDataSource.getRepository(Photo)
723
- const photoToUpdate = await photoRepository.findOneBy({
724
- id: 1,
725
- })
726
- photoToUpdate.name = "Me, my friends and polar bears"
727
- await photoRepository.save(photoToUpdate)
728
- ```
729
-
730
- Now photo with `id = 1` will be updated in the database.
731
-
732
- ### Removing from the database
733
-
734
- Now let's remove our photo from the database:
735
-
736
- ```javascript
737
- import { Photo } from "./entity/Photo"
738
- import { AppDataSource } from "./index"
739
-
740
- const photoRepository = AppDataSource.getRepository(Photo)
741
- const photoToRemove = await photoRepository.findOneBy({
742
- id: 1,
743
- })
744
- await photoRepository.remove(photoToRemove)
745
- ```
746
-
747
- Now photo with `id = 1` will be removed from the database.
748
-
749
- ### Creating a one-to-one relation
750
-
751
- Let's create a one-to-one relationship with another class.
752
- Let's create a new class in `PhotoMetadata.ts`. This PhotoMetadata class is supposed to contain our photo's additional meta-information:
753
-
754
- ```javascript
755
- import {
756
- Entity,
757
- Column,
758
- PrimaryGeneratedColumn,
759
- OneToOne,
760
- JoinColumn,
761
- } from "typeorm"
762
- import { Photo } from "./Photo"
763
-
764
- @Entity()
765
- export class PhotoMetadata {
766
- @PrimaryGeneratedColumn()
767
- id: number
768
-
769
- @Column("int")
770
- height: number
771
-
772
- @Column("int")
773
- width: number
774
-
775
- @Column()
776
- orientation: string
777
-
778
- @Column()
779
- compressed: boolean
780
-
781
- @Column()
782
- comment: string
783
-
784
- @OneToOne(() => Photo)
785
- @JoinColumn()
786
- photo: Photo
787
- }
788
- ```
789
-
790
- Here, we are using a new decorator called `@OneToOne`. It allows us to create a one-to-one relationship between two entities. We also add a `@JoinColumn` decorator, which indicates that this side of the relationship will own the relationship.
791
- Relations can be unidirectional or bidirectional.
792
- Only one side of relational can be owning.
793
- Using `@JoinColumn` decorator is required on the owner side of the relationship.
794
-
795
- If you run the app, you'll see a newly generated table, and it will contain a column with a foreign key for the photo relation:
796
-
797
- ```shell
798
- +-------------+--------------+----------------------------+
799
- | photo_metadata |
800
- +-------------+--------------+----------------------------+
801
- | id | int(11) | PRIMARY KEY AUTO_INCREMENT |
802
- | height | int(11) | |
803
- | width | int(11) | |
804
- | comment | varchar(255) | |
805
- | compressed | boolean | |
806
- | orientation | varchar(255) | |
807
- | photoId | int(11) | FOREIGN KEY |
808
- +-------------+--------------+----------------------------+
809
- ```
810
-
811
- ### Save a one-to-one relation
812
-
813
- Now let's save a photo, and its metadata and attach them to each other.
814
-
815
- ```javascript
816
- import { Photo } from "./entity/Photo"
817
- import { PhotoMetadata } from "./entity/PhotoMetadata"
818
-
819
- // create a photo
820
- const photo = new Photo()
821
- photo.name = "Me and Bears"
822
- photo.description = "I am near polar bears"
823
- photo.filename = "photo-with-bears.jpg"
824
- photo.views = 1
825
- photo.isPublished = true
826
-
827
- // create a photo metadata
828
- const metadata = new PhotoMetadata()
829
- metadata.height = 640
830
- metadata.width = 480
831
- metadata.compressed = true
832
- metadata.comment = "cybershoot"
833
- metadata.orientation = "portrait"
834
- metadata.photo = photo // this way we connect them
835
-
836
- // get entity repositories
837
- const photoRepository = AppDataSource.getRepository(Photo)
838
- const metadataRepository = AppDataSource.getRepository(PhotoMetadata)
839
-
840
- // first we should save a photo
841
- await photoRepository.save(photo)
842
-
843
- // photo is saved. Now we need to save a photo metadata
844
- await metadataRepository.save(metadata)
845
-
846
- // done
847
- console.log(
848
- "Metadata is saved, and the relation between metadata and photo is created in the database too",
849
- )
850
- ```
851
-
852
- ### Inverse side of the relationship
853
-
854
- Relations can be unidirectional or bidirectional.
855
- Currently, our relation between PhotoMetadata and Photo is unidirectional.
856
- The owner of the relation is PhotoMetadata, and Photo doesn't know anything about PhotoMetadata.
857
- This makes it complicated to access PhotoMetadata from the Photo side.
858
- To fix this issue we should add an inverse relation, and make relations between PhotoMetadata and Photo bidirectional.
859
- Let's modify our entities:
860
-
861
- ```javascript
862
- import {
863
- Entity,
864
- Column,
865
- PrimaryGeneratedColumn,
866
- OneToOne,
867
- JoinColumn,
868
- } from "typeorm"
869
- import { Photo } from "./Photo"
870
-
871
- @Entity()
872
- export class PhotoMetadata {
873
- /* ... other columns */
874
-
875
- @OneToOne(() => Photo, (photo) => photo.metadata)
876
- @JoinColumn()
877
- photo: Photo
878
- }
879
- ```
880
-
881
- ```javascript
882
- import { Entity, Column, PrimaryGeneratedColumn, OneToOne } from "typeorm"
883
- import { PhotoMetadata } from "./PhotoMetadata"
884
-
885
- @Entity()
886
- export class Photo {
887
- /* ... other columns */
888
-
889
- @OneToOne(() => PhotoMetadata, (photoMetadata) => photoMetadata.photo)
890
- metadata: PhotoMetadata
891
- }
892
- ```
893
-
894
- `photo => photo.metadata` is a function that returns the name of the inverse side of the relation.
895
- Here we show that the metadata property of the Photo class is where we store PhotoMetadata in the Photo class.
896
- Instead of passing a function that returns a property of the photo, you could alternatively simply pass a string to `@OneToOne` decorator, like `"metadata"`.
897
- But we used this function-typed approach to make our refactoring easier.
898
-
899
- Note that we should use the `@JoinColumn` decorator only on one side of a relation.
900
- Whichever side you put this decorator on will be the owning side of the relationship.
901
- The owning side of a relationship contains a column with a foreign key in the database.
902
-
903
- ### Relations in ESM projects
904
-
905
- If you use ESM in your TypeScript project, you should use the `Relation` wrapper type in relation properties to avoid circular dependency issues.
906
- Let's modify our entities:
907
-
908
- ```javascript
909
- import {
910
- Entity,
911
- Column,
912
- PrimaryGeneratedColumn,
913
- OneToOne,
914
- JoinColumn,
915
- Relation,
916
- } from "typeorm"
917
- import { Photo } from "./Photo"
918
-
919
- @Entity()
920
- export class PhotoMetadata {
921
- /* ... other columns */
922
-
923
- @OneToOne(() => Photo, (photo) => photo.metadata)
924
- @JoinColumn()
925
- photo: Relation<Photo>
926
- }
927
- ```
928
-
929
- ```javascript
930
- import {
931
- Entity,
932
- Column,
933
- PrimaryGeneratedColumn,
934
- OneToOne,
935
- Relation,
936
- } from "typeorm"
937
- import { PhotoMetadata } from "./PhotoMetadata"
938
-
939
- @Entity()
940
- export class Photo {
941
- /* ... other columns */
942
-
943
- @OneToOne(() => PhotoMetadata, (photoMetadata) => photoMetadata.photo)
944
- metadata: Relation<PhotoMetadata>
945
- }
946
- ```
947
-
948
- ### Loading objects with their relations
949
-
950
- Now let's load our photo and its photo metadata in a single query.
951
- There are two ways to do it - using `find*` methods or using `QueryBuilder` functionality.
952
- Let's use `find*` method first.
953
- `find*` methods allow you to specify an object with the `FindOneOptions` / `FindManyOptions` interface.
954
-
955
- ```javascript
956
- import { Photo } from "./entity/Photo"
957
- import { PhotoMetadata } from "./entity/PhotoMetadata"
958
- import { AppDataSource } from "./index"
959
-
960
- const photoRepository = AppDataSource.getRepository(Photo)
961
- const photos = await photoRepository.find({
962
- relations: {
963
- metadata: true,
964
- },
965
- })
966
- ```
967
-
968
- Here, photos will contain an array of photos from the database, and each photo will contain its photo metadata.
969
- Learn more about Find Options in [this documentation](./docs/docs/working-with-entity-manager/3-find-options.md).
970
-
971
- Using find options is good and dead simple, but if you need a more complex query, you should use `QueryBuilder` instead.
972
- `QueryBuilder` allows more complex queries to be used in an elegant way:
973
-
974
- ```javascript
975
- import { Photo } from "./entity/Photo"
976
- import { PhotoMetadata } from "./entity/PhotoMetadata"
977
- import { AppDataSource } from "./index"
978
-
979
- const photos = await AppDataSource.getRepository(Photo)
980
- .createQueryBuilder("photo")
981
- .innerJoinAndSelect("photo.metadata", "metadata")
982
- .getMany()
983
- ```
984
-
985
- `QueryBuilder` allows the creation and execution of SQL queries of almost any complexity.
986
- When you work with `QueryBuilder`, think like you are creating an SQL query.
987
- In this example, "photo" and "metadata" are aliases applied to selected photos.
988
- You use aliases to access columns and properties of the selected data.
989
-
990
- ### Using cascades to automatically save related objects
991
-
992
- We can set up cascade options in our relations, in the cases when we want our related object to be saved whenever the other object is saved.
993
- Let's change our photo's `@OneToOne` decorator a bit:
994
-
995
- ```javascript
996
- export class Photo {
997
- // ... other columns
998
-
999
- @OneToOne(() => PhotoMetadata, (metadata) => metadata.photo, {
1000
- cascade: true,
1001
- })
1002
- metadata: PhotoMetadata
1003
- }
1004
- ```
1005
-
1006
- Using `cascade` allows us not to separately save photos and separately save metadata objects now.
1007
- Now we can simply save a photo object, and the metadata object will be saved automatically because of cascade options.
1008
-
1009
- ```javascript
1010
- import { AppDataSource } from "./index"
1011
-
1012
- // create photo object
1013
- const photo = new Photo()
1014
- photo.name = "Me and Bears"
1015
- photo.description = "I am near polar bears"
1016
- photo.filename = "photo-with-bears.jpg"
1017
- photo.isPublished = true
1018
-
1019
- // create photo metadata object
1020
- const metadata = new PhotoMetadata()
1021
- metadata.height = 640
1022
- metadata.width = 480
1023
- metadata.compressed = true
1024
- metadata.comment = "cybershoot"
1025
- metadata.orientation = "portrait"
1026
-
1027
- photo.metadata = metadata // this way we connect them
1028
-
1029
- // get repository
1030
- const photoRepository = AppDataSource.getRepository(Photo)
1031
-
1032
- // saving a photo also save the metadata
1033
- await photoRepository.save(photo)
1034
-
1035
- console.log("Photo is saved, photo metadata is saved too.")
1036
- ```
1037
-
1038
- Notice that we now set the photo's `metadata` property, instead of the metadata's `photo` property as before. The `cascade` feature only works if you connect the photo to its metadata from the photo's side. If you set the metadata side, the metadata would not be saved automatically.
1039
-
1040
- ### Creating a many-to-one / one-to-many relation
1041
-
1042
- Let's create a many-to-one/one-to-many relation.
1043
- Let's say a photo has one author, and each author can have many photos.
1044
- First, let's create an `Author` class:
1045
-
1046
- ```javascript
1047
- import {
1048
- Entity,
1049
- Column,
1050
- PrimaryGeneratedColumn,
1051
- OneToMany,
1052
- JoinColumn,
1053
- } from "typeorm"
1054
- import { Photo } from "./Photo"
1055
-
1056
- @Entity()
1057
- export class Author {
1058
- @PrimaryGeneratedColumn()
1059
- id: number
1060
-
1061
- @Column()
1062
- name: string
1063
-
1064
- @OneToMany(() => Photo, (photo) => photo.author) // note: we will create author property in the Photo class below
1065
- photos: Photo[]
1066
- }
1067
- ```
1068
-
1069
- `Author` contains an inverse side of a relation.
1070
- `OneToMany` is always an inverse side of the relation, and it can't exist without `ManyToOne` on the other side of the relation.
1071
-
1072
- Now let's add the owner side of the relation into the Photo entity:
1073
-
1074
- ```javascript
1075
- import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from "typeorm"
1076
- import { PhotoMetadata } from "./PhotoMetadata"
1077
- import { Author } from "./Author"
1078
-
1079
- @Entity()
1080
- export class Photo {
1081
- /* ... other columns */
1082
-
1083
- @ManyToOne(() => Author, (author) => author.photos)
1084
- author: Author
1085
- }
1086
- ```
1087
-
1088
- In many-to-one / one-to-many relations, the owner side is always many-to-one.
1089
- It means that the class that uses `@ManyToOne` will store the id of the related object.
1090
-
1091
- After you run the application, the ORM will create the `author` table:
1092
-
1093
- ```shell
1094
- +-------------+--------------+----------------------------+
1095
- | author |
1096
- +-------------+--------------+----------------------------+
1097
- | id | int(11) | PRIMARY KEY AUTO_INCREMENT |
1098
- | name | varchar(255) | |
1099
- +-------------+--------------+----------------------------+
1100
- ```
1101
-
1102
- It will also modify the `photo` table, adding a new `author` column and creating a foreign key for it:
1103
-
1104
- ```shell
1105
- +-------------+--------------+----------------------------+
1106
- | photo |
1107
- +-------------+--------------+----------------------------+
1108
- | id | int(11) | PRIMARY KEY AUTO_INCREMENT |
1109
- | name | varchar(255) | |
1110
- | description | varchar(255) | |
1111
- | filename | varchar(255) | |
1112
- | isPublished | boolean | |
1113
- | authorId | int(11) | FOREIGN KEY |
1114
- +-------------+--------------+----------------------------+
1115
- ```
1116
-
1117
- ### Creating a many-to-many relation
1118
-
1119
- Let's create a many-to-many relation.
1120
- Let's say a photo can be in many albums, and each album can contain many photos.
1121
- Let's create an `Album` class:
1122
-
1123
- ```javascript
1124
- import {
1125
- Entity,
1126
- PrimaryGeneratedColumn,
1127
- Column,
1128
- ManyToMany,
1129
- JoinTable,
1130
- } from "typeorm"
1131
-
1132
- @Entity()
1133
- export class Album {
1134
- @PrimaryGeneratedColumn()
1135
- id: number
1136
-
1137
- @Column()
1138
- name: string
1139
-
1140
- @ManyToMany(() => Photo, (photo) => photo.albums)
1141
- @JoinTable()
1142
- photos: Photo[]
1143
- }
1144
- ```
1145
-
1146
- `@JoinTable` is required to specify that this is the owner side of the relationship.
1147
-
1148
- Now let's add the inverse side of our relation to the `Photo` class:
1149
-
1150
- ```javascript
1151
- export class Photo {
1152
- // ... other columns
1153
-
1154
- @ManyToMany(() => Album, (album) => album.photos)
1155
- albums: Album[]
1156
- }
1157
- ```
1158
-
1159
- After you run the application, the ORM will create a **album_photos_photo_albums** _junction table_:
1160
-
1161
- ```shell
1162
- +-------------+--------------+----------------------------+
1163
- | album_photos_photo_albums |
1164
- +-------------+--------------+----------------------------+
1165
- | album_id | int(11) | PRIMARY KEY FOREIGN KEY |
1166
- | photo_id | int(11) | PRIMARY KEY FOREIGN KEY |
1167
- +-------------+--------------+----------------------------+
1168
- ```
1169
-
1170
- Don't forget to register the `Album` class with your connection in the ORM:
1171
-
1172
- ```javascript
1173
- const options: DataSourceOptions = {
1174
- // ... other options
1175
- entities: [Photo, PhotoMetadata, Author, Album],
1176
- }
1177
- ```
1178
-
1179
- Now let's insert albums and photos into our database:
1180
-
1181
- ```javascript
1182
- import { AppDataSource } from "./index"
1183
-
1184
- // create a few albums
1185
- const album1 = new Album()
1186
- album1.name = "Bears"
1187
- await AppDataSource.manager.save(album1)
1188
-
1189
- const album2 = new Album()
1190
- album2.name = "Me"
1191
- await AppDataSource.manager.save(album2)
1192
-
1193
- // create a few photos
1194
- const photo = new Photo()
1195
- photo.name = "Me and Bears"
1196
- photo.description = "I am near polar bears"
1197
- photo.filename = "photo-with-bears.jpg"
1198
- photo.views = 1
1199
- photo.isPublished = true
1200
- photo.albums = [album1, album2]
1201
- await AppDataSource.manager.save(photo)
1202
-
1203
- // now our photo is saved and albums are attached to it
1204
- // now lets load them:
1205
- const loadedPhoto = await AppDataSource.getRepository(Photo).findOne({
1206
- where: {
1207
- id: 1,
1208
- },
1209
- relations: {
1210
- albums: true,
1211
- },
1212
- })
1213
- ```
1214
-
1215
- `loadedPhoto` will be equal to:
1216
-
1217
- ```javascript
1218
- {
1219
- id: 1,
1220
- name: "Me and Bears",
1221
- description: "I am near polar bears",
1222
- filename: "photo-with-bears.jpg",
1223
- albums: [{
1224
- id: 1,
1225
- name: "Bears"
1226
- }, {
1227
- id: 2,
1228
- name: "Me"
1229
- }]
1230
- }
1231
- ```
1232
-
1233
- ### Using QueryBuilder
1234
-
1235
- You can use QueryBuilder to build SQL queries of almost any complexity. For example, you can do this:
1236
-
1237
- ```javascript
1238
- const photos = await AppDataSource.getRepository(Photo)
1239
- .createQueryBuilder("photo") // first argument is an alias. Alias is what you are selecting - photos. You must specify it.
1240
- .innerJoinAndSelect("photo.metadata", "metadata")
1241
- .leftJoinAndSelect("photo.albums", "album")
1242
- .where("photo.isPublished = true")
1243
- .andWhere("(photo.name = :photoName OR photo.name = :bearName)")
1244
- .orderBy("photo.id", "DESC")
1245
- .skip(5)
1246
- .take(10)
1247
- .setParameters({ photoName: "My", bearName: "Mishka" })
1248
- .getMany()
1249
- ```
1250
-
1251
- This query selects all published photos with "My" or "Mishka" names.
1252
- It will select results from position 5 (pagination offset)
1253
- and will select only 10 results (pagination limit).
1254
- The selection result will be ordered by id in descending order.
1255
- The photo albums will be left joined and their metadata will be inner joined.
1256
-
1257
- You'll use the query builder in your application a lot.
1258
- Learn more about QueryBuilder [here](./docs/docs/query-builder/1-select-query-builder.md).
1259
-
1260
162
  ## Samples
1261
163
 
1262
164
  Take a look at the samples in [sample](https://github.com/typeorm/typeorm/tree/master/sample) for examples of usage.
@@ -1271,7 +173,7 @@ There are a few repositories that you can clone and start with:
1271
173
  - [Example how to use Express and TypeORM](https://github.com/typeorm/typescript-express-example)
1272
174
  - [Example how to use Koa and TypeORM](https://github.com/typeorm/typescript-koa-example)
1273
175
  - [Example how to use TypeORM with MongoDB](https://github.com/typeorm/mongo-typescript-example)
1274
- - [Example how to use TypeORM in a Cordova/PhoneGap app](https://github.com/typeorm/cordova-example)
176
+ - [Example how to use TypeORM in a Cordova app](https://github.com/typeorm/cordova-example)
1275
177
  - [Example how to use TypeORM with an Ionic app](https://github.com/typeorm/ionic-example)
1276
178
  - [Example how to use TypeORM with React Native](https://github.com/typeorm/react-native-example)
1277
179
  - [Example how to use TypeORM with Nativescript-Vue](https://github.com/typeorm/nativescript-vue-typeorm-sample)
@@ -1289,7 +191,7 @@ There are several extensions that simplify working with TypeORM and integrating
1289
191
  - Fixtures loader - [typeorm-fixtures-cli](https://github.com/RobinCK/typeorm-fixtures)
1290
192
  - ER Diagram generator - [typeorm-uml](https://github.com/eugene-manuilov/typeorm-uml/)
1291
193
  - another ER Diagram generator - [erdia](https://www.npmjs.com/package/erdia/)
1292
- - Create, drop & seed database - [typeorm-extension](https://github.com/tada5hi/typeorm-extension)
194
+ - Create, drop and seed database - [typeorm-extension](https://github.com/tada5hi/typeorm-extension)
1293
195
  - Automatically update `data-source.ts` after generating migrations/entities - [typeorm-codebase-sync](https://www.npmjs.com/package/typeorm-codebase-sync)
1294
196
  - Easy manipulation of `relations` objects - [typeorm-relations](https://npmjs.com/package/typeorm-relations)
1295
197
  - Automatically generate `relations` based on a GraphQL query - [typeorm-relations-graphql](https://npmjs.com/package/typeorm-relations-graphql)
@@ -1304,7 +206,7 @@ This project exists thanks to all the people who contribute:
1304
206
 
1305
207
  ## Sponsors
1306
208
 
1307
- Open source is hard and time-consuming. If you want to invest in TypeORM's future you can become a sponsor and allow our core team to spend more time on TypeORM's improvements and new features. [Become a sponsor](https://opencollective.com/typeorm)
209
+ Open source is hard and time-consuming. If you want to invest in TypeORM's future, you can become a sponsor and allow our core team to spend more time on TypeORM's improvements and new features. [Become a sponsor](https://opencollective.com/typeorm)
1308
210
 
1309
211
  <a href="https://opencollective.com/typeorm" target="_blank"><img src="https://opencollective.com/typeorm/tiers/sponsor.svg?width=890"></a>
1310
212