Skip to content

Allow file storage instead of forcing :memory: #26

@cyrille-gaucher

Description

@cyrille-gaucher

Hi,

First of all, thank you for your work. Your lib is great!

It would be nice to allow the use of storage in file.

In my use case I have different connections all along the unit tests. When using the :memory: option, each connection seems to work with it's own allocated memory and so with its own DBs.

I'd like them to share the same DB and the only solution I see here is not to override the storage option.

The concerned code is located in the sequelize-mocking.js file in the adaptSequelizeOptions and a solution would be as follows:

const SQLITE_SEQUELIZE_OPTIONS = {
    'dialect': 'sqlite'
}
const SQLITE_SEQUELIZE_DEFAULT_OPTIONS = {
    'storage': ':memory:'
};

class SequelizeMocking {
    static adaptSequelizeOptions(sequelizeInstance, options) {
        let optionsExtended = _.merge(
            { },
            SQLITE_SEQUELIZE_DEFAULT_OPTIONS,
            sequelizeInstance.options,
            SQLITE_SEQUELIZE_OPTIONS,
            { 'logging': options && !options.logging ? false : console.log }
        );

        return optionsExtended;
    }
    ...
}

I hope I'm clear enough

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions