Skip to content

Sequelize doesn't respect storage parameter for SQLite3 anonymous disk-based database #13375

@soryy708

Description

@soryy708

Issue Creation Checklist

Bug Description

It is impossible to create an Anonymous disk-based database using Sequelize.

SSCCE

new Sequelize({dialect: 'sqlite', storage: ''})

What do you expect to happen?

The empty string in the storage parameter should have been passed to sqlite3, which sqlite3 documentation says ought to create an

anonymous disk-based database
which will be automatically deleted when the handle is closed.

What is actually happening?

An in-memory SQLite database is created

Additional context

Looking in the source code, the storage parameter is part of a chain of || (logic or operator)s. This is a common JS shorthand for picking the rightmost value that isn't falsy. Unfortunately an '' (empty string) is also falsy, which causes Sequelize to keep going right and picking something else that isn't falsy.
For example, in /lib/dialects/sqlite/connection-manager:48 we have this.sequelize.options.storage || this.sequelize.options.host || ':memory:'. Here if storage is empty string it will pick either host or ':memory:'.

Environment

  • Sequelize version: 6.5.0
  • Node.js version: v14.15.0

Bug Report Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s): SQLite
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions