mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2025-12-11 00:22:49 +00:00
清理
This commit is contained in:
parent
74fbae4e3d
commit
95f7218d9e
@ -1 +0,0 @@
|
||||
COOL一些资源包和临时文件
|
||||
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2013 - Now midwayjs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@ -1,96 +0,0 @@
|
||||
# midway typeorm component
|
||||
|
||||
## How to use
|
||||
|
||||
in Configuration.ts file
|
||||
|
||||
```ts
|
||||
import * as typeorm from '@midwayjs/typeorm';
|
||||
import { join } from 'path';
|
||||
|
||||
@Configuration({
|
||||
imports: [
|
||||
typeorm,
|
||||
],
|
||||
importConfigs: [
|
||||
join(__dirname, './config')
|
||||
]
|
||||
})
|
||||
export class ContainerConfiguration {
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
in config files
|
||||
|
||||
```ts
|
||||
export default {
|
||||
typeorm: {
|
||||
dataSource: {
|
||||
default: {
|
||||
type: 'mysql',
|
||||
host: '',
|
||||
port: 3306,
|
||||
username: '',
|
||||
password: '',
|
||||
database: undefined,
|
||||
synchronize: true,
|
||||
logging: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
## Define EntityModel
|
||||
|
||||
```ts
|
||||
// model/user.ts
|
||||
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
|
||||
|
||||
@Entity('test_user')
|
||||
export class Photo {
|
||||
@PrimaryGeneratedColumn({ name: "id" })
|
||||
id: number;
|
||||
|
||||
@Column({ name: "name" })
|
||||
name: string;
|
||||
|
||||
@OneToMany(type => Message, message => message.sender)
|
||||
messages: Message[];
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Use Model
|
||||
|
||||
in code files
|
||||
|
||||
```ts
|
||||
import { InjectEntityModel } from '@midwayjs/orm';
|
||||
import { User } from './model/user';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
@Provide()
|
||||
export class UserService {
|
||||
|
||||
@InjectEntityModel(User)
|
||||
userModel: Repository<User>;
|
||||
|
||||
async testUser() {
|
||||
const u = new User();
|
||||
u.name = 'oneuser1';
|
||||
const uu = await this.userModel.save(u);
|
||||
console.log('user one id = ', uu.id);
|
||||
|
||||
const user = new User();
|
||||
user.id = 1;
|
||||
const users = await this.userModel.findAndCount({
|
||||
where: user
|
||||
});
|
||||
return 'hello world' + JSON.stringify(users);
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
'use strict';
|
||||
|
||||
const { join } = require('path');
|
||||
// eslint-disable-next-line node/no-unpublished-require
|
||||
const { CommandUtils } = require('typeorm/commands/CommandUtils');
|
||||
// eslint-disable-next-line node/no-unpublished-require
|
||||
const ImportUtils = require('typeorm/util/ImportUtils');
|
||||
// eslint-disable-next-line node/no-unpublished-require
|
||||
const { DataSource } = require('typeorm');
|
||||
|
||||
const originLoadDataSource = CommandUtils.loadDataSource;
|
||||
|
||||
CommandUtils.loadDataSource = async function (dataSourceFilePath) {
|
||||
try {
|
||||
let dataSourceFileExports = await ImportUtils.importOrRequireFile(
|
||||
dataSourceFilePath
|
||||
);
|
||||
if (dataSourceFileExports[0] && dataSourceFileExports[0].default) {
|
||||
dataSourceFileExports = dataSourceFileExports[0].default;
|
||||
if (typeof dataSourceFileExports === 'function') {
|
||||
dataSourceFileExports = dataSourceFileExports({
|
||||
appDir: process.cwd(),
|
||||
baseDir: join(process.cwd(), 'src'),
|
||||
});
|
||||
}
|
||||
if (dataSourceFileExports['typeorm']) {
|
||||
dataSourceFileExports = dataSourceFileExports['typeorm'];
|
||||
dataSourceFileExports =
|
||||
dataSourceFileExports.dataSource[
|
||||
dataSourceFileExports['defaultClientName'] || 'default'
|
||||
];
|
||||
|
||||
return new DataSource(dataSourceFileExports);
|
||||
} else {
|
||||
console.log(
|
||||
'[midway:typeorm] Not found dataSource options and run origin loadDataSource method'
|
||||
);
|
||||
return originLoadDataSource(dataSourceFilePath);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
throw new Error(
|
||||
`Unable to open file: "${dataSourceFilePath}". ${err.message}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// eslint-disable-next-line node/no-unpublished-require
|
||||
require('typeorm/cli-ts-node-commonjs');
|
||||
9
cool/package/@midwayjs/typeorm/index.d.ts
vendored
9
cool/package/@midwayjs/typeorm/index.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
import { typeormConfigOptions } from './dist/index';
|
||||
|
||||
export * from './dist/index';
|
||||
|
||||
declare module '@midwayjs/core/dist/interface' {
|
||||
interface MidwayConfig {
|
||||
typeorm?: PowerPartial<typeormConfigOptions>;
|
||||
}
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
{
|
||||
"name": "@midwayjs/typeorm",
|
||||
"version": "3.20.0",
|
||||
"main": "dist/index.js",
|
||||
"typings": "index.d.ts",
|
||||
"bin": {
|
||||
"mwtypeorm": "./cli.js"
|
||||
},
|
||||
"files": [
|
||||
"dist/**/*.js",
|
||||
"dist/**/*.d.ts",
|
||||
"cli.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@midwayjs/core": "^3.20.0",
|
||||
"@midwayjs/mock": "^3.20.0",
|
||||
"sqlite3": "5.1.7",
|
||||
"typeorm": "0.3.20"
|
||||
},
|
||||
"author": {
|
||||
"name": "czy88840616",
|
||||
"email": "czy88840616@gmail.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
|
||||
"cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/midwayjs/midway.git"
|
||||
},
|
||||
"gitHead": "5bf838ec6054f6e1e983664b0456a975db795932"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import "./cli";
|
||||
@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
require("ts-node").register();
|
||||
import "./cli";
|
||||
|
||||
//# sourceMappingURL=cli-ts-node-commonjs.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/cli-ts-node-commonjs.ts"],"names":[],"mappings":";AACA,OAAO,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAA;AAC7B,OAAO,OAAO,CAAA","file":"cli-ts-node-commonjs.js","sourcesContent":["#!/usr/bin/env node\nrequire(\"ts-node\").register()\nimport \"./cli\"\n"],"sourceRoot":"."}
|
||||
@ -1,2 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
export {};
|
||||
@ -1,23 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import { spawnSync } from "child_process";
|
||||
if ((process.env["NODE_OPTIONS"] || "").includes("--loader ts-node"))
|
||||
require("./cli");
|
||||
else {
|
||||
const childProcess = spawnSync(process.argv[0], process.argv.slice(1), {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: [
|
||||
process.env["NODE_OPTIONS"],
|
||||
"--loader ts-node/esm",
|
||||
"--no-warnings",
|
||||
]
|
||||
.filter((item) => !!item)
|
||||
.join(" "),
|
||||
},
|
||||
windowsHide: true,
|
||||
});
|
||||
process.exit(childProcess.status || 0);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=cli-ts-node-esm.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/cli-ts-node-esm.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,kBAAkB,CAAC;IAChE,OAAO,CAAC,OAAO,CAAC,CAAA;KACf,CAAC;IACF,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;QACnE,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE;YACD,GAAG,OAAO,CAAC,GAAG;YACd,YAAY,EAAE;gBACV,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;gBAC3B,sBAAsB;gBACtB,eAAe;aAClB;iBACI,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBACxB,IAAI,CAAC,GAAG,CAAC;SACjB;QACD,WAAW,EAAE,IAAI;KACpB,CAAC,CAAA;IAEF,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,IAAI,CAAC,CAAC,CAAA;AAC1C,CAAC","file":"cli-ts-node-esm.js","sourcesContent":["#!/usr/bin/env node\nimport { spawnSync } from \"child_process\"\n\nif ((process.env[\"NODE_OPTIONS\"] || \"\").includes(\"--loader ts-node\"))\n require(\"./cli\")\nelse {\n const childProcess = spawnSync(process.argv[0], process.argv.slice(1), {\n stdio: \"inherit\",\n env: {\n ...process.env,\n NODE_OPTIONS: [\n process.env[\"NODE_OPTIONS\"],\n \"--loader ts-node/esm\",\n \"--no-warnings\",\n ]\n .filter((item) => !!item)\n .join(\" \"),\n },\n windowsHide: true,\n })\n\n process.exit(childProcess.status || 0)\n}\n"],"sourceRoot":"."}
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.
|
||||
*/
|
||||
export type DeepPartial<T> = T | (T extends Array<infer U> ? DeepPartial<U>[] : T extends Map<infer K, infer V> ? Map<DeepPartial<K>, DeepPartial<V>> : T extends Set<infer M> ? Set<DeepPartial<M>> : T extends object ? {
|
||||
[K in keyof T]?: DeepPartial<T[K]>;
|
||||
} : T);
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=DeepPartial.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/DeepPartial.ts"],"names":[],"mappings":"","file":"DeepPartial.js","sourcesContent":["/**\n * Same as Partial<T> but goes deeper and makes Partial<T> all its properties and sub-properties.\n */\nexport type DeepPartial<T> =\n | T\n | (T extends Array<infer U>\n ? DeepPartial<U>[]\n : T extends Map<infer K, infer V>\n ? Map<DeepPartial<K>, DeepPartial<V>>\n : T extends Set<infer M>\n ? Set<DeepPartial<M>>\n : T extends object\n ? { [K in keyof T]?: DeepPartial<T[K]> }\n : T)\n"],"sourceRoot":".."}
|
||||
@ -1,9 +0,0 @@
|
||||
import { ObjectType } from "./ObjectType";
|
||||
import { EntitySchema } from "..";
|
||||
/**
|
||||
* Entity target.
|
||||
*/
|
||||
export type EntityTarget<Entity> = ObjectType<Entity> | EntitySchema<Entity> | string | {
|
||||
type: Entity;
|
||||
name: string;
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=EntityTarget.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/EntityTarget.ts"],"names":[],"mappings":"","file":"EntityTarget.js","sourcesContent":["import { ObjectType } from \"./ObjectType\"\nimport { EntitySchema } from \"..\"\n\n/**\n * Entity target.\n */\nexport type EntityTarget<Entity> =\n | ObjectType<Entity>\n | EntitySchema<Entity>\n | string\n | { type: Entity; name: string }\n"],"sourceRoot":".."}
|
||||
@ -1,8 +0,0 @@
|
||||
/**
|
||||
* List of T-s passed as an array or object map.
|
||||
*
|
||||
* Example usage: entities as an array of imported using import * as syntax.
|
||||
*/
|
||||
export type MixedList<T> = T[] | {
|
||||
[key: string]: T;
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=MixedList.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/MixedList.ts"],"names":[],"mappings":"","file":"MixedList.js","sourcesContent":["/**\n * List of T-s passed as an array or object map.\n *\n * Example usage: entities as an array of imported using import * as syntax.\n */\nexport type MixedList<T> = T[] | { [key: string]: T }\n"],"sourceRoot":".."}
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Remove keys with `never` value from object type
|
||||
* */
|
||||
export type NonNever<T extends {}> = Pick<T, {
|
||||
[K in keyof T]: T[K] extends never ? never : K;
|
||||
}[keyof T]>;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=NonNever.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/NonNever.ts"],"names":[],"mappings":"","file":"NonNever.js","sourcesContent":["/**\n * Remove keys with `never` value from object type\n * */\nexport type NonNever<T extends {}> = Pick<\n T,\n { [K in keyof T]: T[K] extends never ? never : K }[keyof T]\n>\n"],"sourceRoot":".."}
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Interface of the simple literal object with any string keys.
|
||||
*/
|
||||
export interface ObjectLiteral {
|
||||
[key: string]: any;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ObjectLiteral.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/ObjectLiteral.ts"],"names":[],"mappings":"","file":"ObjectLiteral.js","sourcesContent":["/**\n * Interface of the simple literal object with any string keys.\n */\nexport interface ObjectLiteral {\n [key: string]: any\n}\n"],"sourceRoot":".."}
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Represents some Type of the Object.
|
||||
*/
|
||||
export type ObjectType<T> = {
|
||||
new (): T;
|
||||
} | Function;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ObjectType.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/ObjectType.ts"],"names":[],"mappings":"","file":"ObjectType.js","sourcesContent":["/**\n * Represents some Type of the Object.\n */\nexport type ObjectType<T> = { new (): T } | Function\n"],"sourceRoot":".."}
|
||||
@ -1,6 +0,0 @@
|
||||
/**
|
||||
* Pick only the keys that match the Type `U`
|
||||
*/
|
||||
export type PickKeysByType<T, U> = string & keyof {
|
||||
[P in keyof T as T[P] extends U ? P : never]: T[P];
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=PickKeysByType.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/PickKeysByType.ts"],"names":[],"mappings":"","file":"PickKeysByType.js","sourcesContent":["/**\n * Pick only the keys that match the Type `U`\n */\nexport type PickKeysByType<T, U> = string &\n keyof {\n [P in keyof T as T[P] extends U ? P : never]: T[P]\n }\n"],"sourceRoot":".."}
|
||||
@ -1,14 +0,0 @@
|
||||
/**
|
||||
* Wrapper type for relation type definitions in entities.
|
||||
* Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.
|
||||
*
|
||||
* Usage example:
|
||||
* @Entity()
|
||||
* export default class User {
|
||||
*
|
||||
* @OneToOne(() => Profile, profile => profile.user)
|
||||
* profile: Relation<Profile>;
|
||||
*
|
||||
* }
|
||||
*/
|
||||
export type Relation<T> = T;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=RelationType.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/common/RelationType.ts"],"names":[],"mappings":"","file":"RelationType.js","sourcesContent":["/**\n * Wrapper type for relation type definitions in entities.\n * Used to circumvent ESM modules circular dependency issue caused by reflection metadata saving the type of the property.\n *\n * Usage example:\n * @Entity()\n * export default class User {\n *\n * @OneToOne(() => Profile, profile => profile.user)\n * profile: Relation<Profile>;\n *\n * }\n */\nexport type Relation<T> = T\n"],"sourceRoot":".."}
|
||||
@ -1,7 +0,0 @@
|
||||
import { BaseDataSourceOptions } from "../data-source/BaseDataSourceOptions";
|
||||
/**
|
||||
* BaseConnectionOptions is set of connection options shared by all database types.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export type BaseConnectionOptions = BaseDataSourceOptions;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=BaseConnectionOptions.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/connection/BaseConnectionOptions.ts"],"names":[],"mappings":"","file":"BaseConnectionOptions.js","sourcesContent":["import { BaseDataSourceOptions } from \"../data-source/BaseDataSourceOptions\"\n\n/**\n * BaseConnectionOptions is set of connection options shared by all database types.\n *\n * @deprecated\n */\nexport type BaseConnectionOptions = BaseDataSourceOptions\n"],"sourceRoot":".."}
|
||||
@ -1,10 +0,0 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
/**
|
||||
* Connection is a single database ORM connection to a specific database.
|
||||
* Its not required to be a database connection, depend on database type it can create connection pool.
|
||||
* You can have multiple connections to multiple databases in your application.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class Connection extends DataSource {
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
/**
|
||||
* Connection is a single database ORM connection to a specific database.
|
||||
* Its not required to be a database connection, depend on database type it can create connection pool.
|
||||
* You can have multiple connections to multiple databases in your application.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class Connection extends DataSource {
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Connection.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/connection/Connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,UAAW,SAAQ,UAAU;CAAG","file":"Connection.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\n\n/**\n * Connection is a single database ORM connection to a specific database.\n * Its not required to be a database connection, depend on database type it can create connection pool.\n * You can have multiple connections to multiple databases in your application.\n *\n * @deprecated\n */\nexport class Connection extends DataSource {}\n"],"sourceRoot":".."}
|
||||
@ -1,33 +0,0 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* ConnectionManager is used to store and manage multiple orm connections.
|
||||
* It also provides useful factory methods to simplify connection creation.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class ConnectionManager {
|
||||
/**
|
||||
* List of connections registered in this connection manager.
|
||||
*/
|
||||
get connections(): DataSource[];
|
||||
/**
|
||||
* Internal lookup to quickly get from a connection name to the Connection object.
|
||||
*/
|
||||
private readonly connectionMap;
|
||||
/**
|
||||
* Checks if connection with the given name exist in the manager.
|
||||
*/
|
||||
has(name: string): boolean;
|
||||
/**
|
||||
* Gets registered connection with the given name.
|
||||
* If connection name is not given then it will get a default connection.
|
||||
* Throws error if connection with the given name was not found.
|
||||
*/
|
||||
get(name?: string): DataSource;
|
||||
/**
|
||||
* Creates a new connection based on the given connection options and registers it in the manager.
|
||||
* Connection won't be established, you'll need to manually call connect method to establish connection.
|
||||
*/
|
||||
create(options: DataSourceOptions): DataSource;
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { ConnectionNotFoundError } from "../error/ConnectionNotFoundError";
|
||||
import { AlreadyHasActiveConnectionError } from "../error/AlreadyHasActiveConnectionError";
|
||||
/**
|
||||
* ConnectionManager is used to store and manage multiple orm connections.
|
||||
* It also provides useful factory methods to simplify connection creation.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class ConnectionManager {
|
||||
constructor() {
|
||||
/**
|
||||
* Internal lookup to quickly get from a connection name to the Connection object.
|
||||
*/
|
||||
this.connectionMap = new Map();
|
||||
}
|
||||
/**
|
||||
* List of connections registered in this connection manager.
|
||||
*/
|
||||
get connections() {
|
||||
return Array.from(this.connectionMap.values());
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Checks if connection with the given name exist in the manager.
|
||||
*/
|
||||
has(name) {
|
||||
return this.connectionMap.has(name);
|
||||
}
|
||||
/**
|
||||
* Gets registered connection with the given name.
|
||||
* If connection name is not given then it will get a default connection.
|
||||
* Throws error if connection with the given name was not found.
|
||||
*/
|
||||
get(name = "default") {
|
||||
const connection = this.connectionMap.get(name);
|
||||
if (!connection)
|
||||
throw new ConnectionNotFoundError(name);
|
||||
return connection;
|
||||
}
|
||||
/**
|
||||
* Creates a new connection based on the given connection options and registers it in the manager.
|
||||
* Connection won't be established, you'll need to manually call connect method to establish connection.
|
||||
*/
|
||||
create(options) {
|
||||
// check if such connection is already registered
|
||||
const existConnection = this.connectionMap.get(options.name || "default");
|
||||
if (existConnection) {
|
||||
// if connection is registered and its not closed then throw an error
|
||||
if (existConnection.isInitialized)
|
||||
throw new AlreadyHasActiveConnectionError(options.name || "default");
|
||||
}
|
||||
// create a new connection
|
||||
const connection = new DataSource(options);
|
||||
this.connectionMap.set(connection.name, connection);
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionManager.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/connection/ConnectionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAE1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;AAE1F;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAA9B;QAQI;;WAEG;QACc,kBAAa,GAA4B,IAAI,GAAG,EAAE,CAAA;IA+CvE,CAAC;IAzDG;;OAEG;IACH,IAAI,WAAW;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;IAClD,CAAC;IAOD,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E;;OAEG;IACH,GAAG,CAAC,IAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,OAAe,SAAS;QACxB,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/C,IAAI,CAAC,UAAU;YAAE,MAAM,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAA;QAExD,OAAO,UAAU,CAAA;IACrB,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,OAA0B;QAC7B,iDAAiD;QACjD,MAAM,eAAe,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAC1C,OAAO,CAAC,IAAI,IAAI,SAAS,CAC5B,CAAA;QACD,IAAI,eAAe,EAAE,CAAC;YAClB,qEAAqE;YACrE,IAAI,eAAe,CAAC,aAAa;gBAC7B,MAAM,IAAI,+BAA+B,CACrC,OAAO,CAAC,IAAI,IAAI,SAAS,CAC5B,CAAA;QACT,CAAC;QAED,0BAA0B;QAC1B,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;QACnD,OAAO,UAAU,CAAA;IACrB,CAAC;CACJ","file":"ConnectionManager.js","sourcesContent":["import { DataSource } from \"../data-source/DataSource\"\nimport { ConnectionNotFoundError } from \"../error/ConnectionNotFoundError\"\nimport { DataSourceOptions } from \"../data-source/DataSourceOptions\"\nimport { AlreadyHasActiveConnectionError } from \"../error/AlreadyHasActiveConnectionError\"\n\n/**\n * ConnectionManager is used to store and manage multiple orm connections.\n * It also provides useful factory methods to simplify connection creation.\n *\n * @deprecated\n */\nexport class ConnectionManager {\n /**\n * List of connections registered in this connection manager.\n */\n get connections(): DataSource[] {\n return Array.from(this.connectionMap.values())\n }\n\n /**\n * Internal lookup to quickly get from a connection name to the Connection object.\n */\n private readonly connectionMap: Map<string, DataSource> = new Map()\n\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Checks if connection with the given name exist in the manager.\n */\n has(name: string): boolean {\n return this.connectionMap.has(name)\n }\n\n /**\n * Gets registered connection with the given name.\n * If connection name is not given then it will get a default connection.\n * Throws error if connection with the given name was not found.\n */\n get(name: string = \"default\"): DataSource {\n const connection = this.connectionMap.get(name)\n if (!connection) throw new ConnectionNotFoundError(name)\n\n return connection\n }\n\n /**\n * Creates a new connection based on the given connection options and registers it in the manager.\n * Connection won't be established, you'll need to manually call connect method to establish connection.\n */\n create(options: DataSourceOptions): DataSource {\n // check if such connection is already registered\n const existConnection = this.connectionMap.get(\n options.name || \"default\",\n )\n if (existConnection) {\n // if connection is registered and its not closed then throw an error\n if (existConnection.isInitialized)\n throw new AlreadyHasActiveConnectionError(\n options.name || \"default\",\n )\n }\n\n // create a new connection\n const connection = new DataSource(options)\n this.connectionMap.set(connection.name, connection)\n return connection\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,24 +0,0 @@
|
||||
import { MigrationInterface } from "../migration/MigrationInterface";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
import { EntityMetadata } from "../metadata/EntityMetadata";
|
||||
import { EntitySubscriberInterface } from "../subscriber/EntitySubscriberInterface";
|
||||
/**
|
||||
* Builds migration instances, subscriber instances and entity metadatas for the given classes.
|
||||
*/
|
||||
export declare class ConnectionMetadataBuilder {
|
||||
protected connection: DataSource;
|
||||
constructor(connection: DataSource);
|
||||
/**
|
||||
* Builds migration instances for the given classes or directories.
|
||||
*/
|
||||
buildMigrations(migrations: (Function | string)[]): Promise<MigrationInterface[]>;
|
||||
/**
|
||||
* Builds subscriber instances for the given classes or directories.
|
||||
*/
|
||||
buildSubscribers(subscribers: (Function | string)[]): Promise<EntitySubscriberInterface<any>[]>;
|
||||
/**
|
||||
* Builds entity metadatas for the given classes or directories.
|
||||
*/
|
||||
buildEntityMetadatas(entities: (Function | EntitySchema<any> | string)[]): Promise<EntityMetadata[]>;
|
||||
}
|
||||
@ -1,70 +0,0 @@
|
||||
import { importClassesFromDirectories } from "../util/DirectoryExportedClassesLoader";
|
||||
import { OrmUtils } from "../util/OrmUtils";
|
||||
import { getFromContainer } from "../container";
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { EntityMetadataBuilder } from "../metadata-builder/EntityMetadataBuilder";
|
||||
import { EntitySchemaTransformer } from "../entity-schema/EntitySchemaTransformer";
|
||||
import { InstanceChecker } from "../util/InstanceChecker";
|
||||
/**
|
||||
* Builds migration instances, subscriber instances and entity metadatas for the given classes.
|
||||
*/
|
||||
export class ConnectionMetadataBuilder {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Builds migration instances for the given classes or directories.
|
||||
*/
|
||||
async buildMigrations(migrations) {
|
||||
const [migrationClasses, migrationDirectories] = OrmUtils.splitClassesAndStrings(migrations);
|
||||
const allMigrationClasses = [
|
||||
...migrationClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, migrationDirectories)),
|
||||
];
|
||||
return allMigrationClasses.map((migrationClass) => getFromContainer(migrationClass));
|
||||
}
|
||||
/**
|
||||
* Builds subscriber instances for the given classes or directories.
|
||||
*/
|
||||
async buildSubscribers(subscribers) {
|
||||
const [subscriberClasses, subscriberDirectories] = OrmUtils.splitClassesAndStrings(subscribers || []);
|
||||
const allSubscriberClasses = [
|
||||
...subscriberClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, subscriberDirectories)),
|
||||
];
|
||||
return getMetadataArgsStorage()
|
||||
.filterSubscribers(allSubscriberClasses)
|
||||
.map((metadata) => getFromContainer(metadata.target));
|
||||
}
|
||||
/**
|
||||
* Builds entity metadatas for the given classes or directories.
|
||||
*/
|
||||
async buildEntityMetadatas(entities) {
|
||||
// todo: instead we need to merge multiple metadata args storages
|
||||
const [entityClassesOrSchemas, entityDirectories] = OrmUtils.splitClassesAndStrings(entities || []);
|
||||
const entityClasses = entityClassesOrSchemas.filter((entityClass) => !InstanceChecker.isEntitySchema(entityClass));
|
||||
const entitySchemas = entityClassesOrSchemas.filter((entityClass) => InstanceChecker.isEntitySchema(entityClass));
|
||||
const allEntityClasses = [
|
||||
...entityClasses,
|
||||
...(await importClassesFromDirectories(this.connection.logger, entityDirectories)),
|
||||
];
|
||||
allEntityClasses.forEach((entityClass) => {
|
||||
// if we have entity schemas loaded from directories
|
||||
if (InstanceChecker.isEntitySchema(entityClass)) {
|
||||
entitySchemas.push(entityClass);
|
||||
}
|
||||
});
|
||||
const decoratorEntityMetadatas = new EntityMetadataBuilder(this.connection, getMetadataArgsStorage()).build(allEntityClasses);
|
||||
const metadataArgsStorageFromSchema = new EntitySchemaTransformer().transform(entitySchemas);
|
||||
const schemaEntityMetadatas = new EntityMetadataBuilder(this.connection, metadataArgsStorageFromSchema).build();
|
||||
return [...decoratorEntityMetadatas, ...schemaEntityMetadatas];
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionMetadataBuilder.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,9 +0,0 @@
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* ConnectionOptions is an interface with settings and options for specific connection.
|
||||
* Options contain database and other connection-related settings.
|
||||
* Consumer must provide connection options for each of your connections.
|
||||
*
|
||||
* @deprecated use DataSourceOptions instead
|
||||
*/
|
||||
export type ConnectionOptions = DataSourceOptions;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=ConnectionOptions.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/connection/ConnectionOptions.ts"],"names":[],"mappings":"","file":"ConnectionOptions.js","sourcesContent":["import { DataSourceOptions } from \"../data-source/DataSourceOptions\"\n\n/**\n * ConnectionOptions is an interface with settings and options for specific connection.\n * Options contain database and other connection-related settings.\n * Consumer must provide connection options for each of your connections.\n *\n * @deprecated use DataSourceOptions instead\n */\nexport type ConnectionOptions = DataSourceOptions\n"],"sourceRoot":".."}
|
||||
@ -1,63 +0,0 @@
|
||||
import { DataSourceOptions } from "../data-source/DataSourceOptions";
|
||||
/**
|
||||
* Reads connection options from the ormconfig.
|
||||
*/
|
||||
export declare class ConnectionOptionsReader {
|
||||
protected options?: {
|
||||
/**
|
||||
* Directory where ormconfig should be read from.
|
||||
* By default its your application root (where your app package.json is located).
|
||||
*/
|
||||
root?: string | undefined;
|
||||
/**
|
||||
* Filename of the ormconfig configuration. By default its equal to "ormconfig".
|
||||
*/
|
||||
configName?: string | undefined;
|
||||
} | undefined;
|
||||
constructor(options?: {
|
||||
/**
|
||||
* Directory where ormconfig should be read from.
|
||||
* By default its your application root (where your app package.json is located).
|
||||
*/
|
||||
root?: string | undefined;
|
||||
/**
|
||||
* Filename of the ormconfig configuration. By default its equal to "ormconfig".
|
||||
*/
|
||||
configName?: string | undefined;
|
||||
} | undefined);
|
||||
/**
|
||||
* Returns all connection options read from the ormconfig.
|
||||
*/
|
||||
all(): Promise<DataSourceOptions[]>;
|
||||
/**
|
||||
* Gets a connection with a given name read from ormconfig.
|
||||
* If connection with such name would not be found then it throw error.
|
||||
*/
|
||||
get(name: string): Promise<DataSourceOptions>;
|
||||
/**
|
||||
* Checks if there is a TypeORM configuration file.
|
||||
*/
|
||||
has(name: string): Promise<boolean>;
|
||||
/**
|
||||
* Loads all connection options from a configuration file.
|
||||
*
|
||||
* todo: get in count NODE_ENV somehow
|
||||
*/
|
||||
protected load(): Promise<DataSourceOptions[] | undefined>;
|
||||
/**
|
||||
* Normalize connection options.
|
||||
*/
|
||||
protected normalizeConnectionOptions(connectionOptions: DataSourceOptions | DataSourceOptions[]): DataSourceOptions[];
|
||||
/**
|
||||
* Gets directory where configuration file should be located and configuration file name.
|
||||
*/
|
||||
protected get baseFilePath(): string;
|
||||
/**
|
||||
* Gets directory where configuration file should be located.
|
||||
*/
|
||||
protected get baseDirectory(): string;
|
||||
/**
|
||||
* Gets configuration file name.
|
||||
*/
|
||||
protected get baseConfigName(): string;
|
||||
}
|
||||
@ -1,197 +0,0 @@
|
||||
import appRootPath from "app-root-path";
|
||||
import path from "path";
|
||||
import { PlatformTools } from "../platform/PlatformTools";
|
||||
import { ConnectionOptionsEnvReader } from "./options-reader/ConnectionOptionsEnvReader";
|
||||
import { TypeORMError } from "../error";
|
||||
import { isAbsolute } from "../util/PathUtils";
|
||||
import { importOrRequireFile } from "../util/ImportUtils";
|
||||
/**
|
||||
* Reads connection options from the ormconfig.
|
||||
*/
|
||||
export class ConnectionOptionsReader {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Returns all connection options read from the ormconfig.
|
||||
*/
|
||||
async all() {
|
||||
const options = await this.load();
|
||||
if (!options)
|
||||
throw new TypeORMError(`No connection options were found in any orm configuration files.`);
|
||||
return options;
|
||||
}
|
||||
/**
|
||||
* Gets a connection with a given name read from ormconfig.
|
||||
* If connection with such name would not be found then it throw error.
|
||||
*/
|
||||
async get(name) {
|
||||
const allOptions = await this.all();
|
||||
const targetOptions = allOptions.find((options) => options.name === name || (name === "default" && !options.name));
|
||||
if (!targetOptions)
|
||||
throw new TypeORMError(`Cannot find connection ${name} because its not defined in any orm configuration files.`);
|
||||
return targetOptions;
|
||||
}
|
||||
/**
|
||||
* Checks if there is a TypeORM configuration file.
|
||||
*/
|
||||
async has(name) {
|
||||
const allOptions = await this.load();
|
||||
if (!allOptions)
|
||||
return false;
|
||||
const targetOptions = allOptions.find((options) => options.name === name || (name === "default" && !options.name));
|
||||
return !!targetOptions;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Loads all connection options from a configuration file.
|
||||
*
|
||||
* todo: get in count NODE_ENV somehow
|
||||
*/
|
||||
async load() {
|
||||
let connectionOptions = undefined;
|
||||
const fileFormats = [
|
||||
"env",
|
||||
"js",
|
||||
"mjs",
|
||||
"cjs",
|
||||
"ts",
|
||||
"mts",
|
||||
"cts",
|
||||
"json",
|
||||
];
|
||||
// Detect if baseFilePath contains file extension
|
||||
const possibleExtension = this.baseFilePath.substr(this.baseFilePath.lastIndexOf("."));
|
||||
const fileExtension = fileFormats.find((extension) => `.${extension}` === possibleExtension);
|
||||
// try to find any of following configuration formats
|
||||
const foundFileFormat = fileExtension ||
|
||||
fileFormats.find((format) => {
|
||||
return PlatformTools.fileExist(this.baseFilePath + "." + format);
|
||||
});
|
||||
// Determine config file name
|
||||
const configFile = fileExtension
|
||||
? this.baseFilePath
|
||||
: this.baseFilePath + "." + foundFileFormat;
|
||||
// if .env file found then load all its variables into process.env using dotenv package
|
||||
if (foundFileFormat === "env") {
|
||||
PlatformTools.dotenv(configFile);
|
||||
}
|
||||
else if (PlatformTools.fileExist(this.baseDirectory + "/.env")) {
|
||||
PlatformTools.dotenv(this.baseDirectory + "/.env");
|
||||
}
|
||||
// try to find connection options from any of available sources of configuration
|
||||
if (PlatformTools.getEnvVariable("TYPEORM_CONNECTION") ||
|
||||
PlatformTools.getEnvVariable("TYPEORM_URL")) {
|
||||
connectionOptions = await new ConnectionOptionsEnvReader().read();
|
||||
}
|
||||
else if (foundFileFormat === "js" ||
|
||||
foundFileFormat === "mjs" ||
|
||||
foundFileFormat === "cjs" ||
|
||||
foundFileFormat === "ts" ||
|
||||
foundFileFormat === "mts" ||
|
||||
foundFileFormat === "cts") {
|
||||
const [importOrRequireResult, moduleSystem] = await importOrRequireFile(configFile);
|
||||
const configModule = await importOrRequireResult;
|
||||
if (moduleSystem === "esm" ||
|
||||
(configModule &&
|
||||
"__esModule" in configModule &&
|
||||
"default" in configModule)) {
|
||||
connectionOptions = configModule.default;
|
||||
}
|
||||
else {
|
||||
connectionOptions = configModule;
|
||||
}
|
||||
}
|
||||
else if (foundFileFormat === "json") {
|
||||
connectionOptions = require(configFile);
|
||||
}
|
||||
// normalize and return connection options
|
||||
if (connectionOptions) {
|
||||
return this.normalizeConnectionOptions(connectionOptions);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Normalize connection options.
|
||||
*/
|
||||
normalizeConnectionOptions(connectionOptions) {
|
||||
if (!Array.isArray(connectionOptions))
|
||||
connectionOptions = [connectionOptions];
|
||||
connectionOptions.forEach((options) => {
|
||||
options.baseDirectory = this.baseDirectory;
|
||||
if (options.entities) {
|
||||
const entities = options.entities.map((entity) => {
|
||||
if (typeof entity === "string" &&
|
||||
entity.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + entity;
|
||||
return entity;
|
||||
});
|
||||
Object.assign(connectionOptions, { entities: entities });
|
||||
}
|
||||
if (options.subscribers) {
|
||||
const subscribers = options.subscribers.map((subscriber) => {
|
||||
if (typeof subscriber === "string" &&
|
||||
subscriber.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + subscriber;
|
||||
return subscriber;
|
||||
});
|
||||
Object.assign(connectionOptions, { subscribers: subscribers });
|
||||
}
|
||||
if (options.migrations) {
|
||||
const migrations = options.migrations.map((migration) => {
|
||||
if (typeof migration === "string" &&
|
||||
migration.substr(0, 1) !== "/")
|
||||
return this.baseDirectory + "/" + migration;
|
||||
return migration;
|
||||
});
|
||||
Object.assign(connectionOptions, { migrations: migrations });
|
||||
}
|
||||
// make database path file in sqlite relative to package.json
|
||||
if (options.type === "sqlite" ||
|
||||
options.type === "better-sqlite3") {
|
||||
if (typeof options.database === "string" &&
|
||||
!isAbsolute(options.database) &&
|
||||
options.database.substr(0, 1) !== "/" && // unix absolute
|
||||
options.database.substr(1, 2) !== ":\\" && // windows absolute
|
||||
options.database !== ":memory:") {
|
||||
Object.assign(options, {
|
||||
database: this.baseDirectory + "/" + options.database,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return connectionOptions;
|
||||
}
|
||||
/**
|
||||
* Gets directory where configuration file should be located and configuration file name.
|
||||
*/
|
||||
get baseFilePath() {
|
||||
return path.resolve(this.baseDirectory, this.baseConfigName);
|
||||
}
|
||||
/**
|
||||
* Gets directory where configuration file should be located.
|
||||
*/
|
||||
get baseDirectory() {
|
||||
if (this.options && this.options.root)
|
||||
return this.options.root;
|
||||
return appRootPath.path;
|
||||
}
|
||||
/**
|
||||
* Gets configuration file name.
|
||||
*/
|
||||
get baseConfigName() {
|
||||
if (this.options && this.options.configName)
|
||||
return this.options.configName;
|
||||
return "ormconfig";
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionOptionsReader.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,30 +0,0 @@
|
||||
import { DataSourceOptions } from "../../data-source/DataSourceOptions";
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
* Environment variables can have only a single connection.
|
||||
* Its strongly required to define TYPEORM_CONNECTION env variable.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare class ConnectionOptionsEnvReader {
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
*/
|
||||
read(): Promise<DataSourceOptions[]>;
|
||||
/**
|
||||
* Transforms logging string into real logging value connection requires.
|
||||
*/
|
||||
protected transformLogging(logging: string): any;
|
||||
/**
|
||||
* Transforms caching option into real caching value option requires.
|
||||
*/
|
||||
protected transformCaching(): boolean | object | undefined;
|
||||
/**
|
||||
* Converts a string which contains multiple elements split by comma into a string array of strings.
|
||||
*/
|
||||
protected stringToArray(variable?: string): string[];
|
||||
/**
|
||||
* Converts a string which contains a number into a javascript number
|
||||
*/
|
||||
private stringToNumber;
|
||||
}
|
||||
@ -1,107 +0,0 @@
|
||||
import { PlatformTools } from "../../platform/PlatformTools";
|
||||
import { OrmUtils } from "../../util/OrmUtils";
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
* Environment variables can have only a single connection.
|
||||
* Its strongly required to define TYPEORM_CONNECTION env variable.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export class ConnectionOptionsEnvReader {
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Reads connection options from environment variables.
|
||||
*/
|
||||
async read() {
|
||||
return [
|
||||
{
|
||||
type: PlatformTools.getEnvVariable("TYPEORM_CONNECTION") ||
|
||||
(PlatformTools.getEnvVariable("TYPEORM_URL")
|
||||
? PlatformTools.getEnvVariable("TYPEORM_URL").split("://")[0]
|
||||
: undefined),
|
||||
url: PlatformTools.getEnvVariable("TYPEORM_URL"),
|
||||
host: PlatformTools.getEnvVariable("TYPEORM_HOST"),
|
||||
port: this.stringToNumber(PlatformTools.getEnvVariable("TYPEORM_PORT")),
|
||||
username: PlatformTools.getEnvVariable("TYPEORM_USERNAME"),
|
||||
password: PlatformTools.getEnvVariable("TYPEORM_PASSWORD"),
|
||||
database: PlatformTools.getEnvVariable("TYPEORM_DATABASE"),
|
||||
sid: PlatformTools.getEnvVariable("TYPEORM_SID"),
|
||||
schema: PlatformTools.getEnvVariable("TYPEORM_SCHEMA"),
|
||||
extra: PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA")
|
||||
? JSON.parse(PlatformTools.getEnvVariable("TYPEORM_DRIVER_EXTRA"))
|
||||
: undefined,
|
||||
synchronize: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_SYNCHRONIZE")),
|
||||
dropSchema: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_DROP_SCHEMA")),
|
||||
migrationsRun: OrmUtils.toBoolean(PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_RUN")),
|
||||
entities: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_ENTITIES")),
|
||||
migrations: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS")),
|
||||
migrationsTableName: PlatformTools.getEnvVariable("TYPEORM_MIGRATIONS_TABLE_NAME"),
|
||||
metadataTableName: PlatformTools.getEnvVariable("TYPEORM_METADATA_TABLE_NAME"),
|
||||
subscribers: this.stringToArray(PlatformTools.getEnvVariable("TYPEORM_SUBSCRIBERS")),
|
||||
logging: this.transformLogging(PlatformTools.getEnvVariable("TYPEORM_LOGGING")),
|
||||
logger: PlatformTools.getEnvVariable("TYPEORM_LOGGER"),
|
||||
entityPrefix: PlatformTools.getEnvVariable("TYPEORM_ENTITY_PREFIX"),
|
||||
maxQueryExecutionTime: PlatformTools.getEnvVariable("TYPEORM_MAX_QUERY_EXECUTION_TIME"),
|
||||
debug: PlatformTools.getEnvVariable("TYPEORM_DEBUG"),
|
||||
cache: this.transformCaching(),
|
||||
uuidExtension: PlatformTools.getEnvVariable("TYPEORM_UUID_EXTENSION"),
|
||||
},
|
||||
];
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Transforms logging string into real logging value connection requires.
|
||||
*/
|
||||
transformLogging(logging) {
|
||||
if (logging === "true" || logging === "TRUE" || logging === "1")
|
||||
return true;
|
||||
if (logging === "all")
|
||||
return "all";
|
||||
return this.stringToArray(logging);
|
||||
}
|
||||
/**
|
||||
* Transforms caching option into real caching value option requires.
|
||||
*/
|
||||
transformCaching() {
|
||||
const caching = PlatformTools.getEnvVariable("TYPEORM_CACHE");
|
||||
if (caching === "true" || caching === "TRUE" || caching === "1")
|
||||
return true;
|
||||
if (caching === "false" || caching === "FALSE" || caching === "0")
|
||||
return false;
|
||||
if (caching === "redis" ||
|
||||
caching === "ioredis" ||
|
||||
caching === "database")
|
||||
return {
|
||||
type: caching,
|
||||
options: PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS")
|
||||
? JSON.parse(PlatformTools.getEnvVariable("TYPEORM_CACHE_OPTIONS"))
|
||||
: undefined,
|
||||
alwaysEnabled: PlatformTools.getEnvVariable("TYPEORM_CACHE_ALWAYS_ENABLED"),
|
||||
duration: parseInt(PlatformTools.getEnvVariable("TYPEORM_CACHE_DURATION")),
|
||||
};
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Converts a string which contains multiple elements split by comma into a string array of strings.
|
||||
*/
|
||||
stringToArray(variable) {
|
||||
if (!variable)
|
||||
return [];
|
||||
return variable.split(",").map((str) => str.trim());
|
||||
}
|
||||
/**
|
||||
* Converts a string which contains a number into a javascript number
|
||||
*/
|
||||
stringToNumber(value) {
|
||||
if (!value) {
|
||||
return undefined;
|
||||
}
|
||||
return parseInt(value);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=ConnectionOptionsEnvReader.js.map
|
||||
File diff suppressed because one or more lines are too long
39
cool/package/typeorm/browser/container.d.ts
vendored
39
cool/package/typeorm/browser/container.d.ts
vendored
@ -1,39 +0,0 @@
|
||||
/**
|
||||
* Container options.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export interface UseContainerOptions {
|
||||
/**
|
||||
* If set to true, then default container will be used in the case if given container haven't returned anything.
|
||||
*/
|
||||
fallback?: boolean;
|
||||
/**
|
||||
* If set to true, then default container will be used in the case if given container thrown an exception.
|
||||
*/
|
||||
fallbackOnErrors?: boolean;
|
||||
}
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export type ContainedType<T> = {
|
||||
new (...args: any[]): T;
|
||||
} | Function;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
export interface ContainerInterface {
|
||||
get<T>(someClass: ContainedType<T>): T;
|
||||
}
|
||||
/**
|
||||
* Sets container to be used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare function useContainer(iocContainer: ContainerInterface, options?: UseContainerOptions): void;
|
||||
/**
|
||||
* Gets the IOC container used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export declare function getFromContainer<T>(someClass: ContainedType<T>): T;
|
||||
@ -1,56 +0,0 @@
|
||||
/**
|
||||
* Container to be used by this library for inversion control. If container was not implicitly set then by default
|
||||
* container simply creates a new instance of the given class.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
const defaultContainer = new (class {
|
||||
constructor() {
|
||||
this.instances = [];
|
||||
}
|
||||
get(someClass) {
|
||||
let instance = this.instances.find((i) => i.type === someClass);
|
||||
if (!instance) {
|
||||
instance = {
|
||||
type: someClass,
|
||||
object: new someClass(),
|
||||
};
|
||||
this.instances.push(instance);
|
||||
}
|
||||
return instance.object;
|
||||
}
|
||||
})();
|
||||
let userContainer;
|
||||
let userContainerOptions;
|
||||
/**
|
||||
* Sets container to be used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function useContainer(iocContainer, options) {
|
||||
userContainer = iocContainer;
|
||||
userContainerOptions = options;
|
||||
}
|
||||
/**
|
||||
* Gets the IOC container used by this library.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
export function getFromContainer(someClass) {
|
||||
if (userContainer) {
|
||||
try {
|
||||
const instance = userContainer.get(someClass);
|
||||
if (instance)
|
||||
return instance;
|
||||
if (!userContainerOptions || !userContainerOptions.fallback)
|
||||
return instance;
|
||||
}
|
||||
catch (error) {
|
||||
if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return defaultContainer.get(someClass);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=container.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/container.ts"],"names":[],"mappings":"AA6BA;;;;;GAKG;AACH,MAAM,gBAAgB,GAAuB,IAAI,CAAC;IAAA;QAGtC,cAAS,GAAsC,EAAE,CAAA;IAc7D,CAAC;IAZG,GAAG,CAAI,SAA2B;QAC9B,IAAI,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;QAC/D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,QAAQ,GAAG;gBACP,IAAI,EAAE,SAAS;gBACf,MAAM,EAAE,IAAK,SAAyB,EAAE;aAC3C,CAAA;YACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACjC,CAAC;QAED,OAAO,QAAQ,CAAC,MAAM,CAAA;IAC1B,CAAC;CACJ,CAAC,EAAE,CAAA;AAEJ,IAAI,aAAiC,CAAA;AACrC,IAAI,oBAAqD,CAAA;AAEzD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CACxB,YAAgC,EAChC,OAA6B;IAE7B,aAAa,GAAG,YAAY,CAAA;IAC5B,oBAAoB,GAAG,OAAO,CAAA;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAI,SAA2B;IAC3D,IAAI,aAAa,EAAE,CAAC;QAChB,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7C,IAAI,QAAQ;gBAAE,OAAO,QAAQ,CAAA;YAE7B,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,QAAQ;gBACvD,OAAO,QAAQ,CAAA;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,oBAAoB,IAAI,CAAC,oBAAoB,CAAC,gBAAgB;gBAC/D,MAAM,KAAK,CAAA;QACnB,CAAC;IACL,CAAC;IACD,OAAO,gBAAgB,CAAC,GAAG,CAAI,SAAS,CAAC,CAAA;AAC7C,CAAC","file":"container.js","sourcesContent":["/**\n * Container options.\n *\n * @deprecated\n */\nexport interface UseContainerOptions {\n /**\n * If set to true, then default container will be used in the case if given container haven't returned anything.\n */\n fallback?: boolean\n\n /**\n * If set to true, then default container will be used in the case if given container thrown an exception.\n */\n fallbackOnErrors?: boolean\n}\n\n/**\n * @deprecated\n */\nexport type ContainedType<T> = { new (...args: any[]): T } | Function\n\n/**\n * @deprecated\n */\nexport interface ContainerInterface {\n get<T>(someClass: ContainedType<T>): T\n}\n\n/**\n * Container to be used by this library for inversion control. If container was not implicitly set then by default\n * container simply creates a new instance of the given class.\n *\n * @deprecated\n */\nconst defaultContainer: ContainerInterface = new (class\n implements ContainerInterface\n{\n private instances: { type: Function; object: any }[] = []\n\n get<T>(someClass: ContainedType<T>): T {\n let instance = this.instances.find((i) => i.type === someClass)\n if (!instance) {\n instance = {\n type: someClass,\n object: new (someClass as new () => T)(),\n }\n this.instances.push(instance)\n }\n\n return instance.object\n }\n})()\n\nlet userContainer: ContainerInterface\nlet userContainerOptions: UseContainerOptions | undefined\n\n/**\n * Sets container to be used by this library.\n *\n * @deprecated\n */\nexport function useContainer(\n iocContainer: ContainerInterface,\n options?: UseContainerOptions,\n) {\n userContainer = iocContainer\n userContainerOptions = options\n}\n\n/**\n * Gets the IOC container used by this library.\n *\n * @deprecated\n */\nexport function getFromContainer<T>(someClass: ContainedType<T>): T {\n if (userContainer) {\n try {\n const instance = userContainer.get(someClass)\n if (instance) return instance\n\n if (!userContainerOptions || !userContainerOptions.fallback)\n return instance\n } catch (error) {\n if (!userContainerOptions || !userContainerOptions.fallbackOnErrors)\n throw error\n }\n }\n return defaultContainer.get<T>(someClass)\n}\n"],"sourceRoot":"."}
|
||||
@ -1,169 +0,0 @@
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
import { LoggerOptions } from "../logger/LoggerOptions";
|
||||
import { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface";
|
||||
import { DatabaseType } from "../driver/types/DatabaseType";
|
||||
import { Logger } from "../logger/Logger";
|
||||
import { DataSource } from "../data-source/DataSource";
|
||||
import { QueryResultCache } from "../cache/QueryResultCache";
|
||||
import { MixedList } from "../common/MixedList";
|
||||
/**
|
||||
* BaseDataSourceOptions is set of DataSourceOptions shared by all database types.
|
||||
*/
|
||||
export interface BaseDataSourceOptions {
|
||||
/**
|
||||
* Database type. This value is required.
|
||||
*/
|
||||
readonly type: DatabaseType;
|
||||
/**
|
||||
* Connection name. If connection name is not given then it will be called "default".
|
||||
* Different connections must have different names.
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
readonly name?: string;
|
||||
/**
|
||||
* Entities to be loaded for this connection.
|
||||
* Accepts both entity classes and directories where from entities need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly entities?: MixedList<Function | string | EntitySchema>;
|
||||
/**
|
||||
* Subscribers to be loaded for this connection.
|
||||
* Accepts both subscriber classes and directories where from subscribers need to be loaded.
|
||||
* Directories support glob patterns.
|
||||
*/
|
||||
readonly subscribers?: MixedList<Function | string>;
|
||||
/**
|
||||
* Migrations to be loaded for this connection.
|
||||
* Accepts both migration classes and glob patterns representing migration files.
|
||||
*/
|
||||
readonly migrations?: MixedList<Function | string>;
|
||||
/**
|
||||
* Migrations table name, in case of different name from "migrations".
|
||||
* Accepts single string name.
|
||||
*/
|
||||
readonly migrationsTableName?: string;
|
||||
/**
|
||||
* Transaction mode for migrations to run in
|
||||
*/
|
||||
readonly migrationsTransactionMode?: "all" | "none" | "each";
|
||||
/**
|
||||
* Typeorm metadata table name, in case of different name from "typeorm_metadata".
|
||||
* Accepts single string name.
|
||||
*/
|
||||
readonly metadataTableName?: string;
|
||||
/**
|
||||
* Naming strategy to be used to name tables and columns in the database.
|
||||
*/
|
||||
readonly namingStrategy?: NamingStrategyInterface;
|
||||
/**
|
||||
* Logging options.
|
||||
*/
|
||||
readonly logging?: LoggerOptions;
|
||||
/**
|
||||
* Logger instance used to log queries and events in the ORM.
|
||||
*/
|
||||
readonly logger?: "advanced-console" | "simple-console" | "file" | "debug" | Logger;
|
||||
/**
|
||||
* Maximum number of milliseconds query should be executed before logger log a warning.
|
||||
*/
|
||||
readonly maxQueryExecutionTime?: number;
|
||||
/**
|
||||
* Maximum number of clients the pool should contain.
|
||||
*/
|
||||
readonly poolSize?: number;
|
||||
/**
|
||||
* Indicates if database schema should be auto created on every application launch.
|
||||
* Be careful with this option and don't use this in production - otherwise you can lose production data.
|
||||
* This option is useful during debug and development.
|
||||
* Alternative to it, you can use CLI and run schema:sync command.
|
||||
*
|
||||
* Note that for MongoDB database it does not create schema, because MongoDB is schemaless.
|
||||
* Instead, it syncs just by creating indices.
|
||||
*/
|
||||
readonly synchronize?: boolean;
|
||||
/**
|
||||
* Indicates if migrations should be auto run on every application launch.
|
||||
* Alternative to it, you can use CLI and run migrations:run command.
|
||||
*/
|
||||
readonly migrationsRun?: boolean;
|
||||
/**
|
||||
* Drops the schema each time connection is being established.
|
||||
* Be careful with this option and don't use this in production - otherwise you'll lose all production data.
|
||||
* This option is useful during debug and development.
|
||||
*/
|
||||
readonly dropSchema?: boolean;
|
||||
/**
|
||||
* Prefix to use on all tables (collections) of this connection in the database.
|
||||
*/
|
||||
readonly entityPrefix?: string;
|
||||
/**
|
||||
* When creating new Entity instances, skip all constructors when true.
|
||||
*/
|
||||
readonly entitySkipConstructor?: boolean;
|
||||
/**
|
||||
* Extra connection options to be passed to the underlying driver.
|
||||
*
|
||||
* todo: deprecate this and move all database-specific types into hts own connection options object.
|
||||
*/
|
||||
readonly extra?: any;
|
||||
/**
|
||||
* Specifies how relations must be loaded - using "joins" or separate queries.
|
||||
* If you are loading too much data with nested joins it's better to load relations
|
||||
* using separate queries.
|
||||
*
|
||||
* Default strategy is "join", but this default can be changed here.
|
||||
* Also, strategy can be set per-query in FindOptions and QueryBuilder.
|
||||
*/
|
||||
readonly relationLoadStrategy?: "join" | "query";
|
||||
/**
|
||||
* Optionally applied "typename" to the model.
|
||||
* If set, then each hydrated model will have this property with the target model / entity name inside.
|
||||
*
|
||||
* (works like a discriminator property).
|
||||
*/
|
||||
readonly typename?: string;
|
||||
/**
|
||||
* Allows to setup cache options.
|
||||
*/
|
||||
readonly cache?: boolean | {
|
||||
/**
|
||||
* Type of caching.
|
||||
*
|
||||
* - "database" means cached values will be stored in the separate table in database. This is default value.
|
||||
* - "redis" means cached values will be stored inside redis. You must provide redis connection options.
|
||||
*/
|
||||
readonly type?: "database" | "redis" | "ioredis" | "ioredis/cluster";
|
||||
/**
|
||||
* Factory function for custom cache providers that implement QueryResultCache.
|
||||
*/
|
||||
readonly provider?: (connection: DataSource) => QueryResultCache;
|
||||
/**
|
||||
* Configurable table name for "database" type cache.
|
||||
* Default value is "query-result-cache"
|
||||
*/
|
||||
readonly tableName?: string;
|
||||
/**
|
||||
* Used to provide redis connection options.
|
||||
*/
|
||||
readonly options?: any;
|
||||
/**
|
||||
* If set to true then queries (using find methods and QueryBuilder's methods) will always be cached.
|
||||
*/
|
||||
readonly alwaysEnabled?: boolean;
|
||||
/**
|
||||
* Time in milliseconds in which cache will expire.
|
||||
* This can be setup per-query.
|
||||
* Default value is 1000 which is equivalent to 1 second.
|
||||
*/
|
||||
readonly duration?: number;
|
||||
/**
|
||||
* Used to specify if cache errors should be ignored, and pass through the call to the Database.
|
||||
*/
|
||||
readonly ignoreErrors?: boolean;
|
||||
};
|
||||
/**
|
||||
* Allows automatic isolation of where clauses
|
||||
*/
|
||||
readonly isolateWhereStatements?: boolean;
|
||||
}
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=BaseDataSourceOptions.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,258 +0,0 @@
|
||||
import { Driver } from "../driver/Driver";
|
||||
import { Repository } from "../repository/Repository";
|
||||
import { EntitySubscriberInterface } from "../subscriber/EntitySubscriberInterface";
|
||||
import { EntityTarget } from "../common/EntityTarget";
|
||||
import { ObjectType } from "../common/ObjectType";
|
||||
import { EntityManager } from "../entity-manager/EntityManager";
|
||||
import { TreeRepository } from "../repository/TreeRepository";
|
||||
import { NamingStrategyInterface } from "../naming-strategy/NamingStrategyInterface";
|
||||
import { EntityMetadata } from "../metadata/EntityMetadata";
|
||||
import { Logger } from "../logger/Logger";
|
||||
import { MigrationInterface } from "../migration/MigrationInterface";
|
||||
import { Migration } from "../migration/Migration";
|
||||
import { MongoRepository } from "../repository/MongoRepository";
|
||||
import { MongoEntityManager } from "../entity-manager/MongoEntityManager";
|
||||
import { DataSourceOptions } from "./DataSourceOptions";
|
||||
import { QueryRunner } from "../query-runner/QueryRunner";
|
||||
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
|
||||
import { QueryResultCache } from "../cache/QueryResultCache";
|
||||
import { SqljsEntityManager } from "../entity-manager/SqljsEntityManager";
|
||||
import { RelationLoader } from "../query-builder/RelationLoader";
|
||||
import { IsolationLevel } from "../driver/types/IsolationLevel";
|
||||
import { ReplicationMode } from "../driver/types/ReplicationMode";
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader";
|
||||
import { ObjectLiteral } from "../common/ObjectLiteral";
|
||||
/**
|
||||
* DataSource is a pre-defined connection configuration to a specific database.
|
||||
* You can have multiple data sources connected (with multiple connections in it),
|
||||
* connected to multiple databases in your application.
|
||||
*
|
||||
* Before, it was called `Connection`, but now `Connection` is deprecated
|
||||
* because `Connection` isn't the best name for what it's actually is.
|
||||
*/
|
||||
export declare class DataSource {
|
||||
readonly "@instanceof": symbol;
|
||||
/**
|
||||
* Connection name.
|
||||
*
|
||||
* @deprecated we don't need names anymore since we are going to drop all related methods relying on this property.
|
||||
*/
|
||||
readonly name: string;
|
||||
/**
|
||||
* Connection options.
|
||||
*/
|
||||
readonly options: DataSourceOptions;
|
||||
/**
|
||||
* Indicates if DataSource is initialized or not.
|
||||
*/
|
||||
readonly isInitialized: boolean;
|
||||
/**
|
||||
* Database driver used by this connection.
|
||||
*/
|
||||
driver: Driver;
|
||||
/**
|
||||
* EntityManager of this connection.
|
||||
*/
|
||||
readonly manager: EntityManager;
|
||||
/**
|
||||
* Naming strategy used in the connection.
|
||||
*/
|
||||
namingStrategy: NamingStrategyInterface;
|
||||
/**
|
||||
* Name for the metadata table
|
||||
*/
|
||||
readonly metadataTableName: string;
|
||||
/**
|
||||
* Logger used to log orm events.
|
||||
*/
|
||||
logger: Logger;
|
||||
/**
|
||||
* Migration instances that are registered for this connection.
|
||||
*/
|
||||
readonly migrations: MigrationInterface[];
|
||||
/**
|
||||
* Entity subscriber instances that are registered for this connection.
|
||||
*/
|
||||
readonly subscribers: EntitySubscriberInterface<any>[];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
*/
|
||||
readonly entityMetadatas: EntityMetadata[];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
* This is a copy of #.entityMetadatas property -> used for more performant searches.
|
||||
*/
|
||||
readonly entityMetadatasMap: Map<EntityTarget<any>, EntityMetadata>;
|
||||
/**
|
||||
* Used to work with query result cache.
|
||||
*/
|
||||
queryResultCache?: QueryResultCache;
|
||||
/**
|
||||
* Used to load relations and work with lazy relations.
|
||||
*/
|
||||
readonly relationLoader: RelationLoader;
|
||||
readonly relationIdLoader: RelationIdLoader;
|
||||
constructor(options: DataSourceOptions);
|
||||
/**
|
||||
Indicates if DataSource is initialized or not.
|
||||
*
|
||||
* @deprecated use .isInitialized instead
|
||||
*/
|
||||
get isConnected(): boolean;
|
||||
/**
|
||||
* Gets the mongodb entity manager that allows to perform mongodb-specific repository operations
|
||||
* with any entity in this connection.
|
||||
*
|
||||
* Available only in mongodb connections.
|
||||
*/
|
||||
get mongoManager(): MongoEntityManager;
|
||||
/**
|
||||
* Gets a sql.js specific Entity Manager that allows to perform special load and save operations
|
||||
*
|
||||
* Available only in connection with the sqljs driver.
|
||||
*/
|
||||
get sqljsManager(): SqljsEntityManager;
|
||||
/**
|
||||
* Updates current connection options with provided options.
|
||||
*/
|
||||
setOptions(options: Partial<DataSourceOptions>): this;
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*/
|
||||
initialize(): Promise<this>;
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*
|
||||
* @deprecated use .initialize method instead
|
||||
*/
|
||||
connect(): Promise<this>;
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*/
|
||||
destroy(): Promise<void>;
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*
|
||||
* @deprecated use .destroy method instead
|
||||
*/
|
||||
close(): Promise<void>;
|
||||
/**
|
||||
* Creates database schema for all entities registered in this connection.
|
||||
* Can be used only after connection to the database is established.
|
||||
*
|
||||
* @param dropBeforeSync If set to true then it drops the database with all its tables and data
|
||||
*/
|
||||
synchronize(dropBeforeSync?: boolean): Promise<void>;
|
||||
/**
|
||||
* Drops the database and all its data.
|
||||
* Be careful with this method on production since this method will erase all your database tables and their data.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
dropDatabase(): Promise<void>;
|
||||
/**
|
||||
* Runs all pending migrations.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
runMigrations(options?: {
|
||||
transaction?: "all" | "none" | "each";
|
||||
fake?: boolean;
|
||||
}): Promise<Migration[]>;
|
||||
/**
|
||||
* Reverts last executed migration.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
undoLastMigration(options?: {
|
||||
transaction?: "all" | "none" | "each";
|
||||
fake?: boolean;
|
||||
}): Promise<void>;
|
||||
/**
|
||||
* Lists all migrations and whether they have been run.
|
||||
* Returns true if there are pending migrations
|
||||
*/
|
||||
showMigrations(): Promise<boolean>;
|
||||
/**
|
||||
* Checks if entity metadata exist for the given entity class, target name or table name.
|
||||
*/
|
||||
hasMetadata(target: EntityTarget<any>): boolean;
|
||||
/**
|
||||
* Gets entity metadata for the given entity class or schema name.
|
||||
*/
|
||||
getMetadata(target: EntityTarget<any>): EntityMetadata;
|
||||
/**
|
||||
* Gets repository for the given entity.
|
||||
*/
|
||||
getRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): Repository<Entity>;
|
||||
/**
|
||||
* Gets tree repository for the given entity class or name.
|
||||
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
|
||||
*/
|
||||
getTreeRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): TreeRepository<Entity>;
|
||||
/**
|
||||
* Gets mongodb-specific repository for the given entity class or name.
|
||||
* Works only if connection is mongodb-specific.
|
||||
*/
|
||||
getMongoRepository<Entity extends ObjectLiteral>(target: EntityTarget<Entity>): MongoRepository<Entity>;
|
||||
/**
|
||||
* Gets custom entity repository marked with @EntityRepository decorator.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
getCustomRepository<T>(customRepository: ObjectType<T>): T;
|
||||
/**
|
||||
* Wraps given function execution (and all operations made there) into a transaction.
|
||||
* All database operations must be executed using provided entity manager.
|
||||
*/
|
||||
transaction<T>(runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
|
||||
transaction<T>(isolationLevel: IsolationLevel, runInTransaction: (entityManager: EntityManager) => Promise<T>): Promise<T>;
|
||||
/**
|
||||
* Executes raw SQL query and returns raw database results.
|
||||
*/
|
||||
query<T = any>(query: string, parameters?: any[], queryRunner?: QueryRunner): Promise<T>;
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder<Entity extends ObjectLiteral>(entityClass: EntityTarget<Entity>, alias: string, queryRunner?: QueryRunner): SelectQueryBuilder<Entity>;
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder(queryRunner?: QueryRunner): SelectQueryBuilder<any>;
|
||||
/**
|
||||
* Creates a query runner used for perform queries on a single database connection.
|
||||
* Using query runners you can control your queries to execute using single database connection and
|
||||
* manually control your database transaction.
|
||||
*
|
||||
* Mode is used in replication mode and indicates whatever you want to connect
|
||||
* to master database or any of slave databases.
|
||||
* If you perform writes you must use master database,
|
||||
* if you perform reads you can use slave databases.
|
||||
*/
|
||||
createQueryRunner(mode?: ReplicationMode): QueryRunner;
|
||||
/**
|
||||
* Gets entity metadata of the junction table (many-to-many table).
|
||||
*/
|
||||
getManyToManyMetadata(entityTarget: EntityTarget<any>, relationPropertyPath: string): EntityMetadata | undefined;
|
||||
/**
|
||||
* Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.
|
||||
*/
|
||||
createEntityManager(queryRunner?: QueryRunner): EntityManager;
|
||||
/**
|
||||
* Finds exist entity metadata by the given entity class, target name or table name.
|
||||
*/
|
||||
protected findMetadata(target: EntityTarget<any>): EntityMetadata | undefined;
|
||||
/**
|
||||
* Builds metadatas for all registered classes inside this connection.
|
||||
*/
|
||||
protected buildMetadatas(): Promise<void>;
|
||||
/**
|
||||
* Get the replication mode SELECT queries should use for this datasource by default
|
||||
*/
|
||||
defaultReplicationModeForReads(): ReplicationMode;
|
||||
}
|
||||
@ -1,494 +0,0 @@
|
||||
import { registerQueryBuilders } from "../query-builder";
|
||||
import { DefaultNamingStrategy } from "../naming-strategy/DefaultNamingStrategy";
|
||||
import { CannotConnectAlreadyConnectedError, CannotExecuteNotConnectedError, EntityMetadataNotFoundError, QueryRunnerProviderAlreadyReleasedError, TypeORMError, } from "../error";
|
||||
import { MigrationExecutor } from "../migration/MigrationExecutor";
|
||||
import { EntityMetadataValidator } from "../metadata-builder/EntityMetadataValidator";
|
||||
import { EntityManagerFactory } from "../entity-manager/EntityManagerFactory";
|
||||
import { DriverFactory } from "../driver/DriverFactory";
|
||||
import { ConnectionMetadataBuilder } from "../connection/ConnectionMetadataBuilder";
|
||||
import { SelectQueryBuilder } from "../query-builder/SelectQueryBuilder";
|
||||
import { LoggerFactory } from "../logger/LoggerFactory";
|
||||
import { QueryResultCacheFactory } from "../cache/QueryResultCacheFactory";
|
||||
import { RelationLoader } from "../query-builder/RelationLoader";
|
||||
import { ObjectUtils } from "../util/ObjectUtils";
|
||||
import { RelationIdLoader } from "../query-builder/RelationIdLoader";
|
||||
import { DriverUtils } from "../driver/DriverUtils";
|
||||
import { InstanceChecker } from "../util/InstanceChecker";
|
||||
registerQueryBuilders();
|
||||
/**
|
||||
* DataSource is a pre-defined connection configuration to a specific database.
|
||||
* You can have multiple data sources connected (with multiple connections in it),
|
||||
* connected to multiple databases in your application.
|
||||
*
|
||||
* Before, it was called `Connection`, but now `Connection` is deprecated
|
||||
* because `Connection` isn't the best name for what it's actually is.
|
||||
*/
|
||||
export class DataSource {
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructor
|
||||
// -------------------------------------------------------------------------
|
||||
constructor(options) {
|
||||
this["@instanceof"] = Symbol.for("DataSource");
|
||||
/**
|
||||
* Migration instances that are registered for this connection.
|
||||
*/
|
||||
this.migrations = [];
|
||||
/**
|
||||
* Entity subscriber instances that are registered for this connection.
|
||||
*/
|
||||
this.subscribers = [];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
*/
|
||||
this.entityMetadatas = [];
|
||||
/**
|
||||
* All entity metadatas that are registered for this connection.
|
||||
* This is a copy of #.entityMetadatas property -> used for more performant searches.
|
||||
*/
|
||||
this.entityMetadatasMap = new Map();
|
||||
registerQueryBuilders();
|
||||
this.name = options.name || "default";
|
||||
this.options = options;
|
||||
this.logger = new LoggerFactory().create(this.options.logger, this.options.logging);
|
||||
this.driver = new DriverFactory().create(this);
|
||||
this.manager = this.createEntityManager();
|
||||
this.namingStrategy =
|
||||
options.namingStrategy || new DefaultNamingStrategy();
|
||||
this.metadataTableName = options.metadataTableName || "typeorm_metadata";
|
||||
this.queryResultCache = options.cache
|
||||
? new QueryResultCacheFactory(this).create()
|
||||
: undefined;
|
||||
this.relationLoader = new RelationLoader(this);
|
||||
this.relationIdLoader = new RelationIdLoader(this);
|
||||
this.isInitialized = false;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Accessors
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
Indicates if DataSource is initialized or not.
|
||||
*
|
||||
* @deprecated use .isInitialized instead
|
||||
*/
|
||||
get isConnected() {
|
||||
return this.isInitialized;
|
||||
}
|
||||
/**
|
||||
* Gets the mongodb entity manager that allows to perform mongodb-specific repository operations
|
||||
* with any entity in this connection.
|
||||
*
|
||||
* Available only in mongodb connections.
|
||||
*/
|
||||
get mongoManager() {
|
||||
if (!InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`MongoEntityManager is only available for MongoDB databases.`);
|
||||
return this.manager;
|
||||
}
|
||||
/**
|
||||
* Gets a sql.js specific Entity Manager that allows to perform special load and save operations
|
||||
*
|
||||
* Available only in connection with the sqljs driver.
|
||||
*/
|
||||
get sqljsManager() {
|
||||
if (!InstanceChecker.isSqljsEntityManager(this.manager))
|
||||
throw new TypeORMError(`SqljsEntityManager is only available for Sqljs databases.`);
|
||||
return this.manager;
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Public Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Updates current connection options with provided options.
|
||||
*/
|
||||
setOptions(options) {
|
||||
Object.assign(this.options, options);
|
||||
if (options.logger || options.logging) {
|
||||
this.logger = new LoggerFactory().create(options.logger || this.options.logger, options.logging || this.options.logging);
|
||||
}
|
||||
if (options.namingStrategy) {
|
||||
this.namingStrategy = options.namingStrategy;
|
||||
}
|
||||
if (options.cache) {
|
||||
this.queryResultCache = new QueryResultCacheFactory(this).create();
|
||||
}
|
||||
// todo: we must update the database in the driver as well, if it was set by setOptions method
|
||||
// in the future we need to refactor the code and remove "database" from the driver, and instead
|
||||
// use database (and options) from a single place - data source.
|
||||
if (options.database) {
|
||||
this.driver.database = DriverUtils.buildDriverOptions(this.options).database;
|
||||
}
|
||||
// todo: need to take a look if we need to update schema and other "poor" properties
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*/
|
||||
async initialize() {
|
||||
if (this.isInitialized)
|
||||
throw new CannotConnectAlreadyConnectedError(this.name);
|
||||
// connect to the database via its driver
|
||||
await this.driver.connect();
|
||||
// connect to the cache-specific database if cache is enabled
|
||||
if (this.queryResultCache)
|
||||
await this.queryResultCache.connect();
|
||||
// set connected status for the current connection
|
||||
ObjectUtils.assign(this, { isInitialized: true });
|
||||
try {
|
||||
// build all metadatas registered in the current connection
|
||||
await this.buildMetadatas();
|
||||
await this.driver.afterConnect();
|
||||
// if option is set - drop schema once connection is done
|
||||
if (this.options.dropSchema)
|
||||
await this.dropDatabase();
|
||||
// if option is set - automatically synchronize a schema
|
||||
if (this.options.migrationsRun)
|
||||
await this.runMigrations({
|
||||
transaction: this.options.migrationsTransactionMode,
|
||||
});
|
||||
// if option is set - automatically synchronize a schema
|
||||
if (this.options.synchronize)
|
||||
await this.synchronize();
|
||||
}
|
||||
catch (error) {
|
||||
// if for some reason build metadata fail (for example validation error during entity metadata check)
|
||||
// connection needs to be closed
|
||||
await this.destroy();
|
||||
throw error;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Performs connection to the database.
|
||||
* This method should be called once on application bootstrap.
|
||||
* This method not necessarily creates database connection (depend on database type),
|
||||
* but it also can setup a connection pool with database to use.
|
||||
*
|
||||
* @deprecated use .initialize method instead
|
||||
*/
|
||||
async connect() {
|
||||
return this.initialize();
|
||||
}
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*/
|
||||
async destroy() {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
await this.driver.disconnect();
|
||||
// disconnect from the cache-specific database if cache was enabled
|
||||
if (this.queryResultCache)
|
||||
await this.queryResultCache.disconnect();
|
||||
ObjectUtils.assign(this, { isInitialized: false });
|
||||
}
|
||||
/**
|
||||
* Closes connection with the database.
|
||||
* Once connection is closed, you cannot use repositories or perform any operations except opening connection again.
|
||||
*
|
||||
* @deprecated use .destroy method instead
|
||||
*/
|
||||
async close() {
|
||||
return this.destroy();
|
||||
}
|
||||
/**
|
||||
* Creates database schema for all entities registered in this connection.
|
||||
* Can be used only after connection to the database is established.
|
||||
*
|
||||
* @param dropBeforeSync If set to true then it drops the database with all its tables and data
|
||||
*/
|
||||
async synchronize(dropBeforeSync = false) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
if (dropBeforeSync)
|
||||
await this.dropDatabase();
|
||||
const schemaBuilder = this.driver.createSchemaBuilder();
|
||||
await schemaBuilder.build();
|
||||
}
|
||||
/**
|
||||
* Drops the database and all its data.
|
||||
* Be careful with this method on production since this method will erase all your database tables and their data.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
// TODO rename
|
||||
async dropDatabase() {
|
||||
const queryRunner = this.createQueryRunner();
|
||||
try {
|
||||
if (this.driver.options.type === "mssql" ||
|
||||
DriverUtils.isMySQLFamily(this.driver) ||
|
||||
this.driver.options.type === "aurora-mysql" ||
|
||||
DriverUtils.isSQLiteFamily(this.driver)) {
|
||||
const databases = [];
|
||||
this.entityMetadatas.forEach((metadata) => {
|
||||
if (metadata.database &&
|
||||
databases.indexOf(metadata.database) === -1)
|
||||
databases.push(metadata.database);
|
||||
});
|
||||
if (databases.length === 0 && this.driver.database) {
|
||||
databases.push(this.driver.database);
|
||||
}
|
||||
if (databases.length === 0) {
|
||||
await queryRunner.clearDatabase();
|
||||
}
|
||||
else {
|
||||
for (const database of databases) {
|
||||
await queryRunner.clearDatabase(database);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
await queryRunner.clearDatabase();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Runs all pending migrations.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
async runMigrations(options) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
migrationExecutor.transaction =
|
||||
options?.transaction ||
|
||||
this.options?.migrationsTransactionMode ||
|
||||
"all";
|
||||
migrationExecutor.fake = (options && options.fake) || false;
|
||||
const successMigrations = await migrationExecutor.executePendingMigrations();
|
||||
return successMigrations;
|
||||
}
|
||||
/**
|
||||
* Reverts last executed migration.
|
||||
* Can be used only after connection to the database is established.
|
||||
*/
|
||||
async undoLastMigration(options) {
|
||||
if (!this.isInitialized)
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
migrationExecutor.transaction =
|
||||
(options && options.transaction) || "all";
|
||||
migrationExecutor.fake = (options && options.fake) || false;
|
||||
await migrationExecutor.undoLastMigration();
|
||||
}
|
||||
/**
|
||||
* Lists all migrations and whether they have been run.
|
||||
* Returns true if there are pending migrations
|
||||
*/
|
||||
async showMigrations() {
|
||||
if (!this.isInitialized) {
|
||||
throw new CannotExecuteNotConnectedError(this.name);
|
||||
}
|
||||
const migrationExecutor = new MigrationExecutor(this);
|
||||
return await migrationExecutor.showMigrations();
|
||||
}
|
||||
/**
|
||||
* Checks if entity metadata exist for the given entity class, target name or table name.
|
||||
*/
|
||||
hasMetadata(target) {
|
||||
return !!this.findMetadata(target);
|
||||
}
|
||||
/**
|
||||
* Gets entity metadata for the given entity class or schema name.
|
||||
*/
|
||||
getMetadata(target) {
|
||||
const metadata = this.findMetadata(target);
|
||||
if (!metadata)
|
||||
throw new EntityMetadataNotFoundError(target);
|
||||
return metadata;
|
||||
}
|
||||
/**
|
||||
* Gets repository for the given entity.
|
||||
*/
|
||||
getRepository(target) {
|
||||
return this.manager.getRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets tree repository for the given entity class or name.
|
||||
* Only tree-type entities can have a TreeRepository, like ones decorated with @Tree decorator.
|
||||
*/
|
||||
getTreeRepository(target) {
|
||||
return this.manager.getTreeRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets mongodb-specific repository for the given entity class or name.
|
||||
* Works only if connection is mongodb-specific.
|
||||
*/
|
||||
getMongoRepository(target) {
|
||||
if (!(this.driver.options.type === "mongodb"))
|
||||
throw new TypeORMError(`You can use getMongoRepository only for MongoDB connections.`);
|
||||
return this.manager.getRepository(target);
|
||||
}
|
||||
/**
|
||||
* Gets custom entity repository marked with @EntityRepository decorator.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
getCustomRepository(customRepository) {
|
||||
return this.manager.getCustomRepository(customRepository);
|
||||
}
|
||||
async transaction(isolationOrRunInTransaction, runInTransactionParam) {
|
||||
return this.manager.transaction(isolationOrRunInTransaction, runInTransactionParam);
|
||||
}
|
||||
/**
|
||||
* Executes raw SQL query and returns raw database results.
|
||||
*/
|
||||
async query(query, parameters, queryRunner) {
|
||||
if (InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`Queries aren't supported by MongoDB.`);
|
||||
if (queryRunner && queryRunner.isReleased)
|
||||
throw new QueryRunnerProviderAlreadyReleasedError();
|
||||
const usedQueryRunner = queryRunner || this.createQueryRunner();
|
||||
try {
|
||||
return await usedQueryRunner.query(query, parameters); // await is needed here because we are using finally
|
||||
}
|
||||
finally {
|
||||
if (!queryRunner)
|
||||
await usedQueryRunner.release();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a new query builder that can be used to build a SQL query.
|
||||
*/
|
||||
createQueryBuilder(entityOrRunner, alias, queryRunner) {
|
||||
if (InstanceChecker.isMongoEntityManager(this.manager))
|
||||
throw new TypeORMError(`Query Builder is not supported by MongoDB.`);
|
||||
if (alias) {
|
||||
alias = DriverUtils.buildAlias(this.driver, undefined, alias);
|
||||
const metadata = this.getMetadata(entityOrRunner);
|
||||
return new SelectQueryBuilder(this, queryRunner)
|
||||
.select(alias)
|
||||
.from(metadata.target, alias);
|
||||
}
|
||||
else {
|
||||
return new SelectQueryBuilder(this, entityOrRunner);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates a query runner used for perform queries on a single database connection.
|
||||
* Using query runners you can control your queries to execute using single database connection and
|
||||
* manually control your database transaction.
|
||||
*
|
||||
* Mode is used in replication mode and indicates whatever you want to connect
|
||||
* to master database or any of slave databases.
|
||||
* If you perform writes you must use master database,
|
||||
* if you perform reads you can use slave databases.
|
||||
*/
|
||||
createQueryRunner(mode = "master") {
|
||||
const queryRunner = this.driver.createQueryRunner(mode);
|
||||
const manager = this.createEntityManager(queryRunner);
|
||||
Object.assign(queryRunner, { manager: manager });
|
||||
return queryRunner;
|
||||
}
|
||||
/**
|
||||
* Gets entity metadata of the junction table (many-to-many table).
|
||||
*/
|
||||
getManyToManyMetadata(entityTarget, relationPropertyPath) {
|
||||
const relationMetadata = this.getMetadata(entityTarget).findRelationWithPropertyPath(relationPropertyPath);
|
||||
if (!relationMetadata)
|
||||
throw new TypeORMError(`Relation "${relationPropertyPath}" was not found in ${entityTarget} entity.`);
|
||||
if (!relationMetadata.isManyToMany)
|
||||
throw new TypeORMError(`Relation "${entityTarget}#${relationPropertyPath}" does not have a many-to-many relationship.` +
|
||||
`You can use this method only on many-to-many relations.`);
|
||||
return relationMetadata.junctionEntityMetadata;
|
||||
}
|
||||
/**
|
||||
* Creates an Entity Manager for the current connection with the help of the EntityManagerFactory.
|
||||
*/
|
||||
createEntityManager(queryRunner) {
|
||||
return new EntityManagerFactory().create(this, queryRunner);
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
// Protected Methods
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Finds exist entity metadata by the given entity class, target name or table name.
|
||||
*/
|
||||
findMetadata(target) {
|
||||
const metadataFromMap = this.entityMetadatasMap.get(target);
|
||||
if (metadataFromMap)
|
||||
return metadataFromMap;
|
||||
for (let [_, metadata] of this.entityMetadatasMap) {
|
||||
if (InstanceChecker.isEntitySchema(target) &&
|
||||
metadata.name === target.options.name) {
|
||||
return metadata;
|
||||
}
|
||||
if (typeof target === "string") {
|
||||
if (target.indexOf(".") !== -1) {
|
||||
if (metadata.tablePath === target) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (metadata.name === target ||
|
||||
metadata.tableName === target) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ObjectUtils.isObjectWithName(target) &&
|
||||
typeof target.name === "string") {
|
||||
if (target.name.indexOf(".") !== -1) {
|
||||
if (metadata.tablePath === target.name) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (metadata.name === target.name ||
|
||||
metadata.tableName === target.name) {
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
/**
|
||||
* Builds metadatas for all registered classes inside this connection.
|
||||
*/
|
||||
async buildMetadatas() {
|
||||
const connectionMetadataBuilder = new ConnectionMetadataBuilder(this);
|
||||
const entityMetadataValidator = new EntityMetadataValidator();
|
||||
// create subscribers instances if they are not disallowed from high-level (for example they can disallowed from migrations run process)
|
||||
const flattenedSubscribers = ObjectUtils.mixedListToArray(this.options.subscribers || []);
|
||||
const subscribers = await connectionMetadataBuilder.buildSubscribers(flattenedSubscribers);
|
||||
ObjectUtils.assign(this, { subscribers: subscribers });
|
||||
// build entity metadatas
|
||||
const flattenedEntities = ObjectUtils.mixedListToArray(this.options.entities || []);
|
||||
const entityMetadatas = await connectionMetadataBuilder.buildEntityMetadatas(flattenedEntities);
|
||||
ObjectUtils.assign(this, {
|
||||
entityMetadatas: entityMetadatas,
|
||||
entityMetadatasMap: new Map(entityMetadatas.map((metadata) => [metadata.target, metadata])),
|
||||
});
|
||||
// create migration instances
|
||||
const flattenedMigrations = ObjectUtils.mixedListToArray(this.options.migrations || []);
|
||||
const migrations = await connectionMetadataBuilder.buildMigrations(flattenedMigrations);
|
||||
ObjectUtils.assign(this, { migrations: migrations });
|
||||
// validate all created entity metadatas to make sure user created entities are valid and correct
|
||||
entityMetadataValidator.validateMany(this.entityMetadatas.filter((metadata) => metadata.tableType !== "view"), this.driver);
|
||||
// set current data source to the entities
|
||||
for (let entityMetadata of entityMetadatas) {
|
||||
if (InstanceChecker.isBaseEntityConstructor(entityMetadata.target)) {
|
||||
entityMetadata.target.useDataSource(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the replication mode SELECT queries should use for this datasource by default
|
||||
*/
|
||||
defaultReplicationModeForReads() {
|
||||
if ("replication" in this.driver.options) {
|
||||
const value = this.driver.options.replication.defaultMode;
|
||||
if (value) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "slave";
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=DataSource.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,22 +0,0 @@
|
||||
import { CockroachConnectionOptions } from "../driver/cockroachdb/CockroachConnectionOptions";
|
||||
import { MysqlConnectionOptions } from "../driver/mysql/MysqlConnectionOptions";
|
||||
import { PostgresConnectionOptions } from "../driver/postgres/PostgresConnectionOptions";
|
||||
import { SqliteConnectionOptions } from "../driver/sqlite/SqliteConnectionOptions";
|
||||
import { SqlServerConnectionOptions } from "../driver/sqlserver/SqlServerConnectionOptions";
|
||||
import { OracleConnectionOptions } from "../driver/oracle/OracleConnectionOptions";
|
||||
import { MongoConnectionOptions } from "../driver/mongodb/MongoConnectionOptions";
|
||||
import { CordovaConnectionOptions } from "../driver/cordova/CordovaConnectionOptions";
|
||||
import { SqljsConnectionOptions } from "../driver/sqljs/SqljsConnectionOptions";
|
||||
import { ReactNativeConnectionOptions } from "../driver/react-native/ReactNativeConnectionOptions";
|
||||
import { NativescriptConnectionOptions } from "../driver/nativescript/NativescriptConnectionOptions";
|
||||
import { ExpoConnectionOptions } from "../driver/expo/ExpoConnectionOptions";
|
||||
import { AuroraMysqlConnectionOptions } from "../driver/aurora-mysql/AuroraMysqlConnectionOptions";
|
||||
import { SapConnectionOptions } from "../driver/sap/SapConnectionOptions";
|
||||
import { AuroraPostgresConnectionOptions } from "../driver/aurora-postgres/AuroraPostgresConnectionOptions";
|
||||
import { BetterSqlite3ConnectionOptions } from "../driver/better-sqlite3/BetterSqlite3ConnectionOptions";
|
||||
import { CapacitorConnectionOptions } from "../driver/capacitor/CapacitorConnectionOptions";
|
||||
import { SpannerConnectionOptions } from "../driver/spanner/SpannerConnectionOptions";
|
||||
/**
|
||||
* DataSourceOptions is an interface with settings and options for specific DataSource.
|
||||
*/
|
||||
export type DataSourceOptions = MysqlConnectionOptions | PostgresConnectionOptions | CockroachConnectionOptions | SqliteConnectionOptions | SqlServerConnectionOptions | SapConnectionOptions | OracleConnectionOptions | CordovaConnectionOptions | NativescriptConnectionOptions | ReactNativeConnectionOptions | SqljsConnectionOptions | MongoConnectionOptions | AuroraMysqlConnectionOptions | AuroraPostgresConnectionOptions | ExpoConnectionOptions | BetterSqlite3ConnectionOptions | CapacitorConnectionOptions | SpannerConnectionOptions;
|
||||
@ -1,3 +0,0 @@
|
||||
export {};
|
||||
|
||||
//# sourceMappingURL=DataSourceOptions.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/data-source/DataSourceOptions.ts"],"names":[],"mappings":"","file":"DataSourceOptions.js","sourcesContent":["import { CockroachConnectionOptions } from \"../driver/cockroachdb/CockroachConnectionOptions\"\nimport { MysqlConnectionOptions } from \"../driver/mysql/MysqlConnectionOptions\"\nimport { PostgresConnectionOptions } from \"../driver/postgres/PostgresConnectionOptions\"\nimport { SqliteConnectionOptions } from \"../driver/sqlite/SqliteConnectionOptions\"\nimport { SqlServerConnectionOptions } from \"../driver/sqlserver/SqlServerConnectionOptions\"\nimport { OracleConnectionOptions } from \"../driver/oracle/OracleConnectionOptions\"\nimport { MongoConnectionOptions } from \"../driver/mongodb/MongoConnectionOptions\"\nimport { CordovaConnectionOptions } from \"../driver/cordova/CordovaConnectionOptions\"\nimport { SqljsConnectionOptions } from \"../driver/sqljs/SqljsConnectionOptions\"\nimport { ReactNativeConnectionOptions } from \"../driver/react-native/ReactNativeConnectionOptions\"\nimport { NativescriptConnectionOptions } from \"../driver/nativescript/NativescriptConnectionOptions\"\nimport { ExpoConnectionOptions } from \"../driver/expo/ExpoConnectionOptions\"\nimport { AuroraMysqlConnectionOptions } from \"../driver/aurora-mysql/AuroraMysqlConnectionOptions\"\nimport { SapConnectionOptions } from \"../driver/sap/SapConnectionOptions\"\nimport { AuroraPostgresConnectionOptions } from \"../driver/aurora-postgres/AuroraPostgresConnectionOptions\"\nimport { BetterSqlite3ConnectionOptions } from \"../driver/better-sqlite3/BetterSqlite3ConnectionOptions\"\nimport { CapacitorConnectionOptions } from \"../driver/capacitor/CapacitorConnectionOptions\"\nimport { SpannerConnectionOptions } from \"../driver/spanner/SpannerConnectionOptions\"\n\n/**\n * DataSourceOptions is an interface with settings and options for specific DataSource.\n */\nexport type DataSourceOptions =\n | MysqlConnectionOptions\n | PostgresConnectionOptions\n | CockroachConnectionOptions\n | SqliteConnectionOptions\n | SqlServerConnectionOptions\n | SapConnectionOptions\n | OracleConnectionOptions\n | CordovaConnectionOptions\n | NativescriptConnectionOptions\n | ReactNativeConnectionOptions\n | SqljsConnectionOptions\n | MongoConnectionOptions\n | AuroraMysqlConnectionOptions\n | AuroraPostgresConnectionOptions\n | ExpoConnectionOptions\n | BetterSqlite3ConnectionOptions\n | CapacitorConnectionOptions\n | SpannerConnectionOptions\n"],"sourceRoot":".."}
|
||||
@ -1,2 +0,0 @@
|
||||
export * from "./DataSource";
|
||||
export * from "./DataSourceOptions";
|
||||
@ -1,4 +0,0 @@
|
||||
export * from "./DataSource";
|
||||
export * from "./DataSourceOptions";
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/data-source/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA","file":"index.js","sourcesContent":["export * from \"./DataSource\"\nexport * from \"./DataSourceOptions\"\n"],"sourceRoot":".."}
|
||||
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Check(expression: string): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Check(name: string, expression: string): ClassDecorator & PropertyDecorator;
|
||||
@ -1,24 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { TypeORMError } from "../error";
|
||||
/**
|
||||
* Creates a database check.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create checks with composite columns when used on entity.
|
||||
*/
|
||||
export function Check(nameOrExpression, maybeExpression) {
|
||||
const name = maybeExpression ? nameOrExpression : undefined;
|
||||
const expression = maybeExpression ? maybeExpression : nameOrExpression;
|
||||
if (!expression)
|
||||
throw new TypeORMError(`Check expression is required`);
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().checks.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
expression: expression,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Check.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAmBvC;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACjB,gBAAwB,EACxB,eAAwB;IAExB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3D,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAA;IAEvE,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,YAAY,CAAC,8BAA8B,CAAC,CAAA;IAEvE,OAAO,UACH,WAA8B,EAC9B,YAA8B;QAE9B,sBAAsB,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;YACjC,MAAM,EAAE,YAAY;gBAChB,CAAC,CAAC,WAAW,CAAC,WAAW;gBACzB,CAAC,CAAE,WAAwB;YAC/B,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,UAAU;SACJ,CAAC,CAAA;IAC3B,CAAC,CAAA;AACL,CAAC","file":"Check.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { CheckMetadataArgs } from \"../metadata-args/CheckMetadataArgs\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(expression: string): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(\n name: string,\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database check.\n * Can be used on entity property or on entity.\n * Can create checks with composite columns when used on entity.\n */\nexport function Check(\n nameOrExpression: string,\n maybeExpression?: string,\n): ClassDecorator & PropertyDecorator {\n const name = maybeExpression ? nameOrExpression : undefined\n const expression = maybeExpression ? maybeExpression : nameOrExpression\n\n if (!expression) throw new TypeORMError(`Check expression is required`)\n\n return function (\n clsOrObject: Function | Object,\n propertyName?: string | symbol,\n ) {\n getMetadataArgsStorage().checks.push({\n target: propertyName\n ? clsOrObject.constructor\n : (clsOrObject as Function),\n name: name,\n expression: expression,\n } as CheckMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,9 +0,0 @@
|
||||
import { EntitySchema } from "../entity-schema/EntitySchema";
|
||||
/**
|
||||
* Used to declare a class as a custom repository.
|
||||
* Custom repository can manage some specific entity or just be generic.
|
||||
* Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
export declare function EntityRepository(entity?: Function | EntitySchema<any>): ClassDecorator;
|
||||
@ -1,18 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
/**
|
||||
* Used to declare a class as a custom repository.
|
||||
* Custom repository can manage some specific entity or just be generic.
|
||||
* Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.
|
||||
*
|
||||
* @deprecated use Repository.extend function to create a custom repository
|
||||
*/
|
||||
export function EntityRepository(entity) {
|
||||
return function (target) {
|
||||
getMetadataArgsStorage().entityRepositories.push({
|
||||
target: target,
|
||||
entity: entity,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=EntityRepository.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/EntityRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAInD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC5B,MAAqC;IAErC,OAAO,UAAU,MAAgB;QAC7B,sBAAsB,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC;YAC7C,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;SACe,CAAC,CAAA;IACtC,CAAC,CAAA;AACL,CAAC","file":"EntityRepository.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { EntityRepositoryMetadataArgs } from \"../metadata-args/EntityRepositoryMetadataArgs\"\nimport { EntitySchema } from \"../entity-schema/EntitySchema\"\n\n/**\n * Used to declare a class as a custom repository.\n * Custom repository can manage some specific entity or just be generic.\n * Custom repository optionally can extend AbstractRepository, Repository or TreeRepository.\n *\n * @deprecated use Repository.extend function to create a custom repository\n */\nexport function EntityRepository(\n entity?: Function | EntitySchema<any>,\n): ClassDecorator {\n return function (target: Function) {\n getMetadataArgsStorage().entityRepositories.push({\n target: target,\n entity: entity,\n } as EntityRepositoryMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Exclusion(expression: string): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Exclusion(name: string, expression: string): ClassDecorator & PropertyDecorator;
|
||||
@ -1,24 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { TypeORMError } from "../error";
|
||||
/**
|
||||
* Creates a database exclusion.
|
||||
* Can be used on entity.
|
||||
* Can create exclusions with composite columns when used on entity.
|
||||
*/
|
||||
export function Exclusion(nameOrExpression, maybeExpression) {
|
||||
const name = maybeExpression ? nameOrExpression : undefined;
|
||||
const expression = maybeExpression ? maybeExpression : nameOrExpression;
|
||||
if (!expression)
|
||||
throw new TypeORMError(`Exclusion expression is required`);
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().exclusions.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
expression: expression,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Exclusion.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Exclusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAqBvC;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACrB,gBAAwB,EACxB,eAAwB;IAExB,MAAM,IAAI,GAAG,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAA;IAC3D,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,gBAAgB,CAAA;IAEvE,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,YAAY,CAAC,kCAAkC,CAAC,CAAA;IAE3E,OAAO,UACH,WAA8B,EAC9B,YAA8B;QAE9B,sBAAsB,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,YAAY;gBAChB,CAAC,CAAC,WAAW,CAAC,WAAW;gBACzB,CAAC,CAAE,WAAwB;YAC/B,IAAI,EAAE,IAAI;YACV,UAAU,EAAE,UAAU;SACA,CAAC,CAAA;IAC/B,CAAC,CAAA;AACL,CAAC","file":"Exclusion.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { ExclusionMetadataArgs } from \"../metadata-args/ExclusionMetadataArgs\"\nimport { TypeORMError } from \"../error\"\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n name: string,\n expression: string,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Creates a database exclusion.\n * Can be used on entity.\n * Can create exclusions with composite columns when used on entity.\n */\nexport function Exclusion(\n nameOrExpression: string,\n maybeExpression?: string,\n): ClassDecorator & PropertyDecorator {\n const name = maybeExpression ? nameOrExpression : undefined\n const expression = maybeExpression ? maybeExpression : nameOrExpression\n\n if (!expression) throw new TypeORMError(`Exclusion expression is required`)\n\n return function (\n clsOrObject: Function | Object,\n propertyName?: string | symbol,\n ) {\n getMetadataArgsStorage().exclusions.push({\n target: propertyName\n ? clsOrObject.constructor\n : (clsOrObject as Function),\n name: name,\n expression: expression,\n } as ExclusionMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,10 +0,0 @@
|
||||
/**
|
||||
* Marks a column to generate a value on entity insertion.
|
||||
* There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).
|
||||
* Increment uses a number which increases by one on each insertion.
|
||||
* Uuid generates a special UUID token.
|
||||
* Rowid supports only in CockroachDB and uses `unique_rowid()` function
|
||||
*
|
||||
* Note, some databases do not support non-primary generation columns.
|
||||
*/
|
||||
export declare function Generated(strategy?: "increment" | "uuid" | "rowid"): PropertyDecorator;
|
||||
@ -1,21 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
/**
|
||||
* Marks a column to generate a value on entity insertion.
|
||||
* There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).
|
||||
* Increment uses a number which increases by one on each insertion.
|
||||
* Uuid generates a special UUID token.
|
||||
* Rowid supports only in CockroachDB and uses `unique_rowid()` function
|
||||
*
|
||||
* Note, some databases do not support non-primary generation columns.
|
||||
*/
|
||||
export function Generated(strategy = "increment") {
|
||||
return function (object, propertyName) {
|
||||
getMetadataArgsStorage().generations.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
strategy: strategy,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Generated.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Generated.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAGnD;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACrB,WAA2C,WAAW;IAEtD,OAAO,UAAU,MAAc,EAAE,YAAoB;QACjD,sBAAsB,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;YACtC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,QAAQ,EAAE,QAAQ;SACI,CAAC,CAAA;IAC/B,CAAC,CAAA;AACL,CAAC","file":"Generated.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { GeneratedMetadataArgs } from \"../metadata-args/GeneratedMetadataArgs\"\n\n/**\n * Marks a column to generate a value on entity insertion.\n * There are three types of generation strategy - increment, uuid and rowid (cockroachdb only).\n * Increment uses a number which increases by one on each insertion.\n * Uuid generates a special UUID token.\n * Rowid supports only in CockroachDB and uses `unique_rowid()` function\n *\n * Note, some databases do not support non-primary generation columns.\n */\nexport function Generated(\n strategy: \"increment\" | \"uuid\" | \"rowid\" = \"increment\",\n): PropertyDecorator {\n return function (object: Object, propertyName: string) {\n getMetadataArgsStorage().generations.push({\n target: object.constructor,\n propertyName: propertyName,\n strategy: strategy,\n } as GeneratedMetadataArgs)\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,49 +0,0 @@
|
||||
import { IndexOptions } from "./options/IndexOptions";
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, options: {
|
||||
synchronize: false;
|
||||
}): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(fields: string[], options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export declare function Index(name: string, fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: IndexOptions): ClassDecorator & PropertyDecorator;
|
||||
@ -1,53 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { ObjectUtils } from "../util/ObjectUtils";
|
||||
/**
|
||||
* Creates a database index.
|
||||
* Can be used on entity property or on entity.
|
||||
* Can create indices with composite columns when used on entity.
|
||||
*/
|
||||
export function Index(nameOrFieldsOrOptions, maybeFieldsOrOptions, maybeOptions) {
|
||||
// normalize parameters
|
||||
const name = typeof nameOrFieldsOrOptions === "string"
|
||||
? nameOrFieldsOrOptions
|
||||
: undefined;
|
||||
const fields = typeof nameOrFieldsOrOptions === "string"
|
||||
? maybeFieldsOrOptions
|
||||
: nameOrFieldsOrOptions;
|
||||
let options = ObjectUtils.isObject(nameOrFieldsOrOptions) &&
|
||||
!Array.isArray(nameOrFieldsOrOptions)
|
||||
? nameOrFieldsOrOptions
|
||||
: maybeOptions;
|
||||
if (!options)
|
||||
options =
|
||||
ObjectUtils.isObject(maybeFieldsOrOptions) &&
|
||||
!Array.isArray(maybeFieldsOrOptions)
|
||||
? maybeFieldsOrOptions
|
||||
: maybeOptions;
|
||||
return function (clsOrObject, propertyName) {
|
||||
getMetadataArgsStorage().indices.push({
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
columns: propertyName ? [propertyName] : fields,
|
||||
synchronize: options &&
|
||||
options.synchronize === false
|
||||
? false
|
||||
: true,
|
||||
where: options ? options.where : undefined,
|
||||
unique: options && options.unique ? true : false,
|
||||
spatial: options && options.spatial ? true : false,
|
||||
fulltext: options && options.fulltext ? true : false,
|
||||
nullFiltered: options && options.nullFiltered ? true : false,
|
||||
parser: options ? options.parser : undefined,
|
||||
sparse: options && options.sparse ? true : false,
|
||||
background: options && options.background ? true : false,
|
||||
concurrent: options && options.concurrent ? true : false,
|
||||
expireAfterSeconds: options
|
||||
? options.expireAfterSeconds
|
||||
: undefined,
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Index.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,21 +0,0 @@
|
||||
import { UniqueOptions } from "./options/UniqueOptions";
|
||||
/**
|
||||
* Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.
|
||||
*/
|
||||
export declare function Unique(name: string, fields: string[], options?: UniqueOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.
|
||||
*/
|
||||
export declare function Unique(fields: string[], options?: UniqueOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.
|
||||
*/
|
||||
export declare function Unique(fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: UniqueOptions): ClassDecorator & PropertyDecorator;
|
||||
/**
|
||||
* Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.
|
||||
*/
|
||||
export declare function Unique(name: string, fields: (object?: any) => any[] | {
|
||||
[key: string]: number;
|
||||
}, options?: UniqueOptions): ClassDecorator & PropertyDecorator;
|
||||
@ -1,47 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../globals";
|
||||
import { ObjectUtils } from "../util/ObjectUtils";
|
||||
/**
|
||||
* Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.
|
||||
*/
|
||||
export function Unique(nameOrFieldsOrOptions, maybeFieldsOrOptions, maybeOptions) {
|
||||
const name = typeof nameOrFieldsOrOptions === "string"
|
||||
? nameOrFieldsOrOptions
|
||||
: undefined;
|
||||
const fields = typeof nameOrFieldsOrOptions === "string"
|
||||
? maybeFieldsOrOptions
|
||||
: nameOrFieldsOrOptions;
|
||||
let options = ObjectUtils.isObject(nameOrFieldsOrOptions) &&
|
||||
!Array.isArray(nameOrFieldsOrOptions)
|
||||
? nameOrFieldsOrOptions
|
||||
: maybeOptions;
|
||||
if (!options)
|
||||
options =
|
||||
ObjectUtils.isObject(nameOrFieldsOrOptions) &&
|
||||
!Array.isArray(maybeFieldsOrOptions)
|
||||
? maybeFieldsOrOptions
|
||||
: maybeOptions;
|
||||
return function (clsOrObject, propertyName) {
|
||||
let columns = fields;
|
||||
if (propertyName !== undefined) {
|
||||
switch (typeof propertyName) {
|
||||
case "string":
|
||||
columns = [propertyName];
|
||||
break;
|
||||
case "symbol":
|
||||
columns = [propertyName.toString()];
|
||||
break;
|
||||
}
|
||||
}
|
||||
const args = {
|
||||
target: propertyName
|
||||
? clsOrObject.constructor
|
||||
: clsOrObject,
|
||||
name: name,
|
||||
columns,
|
||||
deferrable: options ? options.deferrable : undefined,
|
||||
};
|
||||
getMetadataArgsStorage().uniques.push(args);
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Unique.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/Unique.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAGnD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAoCjD;;GAEG;AACH,MAAM,UAAU,MAAM,CAClB,qBAImB,EACnB,oBAGmB,EACnB,YAA4B;IAE5B,MAAM,IAAI,GACN,OAAO,qBAAqB,KAAK,QAAQ;QACrC,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,SAAS,CAAA;IACnB,MAAM,MAAM,GACR,OAAO,qBAAqB,KAAK,QAAQ;QACrC,CAAC,CAGE,oBAAoB;QACvB,CAAC,CAAE,qBAAkC,CAAA;IAC7C,IAAI,OAAO,GACP,WAAW,CAAC,QAAQ,CAAC,qBAAqB,CAAC;QAC3C,CAAC,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACjC,CAAC,CAAE,qBAAuC;QAC1C,CAAC,CAAC,YAAY,CAAA;IACtB,IAAI,CAAC,OAAO;QACR,OAAO;YACH,WAAW,CAAC,QAAQ,CAAC,qBAAqB,CAAC;gBAC3C,CAAC,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC;gBAChC,CAAC,CAAE,oBAAsC;gBACzC,CAAC,CAAC,YAAY,CAAA;IAE1B,OAAO,UACH,WAA8B,EAC9B,YAA8B;QAE9B,IAAI,OAAO,GAAG,MAAM,CAAA;QAEpB,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YAC7B,QAAQ,OAAO,YAAY,EAAE,CAAC;gBAC1B,KAAK,QAAQ;oBACT,OAAO,GAAG,CAAC,YAAY,CAAC,CAAA;oBACxB,MAAK;gBAET,KAAK,QAAQ;oBACT,OAAO,GAAG,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAA;oBACnC,MAAK;YACb,CAAC;QACL,CAAC;QAED,MAAM,IAAI,GAAuB;YAC7B,MAAM,EAAE,YAAY;gBAChB,CAAC,CAAC,WAAW,CAAC,WAAW;gBACzB,CAAC,CAAE,WAAwB;YAC/B,IAAI,EAAE,IAAI;YACV,OAAO;YACP,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;SACvD,CAAA;QACD,sBAAsB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/C,CAAC,CAAA;AACL,CAAC","file":"Unique.js","sourcesContent":["import { getMetadataArgsStorage } from \"../globals\"\nimport { UniqueMetadataArgs } from \"../metadata-args/UniqueMetadataArgs\"\nimport { UniqueOptions } from \"./options/UniqueOptions\"\nimport { ObjectUtils } from \"../util/ObjectUtils\"\n\n/**\n * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.\n */\nexport function Unique(\n name: string,\n fields: string[],\n options?: UniqueOptions,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.\n */\nexport function Unique(\n fields: string[],\n options?: UniqueOptions,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.\n */\nexport function Unique(\n fields: (object?: any) => any[] | { [key: string]: number },\n options?: UniqueOptions,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.\n */\nexport function Unique(\n name: string,\n fields: (object?: any) => any[] | { [key: string]: number },\n options?: UniqueOptions,\n): ClassDecorator & PropertyDecorator\n\n/**\n * Composite unique constraint must be set on entity classes and must specify entity's fields to be unique.\n */\nexport function Unique(\n nameOrFieldsOrOptions?:\n | string\n | string[]\n | ((object: any) => any[] | { [key: string]: number })\n | UniqueOptions,\n maybeFieldsOrOptions?:\n | ((object?: any) => any[] | { [key: string]: number })\n | string[]\n | UniqueOptions,\n maybeOptions?: UniqueOptions,\n): ClassDecorator & PropertyDecorator {\n const name =\n typeof nameOrFieldsOrOptions === \"string\"\n ? nameOrFieldsOrOptions\n : undefined\n const fields =\n typeof nameOrFieldsOrOptions === \"string\"\n ? <\n | ((object?: any) => any[] | { [key: string]: number })\n | string[]\n >maybeFieldsOrOptions\n : (nameOrFieldsOrOptions as string[])\n let options =\n ObjectUtils.isObject(nameOrFieldsOrOptions) &&\n !Array.isArray(nameOrFieldsOrOptions)\n ? (nameOrFieldsOrOptions as UniqueOptions)\n : maybeOptions\n if (!options)\n options =\n ObjectUtils.isObject(nameOrFieldsOrOptions) &&\n !Array.isArray(maybeFieldsOrOptions)\n ? (maybeFieldsOrOptions as UniqueOptions)\n : maybeOptions\n\n return function (\n clsOrObject: Function | Object,\n propertyName?: string | symbol,\n ) {\n let columns = fields\n\n if (propertyName !== undefined) {\n switch (typeof propertyName) {\n case \"string\":\n columns = [propertyName]\n break\n\n case \"symbol\":\n columns = [propertyName.toString()]\n break\n }\n }\n\n const args: UniqueMetadataArgs = {\n target: propertyName\n ? clsOrObject.constructor\n : (clsOrObject as Function),\n name: name,\n columns,\n deferrable: options ? options.deferrable : undefined,\n }\n getMetadataArgsStorage().uniques.push(args)\n }\n}\n"],"sourceRoot":".."}
|
||||
@ -1,74 +0,0 @@
|
||||
import { SimpleColumnType, SpatialColumnType, WithLengthColumnType, WithPrecisionColumnType, WithWidthColumnType } from "../../driver/types/ColumnTypes";
|
||||
import { ColumnCommonOptions } from "../options/ColumnCommonOptions";
|
||||
import { SpatialColumnOptions } from "../options/SpatialColumnOptions";
|
||||
import { ColumnWithLengthOptions } from "../options/ColumnWithLengthOptions";
|
||||
import { ColumnNumericOptions } from "../options/ColumnNumericOptions";
|
||||
import { ColumnEnumOptions } from "../options/ColumnEnumOptions";
|
||||
import { ColumnEmbeddedOptions } from "../options/ColumnEmbeddedOptions";
|
||||
import { ColumnHstoreOptions } from "../options/ColumnHstoreOptions";
|
||||
import { ColumnWithWidthOptions } from "../options/ColumnWithWidthOptions";
|
||||
import { ColumnOptions } from "../options/ColumnOptions";
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column. Only properties decorated with this
|
||||
* decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(options: ColumnOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: SimpleColumnType, options?: ColumnCommonOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: SpatialColumnType, options?: ColumnCommonOptions & SpatialColumnOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: WithLengthColumnType, options?: ColumnCommonOptions & ColumnWithLengthOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: WithWidthColumnType, options?: ColumnCommonOptions & ColumnWithWidthOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: WithPrecisionColumnType, options?: ColumnCommonOptions & ColumnNumericOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: "enum", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: "simple-enum", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: "set", options?: ColumnCommonOptions & ColumnEnumOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export declare function Column(type: "hstore", options?: ColumnCommonOptions & ColumnHstoreOptions): PropertyDecorator;
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*
|
||||
* Property in entity can be marked as Embedded, and on persist all columns from the embedded are mapped to the
|
||||
* single table of the entity where Embedded is used. And on hydration all columns which supposed to be in the
|
||||
* embedded will be mapped to it from the single table.
|
||||
*/
|
||||
export declare function Column(type: (type?: any) => Function, options?: ColumnEmbeddedOptions): PropertyDecorator;
|
||||
@ -1,75 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../../globals";
|
||||
import { ColumnTypeUndefinedError } from "../../error/ColumnTypeUndefinedError";
|
||||
/**
|
||||
* Column decorator is used to mark a specific class property as a table column.
|
||||
* Only properties decorated with this decorator will be persisted to the database when entity be saved.
|
||||
*/
|
||||
export function Column(typeOrOptions, options) {
|
||||
return function (object, propertyName) {
|
||||
// normalize parameters
|
||||
let type;
|
||||
if (typeof typeOrOptions === "string" ||
|
||||
typeof typeOrOptions === "function") {
|
||||
type = typeOrOptions;
|
||||
}
|
||||
else if (typeOrOptions) {
|
||||
options = typeOrOptions;
|
||||
type = typeOrOptions.type;
|
||||
}
|
||||
if (!options)
|
||||
options = {};
|
||||
// if type is not given explicitly then try to guess it
|
||||
const reflectMetadataType = Reflect && Reflect.getMetadata
|
||||
? Reflect.getMetadata("design:type", object, propertyName)
|
||||
: undefined;
|
||||
if (!type && reflectMetadataType)
|
||||
// if type is not given explicitly then try to guess it
|
||||
type = reflectMetadataType;
|
||||
// check if there is no type in column options then set type from first function argument, or guessed one
|
||||
if (!options.type && type)
|
||||
options.type = type;
|
||||
// specify HSTORE type if column is HSTORE
|
||||
if (options.type === "hstore" && !options.hstoreType)
|
||||
options.hstoreType =
|
||||
reflectMetadataType === Object ? "object" : "string";
|
||||
if (typeof typeOrOptions === "function") {
|
||||
// register an embedded
|
||||
getMetadataArgsStorage().embeddeds.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
isArray: reflectMetadataType === Array || options.array === true,
|
||||
prefix: options.prefix !== undefined ? options.prefix : undefined,
|
||||
type: typeOrOptions,
|
||||
});
|
||||
}
|
||||
else {
|
||||
// register a regular column
|
||||
// if we still don't have a type then we need to give error to user that type is required
|
||||
if (!options.type)
|
||||
throw new ColumnTypeUndefinedError(object, propertyName);
|
||||
// create unique
|
||||
if (options.unique === true)
|
||||
getMetadataArgsStorage().uniques.push({
|
||||
target: object.constructor,
|
||||
columns: [propertyName],
|
||||
});
|
||||
getMetadataArgsStorage().columns.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
mode: "regular",
|
||||
options: options,
|
||||
});
|
||||
if (options.generated) {
|
||||
getMetadataArgsStorage().generations.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
strategy: typeof options.generated === "string"
|
||||
? options.generated
|
||||
: "increment",
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=Column.js.map
|
||||
File diff suppressed because one or more lines are too long
@ -1,7 +0,0 @@
|
||||
import { ColumnOptions } from "../options/ColumnOptions";
|
||||
/**
|
||||
* This column will store a creation date of the inserted object.
|
||||
* Creation date is generated and inserted only once,
|
||||
* at the first time when you create an object, the value is inserted into the table, and is never touched again.
|
||||
*/
|
||||
export declare function CreateDateColumn(options?: ColumnOptions): PropertyDecorator;
|
||||
@ -1,18 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../../globals";
|
||||
/**
|
||||
* This column will store a creation date of the inserted object.
|
||||
* Creation date is generated and inserted only once,
|
||||
* at the first time when you create an object, the value is inserted into the table, and is never touched again.
|
||||
*/
|
||||
export function CreateDateColumn(options) {
|
||||
return function (object, propertyName) {
|
||||
getMetadataArgsStorage().columns.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
mode: "createDate",
|
||||
options: options || {},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=CreateDateColumn.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/columns/CreateDateColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAItD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACpD,OAAO,UAAU,MAAc,EAAE,YAAoB;QACjD,sBAAsB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YAClC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,OAAO,IAAI,EAAE;SACH,CAAC,CAAA;IAC5B,CAAC,CAAA;AACL,CAAC","file":"CreateDateColumn.js","sourcesContent":["import { getMetadataArgsStorage } from \"../../globals\"\nimport { ColumnMetadataArgs } from \"../../metadata-args/ColumnMetadataArgs\"\nimport { ColumnOptions } from \"../options/ColumnOptions\"\n\n/**\n * This column will store a creation date of the inserted object.\n * Creation date is generated and inserted only once,\n * at the first time when you create an object, the value is inserted into the table, and is never touched again.\n */\nexport function CreateDateColumn(options?: ColumnOptions): PropertyDecorator {\n return function (object: Object, propertyName: string) {\n getMetadataArgsStorage().columns.push({\n target: object.constructor,\n propertyName: propertyName,\n mode: \"createDate\",\n options: options || {},\n } as ColumnMetadataArgs)\n }\n}\n"],"sourceRoot":"../.."}
|
||||
@ -1,6 +0,0 @@
|
||||
import { ColumnOptions } from "../options/ColumnOptions";
|
||||
/**
|
||||
* This column will store a delete date of the soft-deleted object.
|
||||
* This date is being updated each time you soft-delete the object.
|
||||
*/
|
||||
export declare function DeleteDateColumn(options?: ColumnOptions): PropertyDecorator;
|
||||
@ -1,17 +0,0 @@
|
||||
import { getMetadataArgsStorage } from "../../globals";
|
||||
/**
|
||||
* This column will store a delete date of the soft-deleted object.
|
||||
* This date is being updated each time you soft-delete the object.
|
||||
*/
|
||||
export function DeleteDateColumn(options) {
|
||||
return function (object, propertyName) {
|
||||
getMetadataArgsStorage().columns.push({
|
||||
target: object.constructor,
|
||||
propertyName: propertyName,
|
||||
mode: "deleteDate",
|
||||
options: options || {},
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
//# sourceMappingURL=DeleteDateColumn.js.map
|
||||
@ -1 +0,0 @@
|
||||
{"version":3,"sources":["../browser/src/decorator/columns/DeleteDateColumn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAItD;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACpD,OAAO,UAAU,MAAc,EAAE,YAAoB;QACjD,sBAAsB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;YAClC,MAAM,EAAE,MAAM,CAAC,WAAW;YAC1B,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,OAAO,IAAI,EAAE;SACH,CAAC,CAAA;IAC5B,CAAC,CAAA;AACL,CAAC","file":"DeleteDateColumn.js","sourcesContent":["import { getMetadataArgsStorage } from \"../../globals\"\nimport { ColumnMetadataArgs } from \"../../metadata-args/ColumnMetadataArgs\"\nimport { ColumnOptions } from \"../options/ColumnOptions\"\n\n/**\n * This column will store a delete date of the soft-deleted object.\n * This date is being updated each time you soft-delete the object.\n */\nexport function DeleteDateColumn(options?: ColumnOptions): PropertyDecorator {\n return function (object: Object, propertyName: string) {\n getMetadataArgsStorage().columns.push({\n target: object.constructor,\n propertyName: propertyName,\n mode: \"deleteDate\",\n options: options || {},\n } as ColumnMetadataArgs)\n }\n}\n"],"sourceRoot":"../.."}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user