本文整理汇总了TypeScript中typeorm.getConnectionOptions函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getConnectionOptions函数的具体用法?TypeScript getConnectionOptions怎么用?TypeScript getConnectionOptions使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getConnectionOptions函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
useFactory: async () => {
Log.log.debug(` * ${new Date().toISOString()}: Setting up TypeORM`);
const config = await getConnectionOptions('default');
return Object.assign(config, {
logger: new OrmLog('all')
})
}
示例2: async
export const ormOptions = async (databaseName: string, appHomeDirPath: string, appRootPath: string) => {
if (!databaseName) {
throw new Error(`No database name was defined. Define DB_NAME property in your .env file.`);
}
const connectionOptions = await getConnectionOptions();
// overwrite the dynamic config parts
Object.assign(connectionOptions, {
database: path.join(appHomeDirPath, databaseName),
entities: [path.join(appRootPath, 'server/src/entity/**/*.{ts,js}')],
migrations: [path.join(appRootPath, 'server/src/migration/**/*.{ts,js}')],
subscribers: [path.join(appRootPath, 'server/src/subscriber/**/*.{ts,js}')]
});
return connectionOptions;
};
示例3: async
const initTypeORM = async () => {
const loadedConnectionOptions = await getConnectionOptions();
const connectionOptions = Object.assign(loadedConnectionOptions, {
type: env.db.type as any, // See createConnection options for valid types
host: env.db.host,
port: env.db.port,
username: env.db.username,
password: env.db.password,
database: env.db.database,
synchronize: env.db.synchronize,
logging: env.db.logging,
entities: env.app.dirs.entities,
migrations: env.app.dirs.migrations,
});
return createConnection(connectionOptions);
};
示例4: async
export const connectWithRetry = async (retries = 5, timeout = 500) => {
const connectionOptions = Object.assign(
await getConnectionOptions(),
{
host: process.env.TYPEORM_HOST,
username: process.env.TYPEORM_USERNAME,
password: process.env.TYPEORM_PASSWORD,
database: process.env.TYPEORM_DATABASE
},
process.env.NODE_ENV === "production"
? {
entities: [process.env.TYPEORM_ENTITIES_DIR],
subscribers: [process.env.TYPEORM_SUBSCRIBERS_DIR],
migrations: [process.env.TYPEORM_MIGRATIONS_DIR]
}
: {}
);
try {
await createConnection(connectionOptions);
logger.info("DB Connected");
} catch (e) {
logger.error(e);
if (retries > 0) {
setTimeout(() => {
logger.warn(
`Retrying connection, retrys remaining: ${retries}, timeout: ${timeout}`
);
connectWithRetry(retries - 1, timeout);
}, timeout);
} else {
logger.error(new Error(`DB connection failed with retrys`));
return;
}
}
};
示例5: async
export const createTypeormConn = async () => {
// node env changes whether we are testing or running
const connectionOptions = await getConnectionOptions(process.env.NODE_ENV);
return createConnection({...connectionOptions, name: "default"});
}