@lakutata/orm 0.0.0-stage → 3.0.0-beta.0

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 (209) hide show
  1. package/LICENSE +23 -0
  2. package/README.md +463 -2
  3. package/THIRD_PARTY_NOTICES.md +36 -0
  4. package/dist/cjs/components/Database.d.ts +333 -0
  5. package/dist/cjs/components/Database.js +381 -0
  6. package/dist/cjs/decorators/orm/AfterInsert.d.ts +1 -0
  7. package/dist/cjs/decorators/orm/AfterInsert.js +5 -0
  8. package/dist/cjs/decorators/orm/AfterLoad.d.ts +1 -0
  9. package/dist/cjs/decorators/orm/AfterLoad.js +5 -0
  10. package/dist/cjs/decorators/orm/AfterRecover.d.ts +1 -0
  11. package/dist/cjs/decorators/orm/AfterRecover.js +5 -0
  12. package/dist/cjs/decorators/orm/AfterRemove.d.ts +1 -0
  13. package/dist/cjs/decorators/orm/AfterRemove.js +5 -0
  14. package/dist/cjs/decorators/orm/AfterSoftRemove.d.ts +1 -0
  15. package/dist/cjs/decorators/orm/AfterSoftRemove.js +5 -0
  16. package/dist/cjs/decorators/orm/AfterUpdate.d.ts +1 -0
  17. package/dist/cjs/decorators/orm/AfterUpdate.js +5 -0
  18. package/dist/cjs/decorators/orm/BeforeInsert.d.ts +1 -0
  19. package/dist/cjs/decorators/orm/BeforeInsert.js +5 -0
  20. package/dist/cjs/decorators/orm/BeforeRecover.d.ts +1 -0
  21. package/dist/cjs/decorators/orm/BeforeRecover.js +5 -0
  22. package/dist/cjs/decorators/orm/BeforeRemove.d.ts +1 -0
  23. package/dist/cjs/decorators/orm/BeforeRemove.js +5 -0
  24. package/dist/cjs/decorators/orm/BeforeSoftRemove.d.ts +1 -0
  25. package/dist/cjs/decorators/orm/BeforeSoftRemove.js +5 -0
  26. package/dist/cjs/decorators/orm/BeforeUpdate.d.ts +1 -0
  27. package/dist/cjs/decorators/orm/BeforeUpdate.js +5 -0
  28. package/dist/cjs/decorators/orm/Check.d.ts +1 -0
  29. package/dist/cjs/decorators/orm/Check.js +5 -0
  30. package/dist/cjs/decorators/orm/ChildEntity.d.ts +1 -0
  31. package/dist/cjs/decorators/orm/ChildEntity.js +5 -0
  32. package/dist/cjs/decorators/orm/Column.d.ts +1 -0
  33. package/dist/cjs/decorators/orm/Column.js +5 -0
  34. package/dist/cjs/decorators/orm/CreateDateColumn.d.ts +1 -0
  35. package/dist/cjs/decorators/orm/CreateDateColumn.js +5 -0
  36. package/dist/cjs/decorators/orm/DeleteDateColumn.d.ts +1 -0
  37. package/dist/cjs/decorators/orm/DeleteDateColumn.js +5 -0
  38. package/dist/cjs/decorators/orm/Entity.d.ts +1 -0
  39. package/dist/cjs/decorators/orm/Entity.js +5 -0
  40. package/dist/cjs/decorators/orm/EventSubscriber.d.ts +1 -0
  41. package/dist/cjs/decorators/orm/EventSubscriber.js +5 -0
  42. package/dist/cjs/decorators/orm/Exclusion.d.ts +1 -0
  43. package/dist/cjs/decorators/orm/Exclusion.js +5 -0
  44. package/dist/cjs/decorators/orm/Generated.d.ts +1 -0
  45. package/dist/cjs/decorators/orm/Generated.js +5 -0
  46. package/dist/cjs/decorators/orm/Index.d.ts +1 -0
  47. package/dist/cjs/decorators/orm/Index.js +5 -0
  48. package/dist/cjs/decorators/orm/JoinColumn.d.ts +1 -0
  49. package/dist/cjs/decorators/orm/JoinColumn.js +5 -0
  50. package/dist/cjs/decorators/orm/JoinTable.d.ts +1 -0
  51. package/dist/cjs/decorators/orm/JoinTable.js +5 -0
  52. package/dist/cjs/decorators/orm/ManyToMany.d.ts +1 -0
  53. package/dist/cjs/decorators/orm/ManyToMany.js +5 -0
  54. package/dist/cjs/decorators/orm/ManyToOne.d.ts +1 -0
  55. package/dist/cjs/decorators/orm/ManyToOne.js +5 -0
  56. package/dist/cjs/decorators/orm/ObjectIdColumn.d.ts +1 -0
  57. package/dist/cjs/decorators/orm/ObjectIdColumn.js +5 -0
  58. package/dist/cjs/decorators/orm/OneToMany.d.ts +1 -0
  59. package/dist/cjs/decorators/orm/OneToMany.js +5 -0
  60. package/dist/cjs/decorators/orm/OneToOne.d.ts +1 -0
  61. package/dist/cjs/decorators/orm/OneToOne.js +5 -0
  62. package/dist/cjs/decorators/orm/PrimaryColumn.d.ts +1 -0
  63. package/dist/cjs/decorators/orm/PrimaryColumn.js +5 -0
  64. package/dist/cjs/decorators/orm/PrimaryGeneratedColumn.d.ts +1 -0
  65. package/dist/cjs/decorators/orm/PrimaryGeneratedColumn.js +5 -0
  66. package/dist/cjs/decorators/orm/RelationId.d.ts +1 -0
  67. package/dist/cjs/decorators/orm/RelationId.js +5 -0
  68. package/dist/cjs/decorators/orm/TableInheritance.d.ts +1 -0
  69. package/dist/cjs/decorators/orm/TableInheritance.js +5 -0
  70. package/dist/cjs/decorators/orm/Tree.d.ts +1 -0
  71. package/dist/cjs/decorators/orm/Tree.js +5 -0
  72. package/dist/cjs/decorators/orm/TreeChildren.d.ts +1 -0
  73. package/dist/cjs/decorators/orm/TreeChildren.js +5 -0
  74. package/dist/cjs/decorators/orm/TreeLevelColumn.d.ts +1 -0
  75. package/dist/cjs/decorators/orm/TreeLevelColumn.js +5 -0
  76. package/dist/cjs/decorators/orm/TreeParent.d.ts +1 -0
  77. package/dist/cjs/decorators/orm/TreeParent.js +5 -0
  78. package/dist/cjs/decorators/orm/Unique.d.ts +1 -0
  79. package/dist/cjs/decorators/orm/Unique.js +5 -0
  80. package/dist/cjs/decorators/orm/UpdateDateColumn.d.ts +1 -0
  81. package/dist/cjs/decorators/orm/UpdateDateColumn.js +5 -0
  82. package/dist/cjs/decorators/orm/VersionColumn.d.ts +1 -0
  83. package/dist/cjs/decorators/orm/VersionColumn.js +5 -0
  84. package/dist/cjs/decorators/orm/ViewColumn.d.ts +1 -0
  85. package/dist/cjs/decorators/orm/ViewColumn.js +5 -0
  86. package/dist/cjs/decorators/orm/ViewEntity.d.ts +1 -0
  87. package/dist/cjs/decorators/orm/ViewEntity.js +5 -0
  88. package/dist/cjs/decorators/orm/VirtualColumn.d.ts +1 -0
  89. package/dist/cjs/decorators/orm/VirtualColumn.js +5 -0
  90. package/dist/cjs/exports/DatabaseComponent.d.ts +3 -0
  91. package/dist/cjs/exports/DatabaseComponent.js +21 -0
  92. package/dist/cjs/exports/DatabaseProvider.d.ts +3 -0
  93. package/dist/cjs/exports/DatabaseProvider.js +21 -0
  94. package/dist/cjs/exports/ORM.d.ts +193 -0
  95. package/dist/cjs/exports/ORM.js +166 -0
  96. package/dist/cjs/exports/ORMDecorators.d.ts +43 -0
  97. package/dist/cjs/exports/ORMDecorators.js +91 -0
  98. package/dist/cjs/package.json +1 -0
  99. package/dist/cjs/providers/Database.d.ts +326 -0
  100. package/dist/cjs/providers/Database.js +376 -0
  101. package/dist/cjs/providers/migration/ExecuteMigration.d.ts +40 -0
  102. package/dist/cjs/providers/migration/ExecuteMigration.js +143 -0
  103. package/dist/cjs/providers/migration/GenerateMigration.d.ts +59 -0
  104. package/dist/cjs/providers/migration/GenerateMigration.js +303 -0
  105. package/dist/cjs/types/MigrationRunOptions.d.ts +19 -0
  106. package/dist/cjs/types/MigrationRunOptions.js +2 -0
  107. package/dist/esm/components/Database.js +344 -0
  108. package/dist/esm/decorators/orm/AfterInsert.js +1 -0
  109. package/dist/esm/decorators/orm/AfterLoad.js +1 -0
  110. package/dist/esm/decorators/orm/AfterRecover.js +1 -0
  111. package/dist/esm/decorators/orm/AfterRemove.js +1 -0
  112. package/dist/esm/decorators/orm/AfterSoftRemove.js +1 -0
  113. package/dist/esm/decorators/orm/AfterUpdate.js +1 -0
  114. package/dist/esm/decorators/orm/BeforeInsert.js +1 -0
  115. package/dist/esm/decorators/orm/BeforeRecover.js +1 -0
  116. package/dist/esm/decorators/orm/BeforeRemove.js +1 -0
  117. package/dist/esm/decorators/orm/BeforeSoftRemove.js +1 -0
  118. package/dist/esm/decorators/orm/BeforeUpdate.js +1 -0
  119. package/dist/esm/decorators/orm/Check.js +1 -0
  120. package/dist/esm/decorators/orm/ChildEntity.js +1 -0
  121. package/dist/esm/decorators/orm/Column.js +1 -0
  122. package/dist/esm/decorators/orm/CreateDateColumn.js +1 -0
  123. package/dist/esm/decorators/orm/DeleteDateColumn.js +1 -0
  124. package/dist/esm/decorators/orm/Entity.js +1 -0
  125. package/dist/esm/decorators/orm/EventSubscriber.js +1 -0
  126. package/dist/esm/decorators/orm/Exclusion.js +1 -0
  127. package/dist/esm/decorators/orm/Generated.js +1 -0
  128. package/dist/esm/decorators/orm/Index.js +1 -0
  129. package/dist/esm/decorators/orm/JoinColumn.js +1 -0
  130. package/dist/esm/decorators/orm/JoinTable.js +1 -0
  131. package/dist/esm/decorators/orm/ManyToMany.js +1 -0
  132. package/dist/esm/decorators/orm/ManyToOne.js +1 -0
  133. package/dist/esm/decorators/orm/ObjectIdColumn.js +1 -0
  134. package/dist/esm/decorators/orm/OneToMany.js +1 -0
  135. package/dist/esm/decorators/orm/OneToOne.js +1 -0
  136. package/dist/esm/decorators/orm/PrimaryColumn.js +1 -0
  137. package/dist/esm/decorators/orm/PrimaryGeneratedColumn.js +1 -0
  138. package/dist/esm/decorators/orm/RelationId.js +1 -0
  139. package/dist/esm/decorators/orm/TableInheritance.js +1 -0
  140. package/dist/esm/decorators/orm/Tree.js +1 -0
  141. package/dist/esm/decorators/orm/TreeChildren.js +1 -0
  142. package/dist/esm/decorators/orm/TreeLevelColumn.js +1 -0
  143. package/dist/esm/decorators/orm/TreeParent.js +1 -0
  144. package/dist/esm/decorators/orm/Unique.js +1 -0
  145. package/dist/esm/decorators/orm/UpdateDateColumn.js +1 -0
  146. package/dist/esm/decorators/orm/VersionColumn.js +1 -0
  147. package/dist/esm/decorators/orm/ViewColumn.js +1 -0
  148. package/dist/esm/decorators/orm/ViewEntity.js +1 -0
  149. package/dist/esm/decorators/orm/VirtualColumn.js +1 -0
  150. package/dist/esm/exports/DatabaseComponent.js +2 -0
  151. package/dist/esm/exports/DatabaseProvider.js +2 -0
  152. package/dist/esm/exports/ORM.js +120 -0
  153. package/dist/esm/exports/ORMDecorators.js +43 -0
  154. package/dist/esm/providers/Database.js +339 -0
  155. package/dist/esm/providers/migration/ExecuteMigration.js +137 -0
  156. package/dist/esm/providers/migration/GenerateMigration.js +297 -0
  157. package/dist/esm/types/MigrationRunOptions.js +1 -0
  158. package/dist/types/components/Database.d.ts +333 -0
  159. package/dist/types/decorators/orm/AfterInsert.d.ts +1 -0
  160. package/dist/types/decorators/orm/AfterLoad.d.ts +1 -0
  161. package/dist/types/decorators/orm/AfterRecover.d.ts +1 -0
  162. package/dist/types/decorators/orm/AfterRemove.d.ts +1 -0
  163. package/dist/types/decorators/orm/AfterSoftRemove.d.ts +1 -0
  164. package/dist/types/decorators/orm/AfterUpdate.d.ts +1 -0
  165. package/dist/types/decorators/orm/BeforeInsert.d.ts +1 -0
  166. package/dist/types/decorators/orm/BeforeRecover.d.ts +1 -0
  167. package/dist/types/decorators/orm/BeforeRemove.d.ts +1 -0
  168. package/dist/types/decorators/orm/BeforeSoftRemove.d.ts +1 -0
  169. package/dist/types/decorators/orm/BeforeUpdate.d.ts +1 -0
  170. package/dist/types/decorators/orm/Check.d.ts +1 -0
  171. package/dist/types/decorators/orm/ChildEntity.d.ts +1 -0
  172. package/dist/types/decorators/orm/Column.d.ts +1 -0
  173. package/dist/types/decorators/orm/CreateDateColumn.d.ts +1 -0
  174. package/dist/types/decorators/orm/DeleteDateColumn.d.ts +1 -0
  175. package/dist/types/decorators/orm/Entity.d.ts +1 -0
  176. package/dist/types/decorators/orm/EventSubscriber.d.ts +1 -0
  177. package/dist/types/decorators/orm/Exclusion.d.ts +1 -0
  178. package/dist/types/decorators/orm/Generated.d.ts +1 -0
  179. package/dist/types/decorators/orm/Index.d.ts +1 -0
  180. package/dist/types/decorators/orm/JoinColumn.d.ts +1 -0
  181. package/dist/types/decorators/orm/JoinTable.d.ts +1 -0
  182. package/dist/types/decorators/orm/ManyToMany.d.ts +1 -0
  183. package/dist/types/decorators/orm/ManyToOne.d.ts +1 -0
  184. package/dist/types/decorators/orm/ObjectIdColumn.d.ts +1 -0
  185. package/dist/types/decorators/orm/OneToMany.d.ts +1 -0
  186. package/dist/types/decorators/orm/OneToOne.d.ts +1 -0
  187. package/dist/types/decorators/orm/PrimaryColumn.d.ts +1 -0
  188. package/dist/types/decorators/orm/PrimaryGeneratedColumn.d.ts +1 -0
  189. package/dist/types/decorators/orm/RelationId.d.ts +1 -0
  190. package/dist/types/decorators/orm/TableInheritance.d.ts +1 -0
  191. package/dist/types/decorators/orm/Tree.d.ts +1 -0
  192. package/dist/types/decorators/orm/TreeChildren.d.ts +1 -0
  193. package/dist/types/decorators/orm/TreeLevelColumn.d.ts +1 -0
  194. package/dist/types/decorators/orm/TreeParent.d.ts +1 -0
  195. package/dist/types/decorators/orm/Unique.d.ts +1 -0
  196. package/dist/types/decorators/orm/UpdateDateColumn.d.ts +1 -0
  197. package/dist/types/decorators/orm/VersionColumn.d.ts +1 -0
  198. package/dist/types/decorators/orm/ViewColumn.d.ts +1 -0
  199. package/dist/types/decorators/orm/ViewEntity.d.ts +1 -0
  200. package/dist/types/decorators/orm/VirtualColumn.d.ts +1 -0
  201. package/dist/types/exports/DatabaseComponent.d.ts +3 -0
  202. package/dist/types/exports/DatabaseProvider.d.ts +3 -0
  203. package/dist/types/exports/ORM.d.ts +193 -0
  204. package/dist/types/exports/ORMDecorators.d.ts +43 -0
  205. package/dist/types/providers/Database.d.ts +326 -0
  206. package/dist/types/providers/migration/ExecuteMigration.d.ts +40 -0
  207. package/dist/types/providers/migration/GenerateMigration.d.ts +59 -0
  208. package/dist/types/types/MigrationRunOptions.d.ts +19 -0
  209. package/package.json +81 -4
@@ -0,0 +1,333 @@
1
+ import { Component, Provider } from '@lakutata/core';
2
+ import { type DataSourceOptions } from 'typeorm/data-source/DataSourceOptions.js';
3
+ import { DataSource } from 'typeorm/data-source/DataSource.js';
4
+ import { Driver } from 'typeorm/driver/Driver.js';
5
+ import { EntityManager } from 'typeorm/entity-manager/EntityManager.js';
6
+ import { NamingStrategyInterface } from 'typeorm/naming-strategy/NamingStrategyInterface.js';
7
+ import { EntitySubscriberInterface } from 'typeorm/subscriber/EntitySubscriberInterface.js';
8
+ import { EntityMetadata } from 'typeorm/metadata/EntityMetadata.js';
9
+ import { EntityTarget } from 'typeorm/common/EntityTarget.js';
10
+ import { Migration } from 'typeorm/migration/Migration.js';
11
+ import { ObjectLiteral } from 'typeorm/common/ObjectLiteral.js';
12
+ import { TreeRepository } from 'typeorm/repository/TreeRepository.js';
13
+ import { Repository } from 'typeorm/repository/Repository.js';
14
+ import { MongoRepository } from 'typeorm/repository/MongoRepository.js';
15
+ import { QueryRunner } from 'typeorm/query-runner/QueryRunner.js';
16
+ import { SelectQueryBuilder } from 'typeorm/query-builder/SelectQueryBuilder.js';
17
+ import { ReplicationMode } from 'typeorm/driver/types/ReplicationMode.js';
18
+ import { QueryResultCache } from 'typeorm/cache/QueryResultCache.js';
19
+ import { IsolationLevel } from 'typeorm/driver/types/IsolationLevel.js';
20
+ import { type MigrationRunOptions } from '../types/MigrationRunOptions.js';
21
+ /**
22
+ * Build the registration of a {@link Database} component, for the `components` of the application options: the
23
+ * component class with its TypeORM connection options.
24
+ * @param options The TypeORM connection options (`DataSourceOptions`): the driver `type`, the connection settings, the
25
+ * `entities`, the `migrations`, `synchronize`, `migrationsRun`, `logging`… Passed to TypeORM as they are.
26
+ * @returns The registration `{class: Database, options}`.
27
+ * @example
28
+ * ```typescript
29
+ * import {Application} from 'lakutata'
30
+ * import {buildDatabaseOptions} from 'lakutata/com/database'
31
+ * import {Column, Entity, PrimaryGeneratedColumn} from 'lakutata/decorator/orm'
32
+ *
33
+ * @Entity()
34
+ * class User {
35
+ * @PrimaryGeneratedColumn()
36
+ * public id: number
37
+ *
38
+ * @Column()
39
+ * public name: string
40
+ * }
41
+ *
42
+ * Application.run(() => ({
43
+ * id: 'com.example.app',
44
+ * name: 'Example',
45
+ * components: {
46
+ * //A PostgreSQL connection (the pg package installed), the component named db
47
+ * db: buildDatabaseOptions({
48
+ * type: 'postgres',
49
+ * host: 'localhost',
50
+ * port: 5432,
51
+ * username: 'postgres',
52
+ * password: 'secret',
53
+ * database: 'example',
54
+ * entities: [User]
55
+ * })
56
+ * },
57
+ * //Connected while the application launches: a connection failure stops it
58
+ * bootstrap: ['db']
59
+ * }))
60
+ * ```
61
+ */
62
+ export declare const buildDatabaseOptions: (options: DataSourceOptions) => {
63
+ class: typeof Database;
64
+ options: DataSourceOptions;
65
+ };
66
+ /**
67
+ * A database connection shared by the whole application: a singleton component wrapping a TypeORM `DataSource`.
68
+ *
69
+ * Register it in the `components` of the application options with {@link buildDatabaseOptions}, then inject it by its
70
+ * name (`@Inject('db')`) or get it with `getObject('db')`. It connects when it is created (while the application
71
+ * launches when it is listed in `bootstrap`, otherwise on its first use): a connection failure rejects its creation
72
+ * with the driver error. TypeORM applies `synchronize` and `migrationsRun` of the options while connecting. It
73
+ * disconnects when the application stops.
74
+ *
75
+ * An application may register several of them (one per database), each under its own name. Their names are the ones
76
+ * the migration commands of the application (`MIGRATION_GENERATE`, `MIGRATION_RUN`…) select with `MIGRATION_DATABASE`.
77
+ * @example
78
+ * ```typescript
79
+ * import {Application, Component} from 'lakutata'
80
+ * import {Inject} from 'lakutata/decorator/di'
81
+ * import {buildDatabaseOptions, Database} from 'lakutata/com/database'
82
+ * import {Column, Entity, PrimaryGeneratedColumn} from 'lakutata/decorator/orm'
83
+ *
84
+ * @Entity()
85
+ * class Account {
86
+ * @PrimaryGeneratedColumn()
87
+ * public id: number
88
+ *
89
+ * @Column('integer', {default: 0})
90
+ * public balance: number
91
+ * }
92
+ *
93
+ * class Bank extends Component {
94
+ * @Inject('db')
95
+ * protected readonly db: Database
96
+ *
97
+ * public async balance(id: number): Promise<number> {
98
+ * const account: Account | null = await this.db.getRepository(Account).findOneBy({id: id})
99
+ * return account ? account.balance : 0
100
+ * }
101
+ *
102
+ * //Both updates are committed, or none when one fails
103
+ * public async transfer(from: number, to: number, amount: number): Promise<void> {
104
+ * await this.db.transaction(async (manager): Promise<void> => {
105
+ * await manager.decrement(Account, {id: from}, 'balance', amount)
106
+ * await manager.increment(Account, {id: to}, 'balance', amount)
107
+ * })
108
+ * }
109
+ * }
110
+ *
111
+ * Application.run(() => ({
112
+ * id: 'com.example.bank',
113
+ * name: 'Bank',
114
+ * components: {
115
+ * db: buildDatabaseOptions({type: 'postgres', url: 'postgres://postgres:secret@localhost:5432/bank', entities: [Account]}),
116
+ * bank: {class: Bank}
117
+ * },
118
+ * bootstrap: ['db']
119
+ * }))
120
+ * ```
121
+ */
122
+ export declare class Database extends Component {
123
+ #private;
124
+ /**
125
+ * Load the provider generating the migrations of the database. The application calls it when it is started with
126
+ * `MIGRATION_GENERATE`: the applications do not call it.
127
+ * @returns The migration generator provider class.
128
+ */
129
+ static migrationGenerator: () => Promise<typeof Provider>;
130
+ /**
131
+ * Load the provider running, reverting or showing the migrations of the database. The application calls it when it
132
+ * is started with `MIGRATION_RUN`, `MIGRATION_REVERT` or `MIGRATION_SHOW`: the applications do not call it.
133
+ * @returns The migration executor provider class.
134
+ */
135
+ static migrationExecutor: () => Promise<typeof Provider>;
136
+ /**
137
+ * The TypeORM connection options, given by the registration (see {@link buildDatabaseOptions}). Not validated by
138
+ * lakutata: TypeORM checks them while connecting.
139
+ */
140
+ protected readonly options: DataSourceOptions;
141
+ /**
142
+ * The TypeORM `DataSource` of the connection, for the subclasses needing what this class does not expose.
143
+ */
144
+ protected get datasource(): DataSource;
145
+ /**
146
+ * The TypeORM driver of the connection (PostgreSQL, MySQL, SQLite…).
147
+ */
148
+ get driver(): Driver;
149
+ /**
150
+ * The entity manager of the connection: the TypeORM operations on any entity (`find`, `save`, `delete`…) outside a
151
+ * transaction.
152
+ */
153
+ get manager(): EntityManager;
154
+ /**
155
+ * Replace the naming strategy of the connection, which names the tables, the columns and the constraints of the
156
+ * entities. Set it before the metadata is used: the names already built are not renamed.
157
+ * @param instance The naming strategy.
158
+ */
159
+ set namingStrategy(instance: NamingStrategyInterface);
160
+ /**
161
+ * The naming strategy of the connection, which names the tables, the columns and the constraints of the entities.
162
+ * @default TypeORM's `DefaultNamingStrategy`, unless the options set `namingStrategy`
163
+ */
164
+ get namingStrategy(): NamingStrategyInterface;
165
+ /**
166
+ * The entity subscribers registered on the connection (the `subscribers` of the options).
167
+ */
168
+ get subscribers(): EntitySubscriberInterface<any>[];
169
+ /**
170
+ * The metadata of every entity registered on the connection.
171
+ */
172
+ get entityMetadatas(): EntityMetadata[];
173
+ /**
174
+ * The metadata of every entity registered on the connection, by entity target (class, name or schema): the same as
175
+ * {@link Database.entityMetadatas}, for fast lookups.
176
+ */
177
+ get entityMetadatasMap(): Map<EntityTarget<any>, EntityMetadata>;
178
+ /**
179
+ * The query result cache of the connection, `undefined` unless the options enable `cache`.
180
+ */
181
+ get queryResultCache(): QueryResultCache | undefined;
182
+ /**
183
+ * Connect to the database with the options.
184
+ * @protected
185
+ */
186
+ protected init(): Promise<void>;
187
+ /**
188
+ * Disconnect from the database.
189
+ * @protected
190
+ */
191
+ protected destroy(): Promise<void>;
192
+ /**
193
+ * Create or update the database schema from the registered entities (the tables, columns, indices and foreign
194
+ * keys). Meant for development: the migrations change the schema of a production database.
195
+ * @param dropBeforeSync Drop every table of the database schema, with its data (also the tables of no entity),
196
+ * before creating the schema. Defaults to `false`.
197
+ * @returns Resolves once the schema is built.
198
+ * @throws {CannotExecuteNotConnectedError} When the connection is closed.
199
+ */
200
+ synchronize(dropBeforeSync?: boolean): Promise<void>;
201
+ /**
202
+ * Run the pending migrations (the `migrations` of the options not yet recorded in the migrations table), in their
203
+ * timestamp order.
204
+ * @param options The transactions of the migrations, and whether they are only recorded (`fake`).
205
+ * @returns The migrations run, an empty array when none is pending.
206
+ * @throws {CannotExecuteNotConnectedError} When the connection is closed.
207
+ * @throws {Error} The error of a failed migration, once its transaction (`'all'` or `'each'`) is rolled back.
208
+ */
209
+ runMigrations(options?: MigrationRunOptions): Promise<Migration[]>;
210
+ /**
211
+ * Revert the last migration run (its `down()`), and remove it from the migrations table. Does nothing when no
212
+ * migration was run.
213
+ * @param options The transaction of the migration (`'all'` by default, `migrationsTransactionMode` not applying),
214
+ * and whether it is only removed from the migrations table (`fake`).
215
+ * @returns Resolves once the migration is reverted.
216
+ * @throws {CannotExecuteNotConnectedError} When the connection is closed.
217
+ */
218
+ undoLastMigration(options?: MigrationRunOptions): Promise<void>;
219
+ /**
220
+ * Log each migration of the options with whether it was run (`[X]`) or not (`[ ]`), through the logger of the
221
+ * connection (shown when its `logging` includes `schema`).
222
+ * @returns Whether a migration is pending.
223
+ */
224
+ showMigrations(): Promise<boolean>;
225
+ /**
226
+ * Whether an entity is registered on the connection.
227
+ * @param target The entity class, its name, or its table name.
228
+ * @returns `true` when the connection has its metadata.
229
+ */
230
+ hasMetadata(target: EntityTarget<any>): boolean;
231
+ /**
232
+ * The metadata of a registered entity: its table, columns, relations…
233
+ * @param target The entity class, its name, or its table name.
234
+ * @returns The metadata of the entity.
235
+ * @throws {EntityMetadataNotFoundError} When the entity is not registered on the connection.
236
+ */
237
+ getMetadata(target: EntityTarget<any>): EntityMetadata;
238
+ /**
239
+ * The repository of an entity, created once per entity: its `find`, `save`, `delete`… operations outside a
240
+ * transaction (in a transaction, use the entity manager given to the callback).
241
+ * @param target The entity class, its name, or its `EntitySchema`.
242
+ * @returns The repository of the entity (a `MongoRepository` on a MongoDB connection).
243
+ * @throws {EntityMetadataNotFoundError} From the repository operations, when the entity is not registered.
244
+ */
245
+ getRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): Repository<Entity>;
246
+ /**
247
+ * The tree repository of an entity decorated with `@Tree()`: the operations on its ancestors and descendants
248
+ * (`findTrees`, `findDescendants`…).
249
+ * @param target The tree entity class, or its name.
250
+ * @returns The tree repository of the entity.
251
+ * @throws {TreeRepositoryNotSupportedError} On a driver without tree support (MongoDB).
252
+ */
253
+ getTreeRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): TreeRepository<Entity>;
254
+ /**
255
+ * The MongoDB repository of an entity: the repository operations plus the MongoDB ones (`aggregate`, `bulkWrite`…).
256
+ * @param target The entity class, or its name.
257
+ * @returns The MongoDB repository of the entity.
258
+ * @throws {TypeORMError} When the connection is not a MongoDB one.
259
+ */
260
+ getMongoRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): MongoRepository<Entity>;
261
+ /**
262
+ * Run a function in a transaction, on one connection of the pool: committed when the function resolves, rolled
263
+ * back when it rejects (its error rethrown). Every operation of the transaction goes through the entity manager given
264
+ * to the function: the ones made through {@link Database.manager} or the repositories of this object run outside of
265
+ * it.
266
+ * @param runInTransaction The function, given the entity manager of the transaction.
267
+ * @returns What the function resolves.
268
+ * @throws {Error} The error of the function, or of the database, after the rollback.
269
+ */
270
+ transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
271
+ /**
272
+ * Run a function in a transaction with an isolation level, on one connection of the pool: committed when the
273
+ * function resolves, rolled back when it rejects (its error rethrown). Every operation of the transaction goes
274
+ * through the entity manager given to the function.
275
+ * @param isolationLevel The isolation level: `'READ UNCOMMITTED'`, `'READ COMMITTED'`, `'REPEATABLE READ'` or
276
+ * `'SERIALIZABLE'` (the levels the driver supports).
277
+ * @param runInTransaction The function, given the entity manager of the transaction.
278
+ * @returns What the function resolves.
279
+ * @throws {Error} The error of the function, or of the database, after the rollback.
280
+ */
281
+ transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
282
+ /**
283
+ * Run a raw SQL query.
284
+ * @param query The SQL, its parameters as placeholders: `$1`, `$2`… for PostgreSQL, `?` for MySQL and SQLite.
285
+ * @param parameters The values of the placeholders, escaped by the driver.
286
+ * @param queryRunner The query runner to run it on (a transaction of {@link Database.createQueryRunner}), a
287
+ * connection of the pool otherwise.
288
+ * @returns The raw result of the driver: the rows of a `SELECT` (an array of objects).
289
+ * @throws {QueryFailedError} When the database rejects the query.
290
+ */
291
+ query<T = any>(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<T>;
292
+ /**
293
+ * Create a query builder selecting an entity.
294
+ * @param entityClass The entity class, its name, or its `EntitySchema`.
295
+ * @param alias The alias of the entity in the query (`'user'` in `user.name`).
296
+ * @param queryRunner The query runner to run the query on, a connection of the pool otherwise.
297
+ * @returns The query builder, selecting the entity from its table.
298
+ * @throws {EntityMetadataNotFoundError} When the entity is not registered.
299
+ * @throws {TypeORMError} On a MongoDB connection, which has no query builder.
300
+ */
301
+ createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
302
+ /**
303
+ * Create an empty query builder, its selection and source set by its `select()` and `from()`.
304
+ * @param queryRunner The query runner to run the query on, a connection of the pool otherwise.
305
+ * @returns The query builder.
306
+ * @throws {TypeORMError} On a MongoDB connection, which has no query builder.
307
+ */
308
+ createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;
309
+ /**
310
+ * Create a query runner: one connection taken from the pool, to run several queries on the same connection and
311
+ * control its transaction by hand (`connect()`, `startTransaction()`, `commitTransaction()`,
312
+ * `rollbackTransaction()`). The caller must `release()` it, or the connection stays taken.
313
+ * @param mode With replication, `'master'` (the default) for the writes, `'slave'` for the reads on a replica.
314
+ * @returns The query runner, not connected until its first query or `connect()`.
315
+ */
316
+ createQueryRunner(mode?: ReplicationMode): QueryRunner;
317
+ /**
318
+ * The metadata of the junction table of a many-to-many relation.
319
+ * @param entityTarget The entity owning the relation.
320
+ * @param relationPropertyPath The property of the relation (`'tags'`, or a path such as `'profile.tags'`).
321
+ * @returns The metadata of the junction table.
322
+ * @throws {EntityMetadataNotFoundError} When the entity is not registered.
323
+ * @throws {TypeORMError} When the entity has no such relation, or the relation is not a many-to-many one.
324
+ */
325
+ getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string): EntityMetadata | undefined;
326
+ /**
327
+ * Create an entity manager on the connection, bound to a query runner when given (its operations then run on the
328
+ * runner's connection and transaction).
329
+ * @param queryRunner The query runner the manager uses, a connection of the pool per operation otherwise.
330
+ * @returns The entity manager.
331
+ */
332
+ createEntityManager(queryRunner?: QueryRunner): EntityManager;
333
+ }