sourcegraph/cmd/precise-code-intel/src/shared/database/sqlite.ts

29 lines
841 B
TypeScript
Raw Normal View History

2019-11-08 20:21:44 +00:00
import { Connection, createConnection as _createConnection } from 'typeorm'
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.
* @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
entities: Function[],
logger: Logger
2019-11-08 20:21:44 +00:00
): Promise<Connection> {
return _createConnection({
type: 'sqlite',
name: database,
database,
entities,
synchronize: true,
logger: new DatabaseLogger(logger),
2019-11-08 20:21:44 +00:00
maxQueryExecutionTime: 1000,
})
}