Created
October 27, 2020 13:22
-
-
Save bogdan/2b123eb91eee3e240f41075b69baf06d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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