Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created October 27, 2020 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bogdan/2b123eb91eee3e240f41075b69baf06d to your computer and use it in GitHub Desktop.
Save bogdan/2b123eb91eee3e240f41075b69baf06d to your computer and use it in GitHub Desktop.
import {getConnectionManager, getConnection} from 'typeorm';
import {WinstonTypeormLogger} from './WinstonTypeormLogger';
import SnakeNamingStrategy from './SnakeNamingStrategy';
import config from '../config';
process.env.TZ = 'UTC';
const manager = getConnectionManager();
if (!manager.connections.length) {
manager.create({
...config.TYPEORM,
logger: new WinstonTypeormLogger(config.TYPEORM.loggerOptions),
logging: true,
migrationsRun: config.env.isGoogleCloudStagingOrProduction(),
namingStrategy: new SnakeNamingStrategy(),
});
}
export default async function connect() {
const connection = getConnection();
return connection.isConnected ? connection : await connection.connect();
}
connect().then(async c => {
const l = await c.driver.createSchemaBuilder().log()
console.log(l.upQueries)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment