2019-11-08 20:21:44 +00:00
|
|
|
import { Connection, createConnection as _createConnection } from 'typeorm'
|
2020-02-19 20:25:00 +00:00
|
|
|
import { Logger } from 'winston'
|
|
|
|
|
import { DatabaseLogger } from './logger'
|
2019-11-08 20:21:44 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a SQLite connection from the given filename.
|
|
|
|
|
*
|
|
|
|
|
* @param database The database filename.
|
|
|
|
|
* @param entities The set of expected entities present in this schema.
|
2020-02-19 20:25:00 +00:00
|
|
|
* @param logger The logger instance.
|
2019-11-08 20:21:44 +00:00
|
|
|
*/
|
|
|
|
|
export function createSqliteConnection(
|
|
|
|
|
database: string,
|
|
|
|
|
// Decorators are not possible type check
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
2020-02-19 20:25:00 +00:00
|
|
|
entities: Function[],
|
|
|
|
|
logger: Logger
|
2019-11-08 20:21:44 +00:00
|
|
|
): Promise<Connection> {
|
|
|
|
|
return _createConnection({
|
|
|
|
|
type: 'sqlite',
|
|
|
|
|
name: database,
|
|
|
|
|
database,
|
|
|
|
|
entities,
|
|
|
|
|
synchronize: true,
|
2020-02-19 20:25:00 +00:00
|
|
|
logger: new DatabaseLogger(logger),
|
2019-11-08 20:21:44 +00:00
|
|
|
maxQueryExecutionTime: 1000,
|
|
|
|
|
})
|
|
|
|
|
}
|