本文整理匯總了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"});
}