typeorm 0.2.39-dev.dd94c9d → 0.2.39-dev.ef33cf4
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 +60 -59
- package/browser/connection/ConnectionOptionsReader.js +2 -1
- package/browser/connection/ConnectionOptionsReader.js.map +1 -1
- package/browser/decorator/entity-view/ViewEntity.js +1 -0
- package/browser/decorator/entity-view/ViewEntity.js.map +1 -1
- package/browser/decorator/options/ViewEntityOptions.d.ts +5 -0
- package/browser/decorator/options/ViewEntityOptions.js.map +1 -1
- package/browser/driver/aurora-data-api/AuroraDataApiConnectionOptions.d.ts +5 -0
- package/browser/driver/aurora-data-api/AuroraDataApiConnectionOptions.js.map +1 -1
- package/browser/driver/aurora-data-api/AuroraDataApiDriver.js +6 -5
- package/browser/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
- package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.d.ts +5 -0
- package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.js.map +1 -1
- package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js +2 -1
- package/browser/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +5 -0
- package/browser/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js +4 -3
- package/browser/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachConnectionOptions.d.ts +10 -0
- package/browser/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
- package/browser/driver/cockroachdb/CockroachDriver.js +4 -3
- package/browser/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/browser/driver/cordova/CordovaConnectionOptions.d.ts +5 -0
- package/browser/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/browser/driver/cordova/CordovaDriver.js +2 -1
- package/browser/driver/cordova/CordovaDriver.js.map +1 -1
- package/browser/driver/mongodb/MongoConnectionOptions.d.ts +5 -0
- package/browser/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/browser/driver/mongodb/MongoDriver.js +2 -1
- package/browser/driver/mongodb/MongoDriver.js.map +1 -1
- package/browser/driver/mysql/MysqlConnectionOptions.d.ts +6 -0
- package/browser/driver/mysql/MysqlConnectionOptions.js.map +1 -1
- package/browser/driver/mysql/MysqlDriver.js +4 -2
- package/browser/driver/mysql/MysqlDriver.js.map +1 -1
- package/browser/driver/nativescript/NativescriptQueryRunner.js +45 -37
- package/browser/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/browser/driver/oracle/OracleConnectionOptions.d.ts +5 -0
- package/browser/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/browser/driver/oracle/OracleDriver.js +5 -4
- package/browser/driver/oracle/OracleDriver.js.map +1 -1
- package/browser/driver/postgres/PostgresConnectionOptions.d.ts +10 -0
- package/browser/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/browser/driver/postgres/PostgresDriver.js +5 -4
- package/browser/driver/postgres/PostgresDriver.js.map +1 -1
- package/browser/driver/react-native/ReactNativeConnectionOptions.d.ts +5 -0
- package/browser/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/browser/driver/react-native/ReactNativeDriver.js +2 -1
- package/browser/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/browser/driver/sap/SapConnectionOptions.d.ts +16 -6
- package/browser/driver/sap/SapConnectionOptions.js.map +1 -1
- package/browser/driver/sap/SapDriver.js +6 -3
- package/browser/driver/sap/SapDriver.js.map +1 -1
- package/browser/driver/sqlite/SqliteConnectionOptions.d.ts +5 -0
- package/browser/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/browser/driver/sqlite/SqliteDriver.js +4 -3
- package/browser/driver/sqlite/SqliteDriver.js.map +1 -1
- package/browser/driver/sqljs/SqljsConnectionOptions.d.ts +5 -0
- package/browser/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/browser/driver/sqljs/SqljsDriver.js +4 -2
- package/browser/driver/sqljs/SqljsDriver.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerConnectionOptions.d.ts +5 -0
- package/browser/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/browser/driver/sqlserver/SqlServerDriver.js +7 -6
- package/browser/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/browser/metadata/EntityMetadata.d.ts +5 -0
- package/browser/metadata/EntityMetadata.js +1 -0
- package/browser/metadata/EntityMetadata.js.map +1 -1
- package/browser/metadata-args/TableMetadataArgs.d.ts +4 -0
- package/browser/metadata-args/TableMetadataArgs.js.map +1 -1
- package/browser/migration/MigrationExecutor.js +4 -0
- package/browser/migration/MigrationExecutor.js.map +1 -1
- package/browser/query-builder/SelectQueryBuilder.js +5 -1
- package/browser/query-builder/SelectQueryBuilder.js.map +1 -1
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -8
- package/browser/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/browser/schema-builder/RdbmsSchemaBuilder.js +223 -148
- package/browser/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/browser/schema-builder/util/ViewUtils.d.ts +7 -0
- package/browser/schema-builder/util/ViewUtils.js +25 -0
- package/browser/schema-builder/util/ViewUtils.js.map +1 -0
- package/connection/ConnectionOptionsReader.js +2 -1
- package/connection/ConnectionOptionsReader.js.map +1 -1
- package/decorator/entity-view/ViewEntity.js +1 -0
- package/decorator/entity-view/ViewEntity.js.map +1 -1
- package/decorator/options/ViewEntityOptions.d.ts +5 -0
- package/decorator/options/ViewEntityOptions.js.map +1 -1
- package/driver/aurora-data-api/AuroraDataApiConnectionOptions.d.ts +5 -0
- package/driver/aurora-data-api/AuroraDataApiConnectionOptions.js.map +1 -1
- package/driver/aurora-data-api/AuroraDataApiDriver.js +6 -5
- package/driver/aurora-data-api/AuroraDataApiDriver.js.map +1 -1
- package/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.d.ts +5 -0
- package/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions.js.map +1 -1
- package/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js +2 -1
- package/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.d.ts +5 -0
- package/driver/better-sqlite3/BetterSqlite3ConnectionOptions.js.map +1 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js +2 -1
- package/driver/better-sqlite3/BetterSqlite3Driver.js.map +1 -1
- package/driver/cockroachdb/CockroachConnectionOptions.d.ts +10 -0
- package/driver/cockroachdb/CockroachConnectionOptions.js.map +1 -1
- package/driver/cockroachdb/CockroachDriver.js +4 -3
- package/driver/cockroachdb/CockroachDriver.js.map +1 -1
- package/driver/cordova/CordovaConnectionOptions.d.ts +5 -0
- package/driver/cordova/CordovaConnectionOptions.js.map +1 -1
- package/driver/cordova/CordovaDriver.js +2 -1
- package/driver/cordova/CordovaDriver.js.map +1 -1
- package/driver/mongodb/MongoConnectionOptions.d.ts +5 -0
- package/driver/mongodb/MongoConnectionOptions.js.map +1 -1
- package/driver/mongodb/MongoDriver.js +2 -1
- package/driver/mongodb/MongoDriver.js.map +1 -1
- package/driver/mysql/MysqlConnectionOptions.d.ts +6 -0
- package/driver/mysql/MysqlConnectionOptions.js.map +1 -1
- package/driver/mysql/MysqlDriver.js +4 -2
- package/driver/mysql/MysqlDriver.js.map +1 -1
- package/driver/nativescript/NativescriptQueryRunner.js +45 -37
- package/driver/nativescript/NativescriptQueryRunner.js.map +1 -1
- package/driver/oracle/OracleConnectionOptions.d.ts +5 -0
- package/driver/oracle/OracleConnectionOptions.js.map +1 -1
- package/driver/oracle/OracleDriver.js +5 -4
- package/driver/oracle/OracleDriver.js.map +1 -1
- package/driver/postgres/PostgresConnectionOptions.d.ts +10 -0
- package/driver/postgres/PostgresConnectionOptions.js.map +1 -1
- package/driver/postgres/PostgresDriver.js +5 -4
- package/driver/postgres/PostgresDriver.js.map +1 -1
- package/driver/react-native/ReactNativeConnectionOptions.d.ts +5 -0
- package/driver/react-native/ReactNativeConnectionOptions.js.map +1 -1
- package/driver/react-native/ReactNativeDriver.js +2 -1
- package/driver/react-native/ReactNativeDriver.js.map +1 -1
- package/driver/sap/SapConnectionOptions.d.ts +16 -6
- package/driver/sap/SapConnectionOptions.js.map +1 -1
- package/driver/sap/SapDriver.js +6 -3
- package/driver/sap/SapDriver.js.map +1 -1
- package/driver/sqlite/SqliteConnectionOptions.d.ts +5 -0
- package/driver/sqlite/SqliteConnectionOptions.js.map +1 -1
- package/driver/sqlite/SqliteDriver.js +2 -1
- package/driver/sqlite/SqliteDriver.js.map +1 -1
- package/driver/sqljs/SqljsConnectionOptions.d.ts +5 -0
- package/driver/sqljs/SqljsConnectionOptions.js.map +1 -1
- package/driver/sqljs/SqljsDriver.js +4 -2
- package/driver/sqljs/SqljsDriver.js.map +1 -1
- package/driver/sqlserver/SqlServerConnectionOptions.d.ts +5 -0
- package/driver/sqlserver/SqlServerConnectionOptions.js.map +1 -1
- package/driver/sqlserver/SqlServerDriver.js +7 -6
- package/driver/sqlserver/SqlServerDriver.js.map +1 -1
- package/metadata/EntityMetadata.d.ts +5 -0
- package/metadata/EntityMetadata.js +1 -0
- package/metadata/EntityMetadata.js.map +1 -1
- package/metadata-args/TableMetadataArgs.d.ts +4 -0
- package/metadata-args/TableMetadataArgs.js.map +1 -1
- package/migration/MigrationExecutor.js +4 -0
- package/migration/MigrationExecutor.js.map +1 -1
- package/package.json +1 -1
- package/query-builder/SelectQueryBuilder.js +5 -1
- package/query-builder/SelectQueryBuilder.js.map +1 -1
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js +2 -8
- package/query-builder/transformer/RawSqlResultsToEntityTransformer.js.map +1 -1
- package/schema-builder/RdbmsSchemaBuilder.js +222 -147
- package/schema-builder/RdbmsSchemaBuilder.js.map +1 -1
- package/schema-builder/util/ViewUtils.d.ts +7 -0
- package/schema-builder/util/ViewUtils.js +28 -0
- package/schema-builder/util/ViewUtils.js.map +1 -0
package/README.md
CHANGED
|
@@ -41,42 +41,42 @@ TypeORM is highly influenced by other ORMs, such as [Hibernate](http://hibernate
|
|
|
41
41
|
|
|
42
42
|
## Features
|
|
43
43
|
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* TypeScript and JavaScript support
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* CLI
|
|
44
|
+
* Supports both [DataMapper](./docs/active-record-data-mapper.md#what-is-the-data-mapper-pattern) and [ActiveRecord](./docs/active-record-data-mapper.md#what-is-the-active-record-pattern) (your choice).
|
|
45
|
+
* Entities and columns.
|
|
46
|
+
* Database-specific column types.
|
|
47
|
+
* Entity manager.
|
|
48
|
+
* Repositories and custom repositories.
|
|
49
|
+
* Clean object relational model.
|
|
50
|
+
* Associations (relations).
|
|
51
|
+
* Eager and lazy relations.
|
|
52
|
+
* Uni-directional, bi-directional and self-referenced relations.
|
|
53
|
+
* Supports multiple inheritance patterns.
|
|
54
|
+
* Cascades.
|
|
55
|
+
* Indices.
|
|
56
|
+
* Transactions.
|
|
57
|
+
* Migrations and automatic migrations generation.
|
|
58
|
+
* Connection pooling.
|
|
59
|
+
* Replication.
|
|
60
|
+
* Using multiple database connections.
|
|
61
|
+
* Working with multiple databases types.
|
|
62
|
+
* Cross-database and cross-schema queries.
|
|
63
|
+
* Elegant-syntax, flexible and powerful QueryBuilder.
|
|
64
|
+
* Left and inner joins.
|
|
65
|
+
* Proper pagination for queries using joins.
|
|
66
|
+
* Query caching.
|
|
67
|
+
* Streaming raw results.
|
|
68
|
+
* Logging.
|
|
69
|
+
* Listeners and subscribers (hooks).
|
|
70
|
+
* Supports closure table pattern.
|
|
71
|
+
* Schema declaration in models or separate configuration files.
|
|
72
|
+
* Connection configuration in json / xml / yml / env formats.
|
|
73
|
+
* Supports MySQL / MariaDB / Postgres / CockroachDB / SQLite / Microsoft SQL Server / Oracle / SAP Hana / sql.js.
|
|
74
|
+
* Supports MongoDB NoSQL database.
|
|
75
|
+
* Works in NodeJS / Browser / Ionic / Cordova / React Native / NativeScript / Expo / Electron platforms.
|
|
76
|
+
* TypeScript and JavaScript support.
|
|
77
|
+
* Produced code is performant, flexible, clean and maintainable.
|
|
78
|
+
* Follows all possible best practices.
|
|
79
|
+
* CLI.
|
|
80
80
|
|
|
81
81
|
And more...
|
|
82
82
|
|
|
@@ -215,7 +215,7 @@ await timber.remove();
|
|
|
215
215
|
npm i hdb-pool
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
*SAP Hana support made possible by sponsorship of [Neptune Software](https://www.neptune-software.com/).*
|
|
218
|
+
*SAP Hana support made possible by the sponsorship of [Neptune Software](https://www.neptune-software.com/).*
|
|
219
219
|
|
|
220
220
|
* for **MongoDB** (experimental)
|
|
221
221
|
|
|
@@ -327,7 +327,7 @@ creating more entities.
|
|
|
327
327
|
> You can generate an even more advanced project with express installed by running
|
|
328
328
|
`typeorm init --name MyProject --database mysql --express` command.
|
|
329
329
|
|
|
330
|
-
> You can generate docker-compose file by running
|
|
330
|
+
> You can generate a docker-compose file by running
|
|
331
331
|
`typeorm init --name MyProject --database postgres --docker` command.
|
|
332
332
|
|
|
333
333
|
## Step-by-Step Guide
|
|
@@ -336,7 +336,7 @@ What are you expecting from ORM?
|
|
|
336
336
|
First of all, you are expecting it will create database tables for you
|
|
337
337
|
and find / insert / update / delete your data without the pain of
|
|
338
338
|
having to write lots of hardly maintainable SQL queries.
|
|
339
|
-
This guide will show you how to
|
|
339
|
+
This guide will show you how to set up TypeORM from scratch and make it do what you are expecting from an ORM.
|
|
340
340
|
|
|
341
341
|
### Create a model
|
|
342
342
|
|
|
@@ -359,7 +359,7 @@ export class Photo {
|
|
|
359
359
|
```
|
|
360
360
|
|
|
361
361
|
And you want to store photos in your database.
|
|
362
|
-
To store things in the database, first you need a database table,
|
|
362
|
+
To store things in the database, first, you need a database table,
|
|
363
363
|
and database tables are created from your models.
|
|
364
364
|
Not all models, but only those you define as *entities*.
|
|
365
365
|
|
|
@@ -387,7 +387,7 @@ export class Photo {
|
|
|
387
387
|
```
|
|
388
388
|
|
|
389
389
|
Now, a database table will be created for the `Photo` entity and we'll be able to work with it anywhere in our app.
|
|
390
|
-
We have created a database table, however what table can exist without columns?
|
|
390
|
+
We have created a database table, however, what table can exist without columns?
|
|
391
391
|
Let's create a few columns in our database table.
|
|
392
392
|
|
|
393
393
|
### Adding table columns
|
|
@@ -433,7 +433,7 @@ Each database table must have a column with a primary key.
|
|
|
433
433
|
|
|
434
434
|
Each entity **must** have at least one primary key column.
|
|
435
435
|
This is a requirement and you can't avoid it.
|
|
436
|
-
To make a column a primary key, you need to use `@PrimaryColumn` decorator.
|
|
436
|
+
To make a column a primary key, you need to use the `@PrimaryColumn` decorator.
|
|
437
437
|
|
|
438
438
|
```javascript
|
|
439
439
|
import { Entity, Column, PrimaryColumn } from "typeorm";
|
|
@@ -461,7 +461,7 @@ export class Photo {
|
|
|
461
461
|
}
|
|
462
462
|
```
|
|
463
463
|
|
|
464
|
-
### Creating an auto
|
|
464
|
+
### Creating an auto-generated column
|
|
465
465
|
|
|
466
466
|
Now, let's say you want your id column to be auto-generated (this is known as auto-increment / sequence / serial / generated identity column).
|
|
467
467
|
To do that, you need to change the `@PrimaryColumn` decorator to a `@PrimaryGeneratedColumn` decorator:
|
|
@@ -494,8 +494,8 @@ export class Photo {
|
|
|
494
494
|
|
|
495
495
|
### Column data types
|
|
496
496
|
|
|
497
|
-
Next, let's fix our data types. By default, string is mapped to a varchar(255)-like type (depending on the database type).
|
|
498
|
-
|
|
497
|
+
Next, let's fix our data types. By default, the string is mapped to a varchar(255)-like type (depending on the database type).
|
|
498
|
+
The number is mapped to an integer-like type (depending on the database type).
|
|
499
499
|
We don't want all our columns to be limited varchars or integers.
|
|
500
500
|
Let's setup correct data types:
|
|
501
501
|
|
|
@@ -571,7 +571,7 @@ Setting `synchronize` makes sure your entities will be synced with the database,
|
|
|
571
571
|
### Loading all entities from the directory
|
|
572
572
|
|
|
573
573
|
Later, when we create more entities we need to add them to the entities in our configuration.
|
|
574
|
-
This is not very convenient, so instead we can set up the whole directory, from where all entities will be connected and used in our connection:
|
|
574
|
+
This is not very convenient, so instead, we can set up the whole directory, from where all entities will be connected and used in our connection:
|
|
575
575
|
|
|
576
576
|
```javascript
|
|
577
577
|
import { createConnection } from "typeorm";
|
|
@@ -594,14 +594,14 @@ createConnection({
|
|
|
594
594
|
|
|
595
595
|
But be careful with this approach.
|
|
596
596
|
If you are using `ts-node` then you need to specify paths to `.ts` files instead.
|
|
597
|
-
If you are using `outDir` then you'll need to specify paths to `.js` files inside outDir directory.
|
|
597
|
+
If you are using `outDir` then you'll need to specify paths to `.js` files inside the outDir directory.
|
|
598
598
|
If you are using `outDir` and when you remove or rename your entities make sure to clear `outDir` directory
|
|
599
599
|
and re-compile your project again, because when you remove your source `.ts` files their compiled `.js` versions
|
|
600
600
|
aren't removed from output directory and still are loaded by TypeORM because they are present in the `outDir` directory.
|
|
601
601
|
|
|
602
602
|
### Running the application
|
|
603
603
|
|
|
604
|
-
Now if you run your `index.ts`, a connection with database will be initialized and a database table for your photos will be created.
|
|
604
|
+
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.
|
|
605
605
|
|
|
606
606
|
|
|
607
607
|
```shell
|
|
@@ -801,7 +801,7 @@ Now photo with `id = 1` will be removed from the database.
|
|
|
801
801
|
|
|
802
802
|
### Creating a one-to-one relation
|
|
803
803
|
|
|
804
|
-
Let's create a one-to-one
|
|
804
|
+
Let's create a one-to-one relationship with another class.
|
|
805
805
|
Let's create a new class in `PhotoMetadata.ts`. This PhotoMetadata class is supposed to contain our photo's additional meta-information:
|
|
806
806
|
|
|
807
807
|
```javascript
|
|
@@ -901,7 +901,7 @@ createConnection(/*...*/).then(async connection => {
|
|
|
901
901
|
await metadataRepository.save(metadata);
|
|
902
902
|
|
|
903
903
|
// done
|
|
904
|
-
console.log("Metadata is saved, and relation between metadata and photo is created in the database too");
|
|
904
|
+
console.log("Metadata is saved, and the relation between metadata and photo is created in the database too");
|
|
905
905
|
|
|
906
906
|
}).catch(error => console.log(error));
|
|
907
907
|
```
|
|
@@ -949,7 +949,7 @@ Here we show that the metadata property of the Photo class is where we store Pho
|
|
|
949
949
|
Instead of passing a function that returns a property of the photo, you could alternatively simply pass a string to `@OneToOne` decorator, like `"metadata"`.
|
|
950
950
|
But we used this function-typed approach to make our refactoring easier.
|
|
951
951
|
|
|
952
|
-
Note that we should use `@JoinColumn` decorator only on one side of a relation.
|
|
952
|
+
Note that we should use the `@JoinColumn` decorator only on one side of a relation.
|
|
953
953
|
Whichever side you put this decorator on will be the owning side of the relationship.
|
|
954
954
|
The owning side of a relationship contains a column with a foreign key in the database.
|
|
955
955
|
|
|
@@ -998,14 +998,14 @@ createConnection(/*...*/).then(async connection => {
|
|
|
998
998
|
}).catch(error => console.log(error));
|
|
999
999
|
```
|
|
1000
1000
|
|
|
1001
|
-
`QueryBuilder` allows creation and execution of SQL queries of almost any complexity.
|
|
1001
|
+
`QueryBuilder` allows the creation and execution of SQL queries of almost any complexity.
|
|
1002
1002
|
When you work with `QueryBuilder`, think like you are creating an SQL query.
|
|
1003
1003
|
In this example, "photo" and "metadata" are aliases applied to selected photos.
|
|
1004
1004
|
You use aliases to access columns and properties of the selected data.
|
|
1005
1005
|
|
|
1006
1006
|
### Using cascades to automatically save related objects
|
|
1007
1007
|
|
|
1008
|
-
We can
|
|
1008
|
+
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.
|
|
1009
1009
|
Let's change our photo's `@OneToOne` decorator a bit:
|
|
1010
1010
|
|
|
1011
1011
|
```javascript
|
|
@@ -1057,7 +1057,7 @@ Notice that we now set the photo's `metadata` property, instead of the metadata'
|
|
|
1057
1057
|
|
|
1058
1058
|
### Creating a many-to-one / one-to-many relation
|
|
1059
1059
|
|
|
1060
|
-
Let's create a many-to-one
|
|
1060
|
+
Let's create a many-to-one/one-to-many relation.
|
|
1061
1061
|
Let's say a photo has one author, and each author can have many photos.
|
|
1062
1062
|
First, let's create an `Author` class:
|
|
1063
1063
|
|
|
@@ -1080,7 +1080,7 @@ export class Author {
|
|
|
1080
1080
|
```
|
|
1081
1081
|
|
|
1082
1082
|
`Author` contains an inverse side of a relation.
|
|
1083
|
-
`OneToMany` is always an inverse side of relation, and it can't exist without `ManyToOne` on the other side of the relation.
|
|
1083
|
+
`OneToMany` is always an inverse side of the relation, and it can't exist without `ManyToOne` on the other side of the relation.
|
|
1084
1084
|
|
|
1085
1085
|
Now let's add the owner side of the relation into the Photo entity:
|
|
1086
1086
|
|
|
@@ -1255,10 +1255,10 @@ let photos = await connection
|
|
|
1255
1255
|
```
|
|
1256
1256
|
|
|
1257
1257
|
This query selects all published photos with "My" or "Mishka" names.
|
|
1258
|
-
It will select results from position 5 (pagination offset)
|
|
1258
|
+
It will select results from position 5 (pagination offset)
|
|
1259
1259
|
and will select only 10 results (pagination limit).
|
|
1260
1260
|
The selection result will be ordered by id in descending order.
|
|
1261
|
-
The photo's albums will be left
|
|
1261
|
+
The photo's albums will be left joined and their metadata will be inner joined.
|
|
1262
1262
|
|
|
1263
1263
|
You'll use the query builder in your application a lot.
|
|
1264
1264
|
Learn more about QueryBuilder [here](./docs/select-query-builder.md).
|
|
@@ -1273,6 +1273,7 @@ There are a few repositories which you can clone and start with:
|
|
|
1273
1273
|
* [Example how to use TypeORM with JavaScript](https://github.com/typeorm/javascript-example)
|
|
1274
1274
|
* [Example how to use TypeORM with JavaScript and Babel](https://github.com/typeorm/babel-example)
|
|
1275
1275
|
* [Example how to use TypeORM with TypeScript and SystemJS in Browser](https://github.com/typeorm/browser-example)
|
|
1276
|
+
* [Example how to use TypeORM with TypeScript and React in Browser](https://github.com/ItayGarin/typeorm-react-swc)
|
|
1276
1277
|
* [Example how to use Express and TypeORM](https://github.com/typeorm/typescript-express-example)
|
|
1277
1278
|
* [Example how to use Koa and TypeORM](https://github.com/typeorm/typescript-koa-example)
|
|
1278
1279
|
* [Example how to use TypeORM with MongoDB](https://github.com/typeorm/mongo-typescript-example)
|
|
@@ -1306,12 +1307,12 @@ This project exists thanks to all the people who contribute:
|
|
|
1306
1307
|
|
|
1307
1308
|
## Sponsors
|
|
1308
1309
|
|
|
1309
|
-
Open source is hard and time-consuming. If you want to invest
|
|
1310
|
+
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)
|
|
1310
1311
|
|
|
1311
1312
|
<a href="https://opencollective.com/typeorm" target="_blank"><img src="https://opencollective.com/typeorm/tiers/sponsor.svg?width=890"></a>
|
|
1312
1313
|
|
|
1313
1314
|
## Gold Sponsors
|
|
1314
1315
|
|
|
1315
|
-
Become a gold sponsor and get
|
|
1316
|
+
Become a gold sponsor and get premium technical support from our core contributors. [Become a gold sponsor](https://opencollective.com/typeorm)
|
|
1316
1317
|
|
|
1317
1318
|
<a href="https://opencollective.com/typeorm" target="_blank"><img src="https://opencollective.com/typeorm/tiers/gold-sponsor.svg?width=890"></a>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __awaiter, __generator } from "tslib";
|
|
2
2
|
import appRootPath from "app-root-path";
|
|
3
|
+
import path from "path";
|
|
3
4
|
import { PlatformTools } from "../platform/PlatformTools";
|
|
4
5
|
import { ConnectionOptionsEnvReader } from "./options-reader/ConnectionOptionsEnvReader";
|
|
5
6
|
import { ConnectionOptionsYmlReader } from "./options-reader/ConnectionOptionsYmlReader";
|
|
@@ -206,7 +207,7 @@ var ConnectionOptionsReader = /** @class */ (function () {
|
|
|
206
207
|
* Gets directory where configuration file should be located and configuration file name.
|
|
207
208
|
*/
|
|
208
209
|
get: function () {
|
|
209
|
-
return this.baseDirectory
|
|
210
|
+
return path.resolve(this.baseDirectory, this.baseConfigName);
|
|
210
211
|
},
|
|
211
212
|
enumerable: false,
|
|
212
213
|
configurable: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;GAGG;AACH;IAEI,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,iCAAsB,OAWrB;QAXqB,YAAO,GAAP,OAAO,CAW5B;IACD,CAAC;IAED,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACG,qCAAG,GAAT;;;;;4BACoB,qBAAM,IAAI,CAAC,IAAI,EAAE,EAAA;;wBAA3B,OAAO,GAAG,SAAiB;wBACjC,IAAI,CAAC,OAAO;4BACR,MAAM,IAAI,YAAY,CAAC,kEAAkE,CAAC,CAAC;wBAE/F,sBA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,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,IAAK,gBAAgB;oBAC1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,mBAAmB;oBAC9D,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE;oBACjC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;wBACnB,QAAQ,EAAE,KAAI,CAAC,aAAa,GAAG,GAAG,GAAG,OAAO,CAAC,QAAQ;qBACxD,CAAC,CAAC;iBACN;aACJ;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,iBAAiB,CAAC;IAC7B,CAAC;IAKD,sBAAc,iDAAY;QAH1B;;WAEG;aACH;YACI,OAAO,IAAI,CAAC,aAAa,GAAG,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1D,CAAC;;;OAAA;IAKD,sBAAc,kDAAa;QAH3B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI;gBACjC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAE7B,OAAO,WAAW,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAKD,sBAAc,mDAAc;QAH5B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;gBACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAEnC,OAAO,WAAW,CAAC;QACvB,CAAC;;;OAAA;IAEL,8BAAC;AAAD,CA9MA,AA8MC,IAAA","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport {ConnectionOptionsEnvReader} from \"./options-reader/ConnectionOptionsEnvReader\";\nimport {ConnectionOptionsYmlReader} from \"./options-reader/ConnectionOptionsYmlReader\";\nimport {ConnectionOptionsXmlReader} from \"./options-reader/ConnectionOptionsXmlReader\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string,\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n }) {\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<ConnectionOptions[]> {\n const options = await this.load();\n if (!options)\n throw new TypeORMError(`No connection options were found in any orm configuration files.`);\n\n return options;\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<ConnectionOptions> {\n const allOptions = await this.all();\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n if (!targetOptions)\n throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);\n\n return targetOptions;\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load();\n if (!allOptions)\n return false;\n\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n return !!targetOptions;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<ConnectionOptions[]|undefined> {\n let connectionOptions: ConnectionOptions|ConnectionOptions[]|undefined = undefined;\n\n const fileFormats = [\"env\", \"js\", \"cjs\", \"ts\", \"json\", \"yml\", \"yaml\", \"xml\"];\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf(\".\"));\n const fileExtension = fileFormats.find(extension => `.${extension}` === possibleExtension);\n\n // try to find any of following configuration formats\n const foundFileFormat = fileExtension || fileFormats.find(format => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format);\n });\n\n // Determine config file name\n const configFile = fileExtension ? this.baseFilePath : this.baseFilePath + \".\" + foundFileFormat;\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile);\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\");\n }\n\n // try to find connection options from any of available sources of configuration\n if (PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") || PlatformTools.getEnvVariable(\"TYPEORM_URL\")) {\n connectionOptions = await new ConnectionOptionsEnvReader().read();\n\n } else if (foundFileFormat === \"js\" || foundFileFormat === \"cjs\" || foundFileFormat === \"ts\") {\n const configModule = await require(configFile);\n\n if (configModule && \"__esModule\" in configModule && \"default\" in configModule) {\n connectionOptions = configModule.default;\n } else {\n connectionOptions = configModule;\n }\n\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile);\n\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(configFile);\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions);\n }\n\n return undefined;\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(connectionOptions: ConnectionOptions|ConnectionOptions[]): ConnectionOptions[] {\n if (!(Array.isArray(connectionOptions)))\n connectionOptions = [connectionOptions];\n\n connectionOptions.forEach(options => {\n if (options.entities) {\n const entities = (options.entities as any[]).map(entity => {\n if (typeof entity === \"string\" && entity.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + entity;\n\n return entity;\n });\n Object.assign(connectionOptions, { entities: entities });\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(subscriber => {\n if (typeof subscriber === \"string\" && subscriber.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + subscriber;\n\n return subscriber;\n });\n Object.assign(connectionOptions, { subscribers: subscribers });\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(migration => {\n if (typeof migration === \"string\" && migration.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + migration;\n\n return migration;\n });\n Object.assign(connectionOptions, { migrations: migrations });\n }\n\n // make database path file in sqlite relative to package.json\n if (options.type === \"sqlite\" || options.type === \"better-sqlite3\") {\n if (typeof options.database === \"string\" &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\") {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database\n });\n }\n }\n });\n\n return connectionOptions;\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return this.baseDirectory + \"/\" + this.baseConfigName;\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root)\n return this.options.root;\n\n return appRootPath.path;\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName;\n\n return \"ormconfig\";\n }\n\n}\n"],"sourceRoot":".."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/connection/ConnectionOptionsReader.ts"],"names":[],"mappings":";AAAA,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAC,aAAa,EAAC,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAC,0BAA0B,EAAC,MAAM,6CAA6C,CAAC;AACvF,OA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AAO,CAAC,IAAI,CAAC;YAE7B,OAAO,WAAW,CAAC,IAAI,CAAC;QAC5B,CAAC;;;OAAA;IAKD,sBAAc,mDAAc;QAH5B;;WAEG;aACH;YACI,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,UAAU;gBACvC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YAEnC,OAAO,WAAW,CAAC;QACvB,CAAC;;;OAAA;IAEL,8BAAC;AAAD,CA9MA,AA8MC,IAAA","file":"ConnectionOptionsReader.js","sourcesContent":["import appRootPath from \"app-root-path\";\nimport path from \"path\";\nimport {ConnectionOptions} from \"./ConnectionOptions\";\nimport {PlatformTools} from \"../platform/PlatformTools\";\nimport {ConnectionOptionsEnvReader} from \"./options-reader/ConnectionOptionsEnvReader\";\nimport {ConnectionOptionsYmlReader} from \"./options-reader/ConnectionOptionsYmlReader\";\nimport {ConnectionOptionsXmlReader} from \"./options-reader/ConnectionOptionsXmlReader\";\nimport { TypeORMError } from \"../error\";\n\n/**\n * Reads connection options from the ormconfig.\n * Can read from multiple file extensions including env, json, js, xml and yml.\n */\nexport class ConnectionOptionsReader {\n\n // -------------------------------------------------------------------------\n // Constructor\n // -------------------------------------------------------------------------\n\n constructor(protected options?: {\n /**\n * Directory where ormconfig should be read from.\n * By default its your application root (where your app package.json is located).\n */\n root?: string,\n\n /**\n * Filename of the ormconfig configuration. By default its equal to \"ormconfig\".\n */\n configName?: string\n }) {\n }\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Returns all connection options read from the ormconfig.\n */\n async all(): Promise<ConnectionOptions[]> {\n const options = await this.load();\n if (!options)\n throw new TypeORMError(`No connection options were found in any orm configuration files.`);\n\n return options;\n }\n\n /**\n * Gets a connection with a given name read from ormconfig.\n * If connection with such name would not be found then it throw error.\n */\n async get(name: string): Promise<ConnectionOptions> {\n const allOptions = await this.all();\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n if (!targetOptions)\n throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);\n\n return targetOptions;\n }\n\n /**\n * Checks if there is a TypeORM configuration file.\n */\n async has(name: string): Promise<boolean> {\n const allOptions = await this.load();\n if (!allOptions)\n return false;\n\n const targetOptions = allOptions.find(options => options.name === name || (name === \"default\" && !options.name));\n return !!targetOptions;\n }\n\n // -------------------------------------------------------------------------\n // Protected Methods\n // -------------------------------------------------------------------------\n\n /**\n * Loads all connection options from a configuration file.\n *\n * todo: get in count NODE_ENV somehow\n */\n protected async load(): Promise<ConnectionOptions[]|undefined> {\n let connectionOptions: ConnectionOptions|ConnectionOptions[]|undefined = undefined;\n\n const fileFormats = [\"env\", \"js\", \"cjs\", \"ts\", \"json\", \"yml\", \"yaml\", \"xml\"];\n\n // Detect if baseFilePath contains file extension\n const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf(\".\"));\n const fileExtension = fileFormats.find(extension => `.${extension}` === possibleExtension);\n\n // try to find any of following configuration formats\n const foundFileFormat = fileExtension || fileFormats.find(format => {\n return PlatformTools.fileExist(this.baseFilePath + \".\" + format);\n });\n\n // Determine config file name\n const configFile = fileExtension ? this.baseFilePath : this.baseFilePath + \".\" + foundFileFormat;\n\n // if .env file found then load all its variables into process.env using dotenv package\n if (foundFileFormat === \"env\") {\n PlatformTools.dotenv(configFile);\n } else if (PlatformTools.fileExist(this.baseDirectory + \"/.env\")) {\n PlatformTools.dotenv(this.baseDirectory + \"/.env\");\n }\n\n // try to find connection options from any of available sources of configuration\n if (PlatformTools.getEnvVariable(\"TYPEORM_CONNECTION\") || PlatformTools.getEnvVariable(\"TYPEORM_URL\")) {\n connectionOptions = await new ConnectionOptionsEnvReader().read();\n\n } else if (foundFileFormat === \"js\" || foundFileFormat === \"cjs\" || foundFileFormat === \"ts\") {\n const configModule = await require(configFile);\n\n if (configModule && \"__esModule\" in configModule && \"default\" in configModule) {\n connectionOptions = configModule.default;\n } else {\n connectionOptions = configModule;\n }\n\n } else if (foundFileFormat === \"json\") {\n connectionOptions = require(configFile);\n\n } else if (foundFileFormat === \"yml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"yaml\") {\n connectionOptions = await new ConnectionOptionsYmlReader().read(configFile);\n\n } else if (foundFileFormat === \"xml\") {\n connectionOptions = await new ConnectionOptionsXmlReader().read(configFile);\n }\n\n // normalize and return connection options\n if (connectionOptions) {\n return this.normalizeConnectionOptions(connectionOptions);\n }\n\n return undefined;\n }\n\n /**\n * Normalize connection options.\n */\n protected normalizeConnectionOptions(connectionOptions: ConnectionOptions|ConnectionOptions[]): ConnectionOptions[] {\n if (!(Array.isArray(connectionOptions)))\n connectionOptions = [connectionOptions];\n\n connectionOptions.forEach(options => {\n if (options.entities) {\n const entities = (options.entities as any[]).map(entity => {\n if (typeof entity === \"string\" && entity.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + entity;\n\n return entity;\n });\n Object.assign(connectionOptions, { entities: entities });\n }\n if (options.subscribers) {\n const subscribers = (options.subscribers as any[]).map(subscriber => {\n if (typeof subscriber === \"string\" && subscriber.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + subscriber;\n\n return subscriber;\n });\n Object.assign(connectionOptions, { subscribers: subscribers });\n }\n if (options.migrations) {\n const migrations = (options.migrations as any[]).map(migration => {\n if (typeof migration === \"string\" && migration.substr(0, 1) !== \"/\")\n return this.baseDirectory + \"/\" + migration;\n\n return migration;\n });\n Object.assign(connectionOptions, { migrations: migrations });\n }\n\n // make database path file in sqlite relative to package.json\n if (options.type === \"sqlite\" || options.type === \"better-sqlite3\") {\n if (typeof options.database === \"string\" &&\n options.database.substr(0, 1) !== \"/\" && // unix absolute\n options.database.substr(1, 2) !== \":\\\\\" && // windows absolute\n options.database !== \":memory:\") {\n Object.assign(options, {\n database: this.baseDirectory + \"/\" + options.database\n });\n }\n }\n });\n\n return connectionOptions;\n }\n\n /**\n * Gets directory where configuration file should be located and configuration file name.\n */\n protected get baseFilePath(): string {\n return path.resolve(this.baseDirectory, this.baseConfigName);\n }\n\n /**\n * Gets directory where configuration file should be located.\n */\n protected get baseDirectory(): string {\n if (this.options && this.options.root)\n return this.options.root;\n\n return appRootPath.path;\n }\n\n /**\n * Gets configuration file name.\n */\n protected get baseConfigName(): string {\n if (this.options && this.options.configName)\n return this.options.configName;\n\n return \"ormconfig\";\n }\n\n}\n"],"sourceRoot":".."}
|
|
@@ -11,6 +11,7 @@ export function ViewEntity(nameOrOptions, maybeOptions) {
|
|
|
11
11
|
target: target,
|
|
12
12
|
name: name,
|
|
13
13
|
expression: options.expression,
|
|
14
|
+
dependsOn: options.dependsOn ? new Set(options.dependsOn) : undefined,
|
|
14
15
|
type: "view",
|
|
15
16
|
database: options.database ? options.database : undefined,
|
|
16
17
|
schema: options.schema ? options.schema : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/decorator/entity-view/ViewEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AAgBrD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,aAAwC,EAAE,YAAgC;IACjG,IAAM,OAAO,GAAG,CAAC,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAkC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAC9G,IAAM,IAAI,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAE9E,OAAO,UAAU,MAAgB;QAC7B,sBAAsB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACzD,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YACnD,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;YACzD,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY;SAClB,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC","file":"ViewEntity.js","sourcesContent":["import {getMetadataArgsStorage} from \"../../globals\";\nimport {TableMetadataArgs} from \"../../metadata-args/TableMetadataArgs\";\nimport {ViewEntityOptions} from \"../options/ViewEntityOptions\";\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(options?: ViewEntityOptions): ClassDecorator;\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(name?: string, options?: ViewEntityOptions): ClassDecorator;\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(nameOrOptions?: string|ViewEntityOptions, maybeOptions?: ViewEntityOptions): ClassDecorator {\n const options = (typeof nameOrOptions === \"object\" ? nameOrOptions as ViewEntityOptions : maybeOptions) || {};\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : options.name;\n\n return function (target: Function) {\n getMetadataArgsStorage().tables.push({\n target: target,\n name: name,\n expression: options.expression,\n type: \"view\",\n database: options.database ? options.database : undefined,\n schema: options.schema ? options.schema : undefined,\n synchronize: options.synchronize === false ? false : true,\n materialized: !!options.materialized\n } as TableMetadataArgs);\n };\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/decorator/entity-view/ViewEntity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AAgBrD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,aAAwC,EAAE,YAAgC;IACjG,IAAM,OAAO,GAAG,CAAC,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAkC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAC9G,IAAM,IAAI,GAAG,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAE9E,OAAO,UAAU,MAAgB;QAC7B,sBAAsB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;YACrE,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;YACzD,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YACnD,WAAW,EAAE,OAAO,CAAC,WAAW,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;YACzD,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY;SAClB,CAAC,CAAC;IAC5B,CAAC,CAAC;AACN,CAAC","file":"ViewEntity.js","sourcesContent":["import {getMetadataArgsStorage} from \"../../globals\";\nimport {TableMetadataArgs} from \"../../metadata-args/TableMetadataArgs\";\nimport {ViewEntityOptions} from \"../options/ViewEntityOptions\";\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(options?: ViewEntityOptions): ClassDecorator;\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(name?: string, options?: ViewEntityOptions): ClassDecorator;\n\n/**\n * This decorator is used to mark classes that will be an entity view.\n * Database schema will be created for all classes decorated with it, and Repository can be retrieved and used for it.\n */\nexport function ViewEntity(nameOrOptions?: string|ViewEntityOptions, maybeOptions?: ViewEntityOptions): ClassDecorator {\n const options = (typeof nameOrOptions === \"object\" ? nameOrOptions as ViewEntityOptions : maybeOptions) || {};\n const name = typeof nameOrOptions === \"string\" ? nameOrOptions : options.name;\n\n return function (target: Function) {\n getMetadataArgsStorage().tables.push({\n target: target,\n name: name,\n expression: options.expression,\n dependsOn: options.dependsOn ? new Set(options.dependsOn) : undefined,\n type: \"view\",\n database: options.database ? options.database : undefined,\n schema: options.schema ? options.schema : undefined,\n synchronize: options.synchronize === false ? false : true,\n materialized: !!options.materialized\n } as TableMetadataArgs);\n };\n}\n"],"sourceRoot":"../.."}
|
|
@@ -31,4 +31,9 @@ export interface ViewEntityOptions {
|
|
|
31
31
|
* It's supported by Postgres and Oracle.
|
|
32
32
|
*/
|
|
33
33
|
materialized?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* View dependencies. In case the view depends on another view it can be listed here
|
|
36
|
+
* to ensure correct order of view migrations.
|
|
37
|
+
*/
|
|
38
|
+
dependsOn?: (Function | string)[];
|
|
34
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/decorator/options/ViewEntityOptions.ts"],"names":[],"mappings":"","file":"ViewEntityOptions.js","sourcesContent":["/**\n * Describes all entity view's options.\n */\nimport {Connection, SelectQueryBuilder} from \"../..\";\n\nexport interface ViewEntityOptions {\n\n /**\n * View name.\n * If not specified then naming strategy will generate view name from class name.\n */\n name?: string;\n\n /**\n * View expression.\n */\n expression?: string|((connection: Connection) => SelectQueryBuilder<any>);\n\n /**\n * Database name. Used in Mysql and Sql Server.\n */\n database?: string;\n\n /**\n * Schema name. Used in Postgres and Sql Server.\n */\n schema?: string;\n\n /**\n * Indicates if schema synchronization is enabled or disabled for this entity.\n * If it will be set to false then schema sync will and migrations ignore this entity.\n * By default schema synchronization is enabled for all entities.\n */\n synchronize?: boolean;\n\n /**\n * Indicates if view should be materialized view.\n * It's supported by Postgres and Oracle.\n */\n materialized?: boolean;\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/decorator/options/ViewEntityOptions.ts"],"names":[],"mappings":"","file":"ViewEntityOptions.js","sourcesContent":["/**\n * Describes all entity view's options.\n */\nimport {Connection, SelectQueryBuilder} from \"../..\";\n\nexport interface ViewEntityOptions {\n\n /**\n * View name.\n * If not specified then naming strategy will generate view name from class name.\n */\n name?: string;\n\n /**\n * View expression.\n */\n expression?: string|((connection: Connection) => SelectQueryBuilder<any>);\n\n /**\n * Database name. Used in Mysql and Sql Server.\n */\n database?: string;\n\n /**\n * Schema name. Used in Postgres and Sql Server.\n */\n schema?: string;\n\n /**\n * Indicates if schema synchronization is enabled or disabled for this entity.\n * If it will be set to false then schema sync will and migrations ignore this entity.\n * By default schema synchronization is enabled for all entities.\n */\n synchronize?: boolean;\n\n /**\n * Indicates if view should be materialized view.\n * It's supported by Postgres and Oracle.\n */\n materialized?: boolean;\n\n /**\n * View dependencies. In case the view depends on another view it can be listed here\n * to ensure correct order of view migrations.\n */\n dependsOn?: (Function|string)[];\n}\n"],"sourceRoot":"../.."}
|
|
@@ -14,6 +14,11 @@ export interface AuroraDataApiConnectionOptions extends BaseConnectionOptions, A
|
|
|
14
14
|
readonly secretArn: string;
|
|
15
15
|
readonly resourceArn: string;
|
|
16
16
|
readonly database: string;
|
|
17
|
+
/**
|
|
18
|
+
* The driver object
|
|
19
|
+
* This defaults to require("typeorm-aurora-data-api-driver")
|
|
20
|
+
*/
|
|
21
|
+
readonly driver?: any;
|
|
17
22
|
readonly serviceConfigOptions?: {
|
|
18
23
|
[key: string]: any;
|
|
19
24
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../browser/src/driver/aurora-data-api/AuroraDataApiConnectionOptions.ts"],"names":[],"mappings":"","file":"AuroraDataApiConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\nimport {AuroraDataApiConnectionCredentialsOptions} from \"./AuroraDataApiConnectionCredentialsOptions\";\n\n/**\n * MySQL specific connection options.\n *\n * @see https://github.com/mysqljs/mysql#connection-options\n */\nexport interface AuroraDataApiConnectionOptions extends BaseConnectionOptions, AuroraDataApiConnectionCredentialsOptions {\n\n /**\n * Database type.\n */\n readonly type: \"aurora-data-api\";\n\n readonly region: string;\n\n readonly secretArn: string;\n\n readonly resourceArn: string;\n\n readonly database: string;\n\n readonly serviceConfigOptions?: { [key: string]: any }; // pass optional AWS.ConfigurationOptions here\n\n readonly formatOptions?: { [key: string]: any, castParameters: boolean };\n\n /**\n * Use spatial functions like GeomFromText and AsText which are removed in MySQL 8.\n * (Default: true)\n */\n readonly legacySpatialSupport?: boolean;\n}\n"],"sourceRoot":"../.."}
|
|
1
|
+
{"version":3,"sources":["../browser/src/driver/aurora-data-api/AuroraDataApiConnectionOptions.ts"],"names":[],"mappings":"","file":"AuroraDataApiConnectionOptions.js","sourcesContent":["import {BaseConnectionOptions} from \"../../connection/BaseConnectionOptions\";\nimport {AuroraDataApiConnectionCredentialsOptions} from \"./AuroraDataApiConnectionCredentialsOptions\";\n\n/**\n * MySQL specific connection options.\n *\n * @see https://github.com/mysqljs/mysql#connection-options\n */\nexport interface AuroraDataApiConnectionOptions extends BaseConnectionOptions, AuroraDataApiConnectionCredentialsOptions {\n\n /**\n * Database type.\n */\n readonly type: \"aurora-data-api\";\n\n readonly region: string;\n\n readonly secretArn: string;\n\n readonly resourceArn: string;\n\n readonly database: string;\n\n /**\n * The driver object\n * This defaults to require(\"typeorm-aurora-data-api-driver\")\n */\n readonly driver?: any;\n\n readonly serviceConfigOptions?: { [key: string]: any }; // pass optional AWS.ConfigurationOptions here\n\n readonly formatOptions?: { [key: string]: any, castParameters: boolean };\n\n /**\n * Use spatial functions like GeomFromText and AsText which are removed in MySQL 8.\n * (Default: true)\n */\n readonly legacySpatialSupport?: boolean;\n}\n"],"sourceRoot":"../.."}
|
|
@@ -356,7 +356,7 @@ var AuroraDataApiDriver = /** @class */ (function () {
|
|
|
356
356
|
if (database) {
|
|
357
357
|
tablePath.unshift(database);
|
|
358
358
|
}
|
|
359
|
-
return tablePath.join(
|
|
359
|
+
return tablePath.join(".");
|
|
360
360
|
};
|
|
361
361
|
/**
|
|
362
362
|
* Parse a target table name or other types and return a normalized table definition.
|
|
@@ -745,7 +745,8 @@ var AuroraDataApiDriver = /** @class */ (function () {
|
|
|
745
745
|
* Loads all driver dependencies.
|
|
746
746
|
*/
|
|
747
747
|
AuroraDataApiDriver.prototype.loadDependencies = function () {
|
|
748
|
-
|
|
748
|
+
var DataApiDriver = this.options.driver || PlatformTools.load("typeorm-aurora-data-api-driver");
|
|
749
|
+
this.DataApiDriver = DataApiDriver;
|
|
749
750
|
// Driver uses rollup for publishing, which has issues when using typeorm in combination with webpack
|
|
750
751
|
// See https://github.com/webpack/webpack/issues/4742#issuecomment-295556787
|
|
751
752
|
this.DataApiDriver = this.DataApiDriver.default || this.DataApiDriver;
|
|
@@ -786,9 +787,9 @@ var AuroraDataApiDriver = /** @class */ (function () {
|
|
|
786
787
|
*/
|
|
787
788
|
AuroraDataApiDriver.prototype.prepareDbConnection = function (connection) {
|
|
788
789
|
var logger = this.connection.logger;
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
790
|
+
/**
|
|
791
|
+
* Attaching an error handler to connection errors is essential, as, otherwise, errors raised will go unhandled and
|
|
792
|
+
* cause the hosting app to crash.
|
|
792
793
|
*/
|
|
793
794
|
if (connection.listeners("error").length === 0) {
|
|
794
795
|
connection.on("error", function (error) { return logger.log("warn", "MySQL connection raised an error. " + error); });
|