typeorm#useContainer TypeScript Examples
The following examples show how to use
typeorm#useContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: database.ts From jaebook-server with MIT License | 6 votes |
/**
* 데이터베이스 커넥션을 생성한다.
*/
export async function createDatabaseConnection(): Promise<void> {
try {
const connectionOpts: ConnectionOptions = {
type: "mysql",
host: env.database.host,
port: env.database.port,
username: env.database.usename,
password: env.database.password,
database: env.database.name,
synchronize: env.database.synchronize,
logging: env.database.logging,
entities: [__dirname + "/entities/*{.ts,.js}"],
};
useContainer(Container);
await createConnection(connectionOpts);
} catch (error) {
throw error;
}
}
Example #2
Source File: CreateMemoryDatabase.ts From jaebook-server with MIT License | 6 votes |
/**
* 테스트에 사용할 In-memory Database를 만든다
* @param entities
*/
export async function createMemoryDatabase() {
useContainer(Container);
return createConnection({
type: "sqlite",
database: ":memory:",
entities: [__dirname + "/../../src/entities/*{.ts,.js}"],
dropSchema: true,
synchronize: true,
logging: false,
});
}
Example #3
Source File: database.ts From spurtcommerce with BSD 3-Clause "New" or "Revised" License | 6 votes |
createDatabaseConnection = async (): Promise<Connection> => {
useContainer(Container);
const connection = await createConnection({
type: env.db.type as any, // See createConnection options for valid types
database: env.db.database,
logging: env.db.logging,
entities: env.app.dirs.entities,
migrations: env.app.dirs.migrations,
});
return connection;
}