Also normalize the config override
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
@@ -26,7 +26,7 @@ describe('sqlite3', () => {
|
||||
new ConfigReader({ client: 'sqlite3', connection });
|
||||
|
||||
describe('buildSqliteDatabaseConfig', () => {
|
||||
it('builds an in memory connection', () => {
|
||||
it('builds an in-memory connection', () => {
|
||||
expect(buildSqliteDatabaseConfig(createConfig(':memory:'))).toEqual({
|
||||
client: 'sqlite3',
|
||||
connection: { filename: ':memory:' },
|
||||
@@ -34,6 +34,19 @@ describe('sqlite3', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('builds an in-memory connection by override with filename', () => {
|
||||
expect(
|
||||
buildSqliteDatabaseConfig(
|
||||
createConfig(path.join('path', 'to', 'foo')),
|
||||
{ connection: ':memory:' },
|
||||
),
|
||||
).toEqual({
|
||||
client: 'sqlite3',
|
||||
connection: { filename: ':memory:' },
|
||||
useNullAsDefault: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('builds a persistent connection, normalize config with filename', () => {
|
||||
expect(
|
||||
buildSqliteDatabaseConfig(createConfig(path.join('path', 'to', 'foo'))),
|
||||
|
||||
@@ -34,7 +34,7 @@ export function createSqliteDatabaseClient(
|
||||
|
||||
// If storage on disk is used, ensure that the directory exists
|
||||
if (
|
||||
typeof knexConfig.connection === 'object' &&
|
||||
knexConfig.connection &&
|
||||
(knexConfig.connection as Knex.Sqlite3ConnectionConfig).filename
|
||||
) {
|
||||
const { filename } = knexConfig.connection as Knex.Sqlite3ConnectionConfig;
|
||||
@@ -70,6 +70,9 @@ export function buildSqliteDatabaseConfig(
|
||||
if (typeof baseConfig.connection === 'string') {
|
||||
baseConfig.connection = { filename: baseConfig.connection };
|
||||
}
|
||||
if (overrides && typeof overrides.connection === 'string') {
|
||||
overrides.connection = { filename: overrides.connection };
|
||||
}
|
||||
|
||||
const config: Knex.Config = mergeDatabaseConfig(
|
||||
baseConfig,
|
||||
@@ -82,7 +85,7 @@ export function buildSqliteDatabaseConfig(
|
||||
// If we don't create an in-memory database, interpret the connection string
|
||||
// as a directory that contains multiple sqlite files based on the database
|
||||
// name.
|
||||
if (config.connection && typeof config.connection === 'object') {
|
||||
if (config.connection) {
|
||||
const database = (config.connection as Knex.ConnectionConfig).database;
|
||||
const sqliteConnection = config.connection as Knex.Sqlite3ConnectionConfig;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user