Skip to content

Support sqlite3's immutable parameter for reading from RO filesystems #640

@Suika

Description

@Suika

One of the projects I use uses the better-sqlite3 library to read data from sqlite3 files for further processing.
This whole process uses the "readonly" flag of better-sqlite3, that behaves the same way as it would with sqlite3 executable.

A problem I run into with with better-sqlite3 and not with the executable, are readonly filesystems(snapshots, etc).
Trying to open the db files with sqlite3 and mode=ro/-readonly will fail as expected, but can be circumvented by using immutable=1
https://sqlite.org/uri.html#recognized_query_parameters

The immutable query parameter is a boolean that signals to SQLite that the underlying database file is held on read-only media and cannot be modified, even by another process with elevated privileges. SQLite always opens immutable database files read-only and it skips all file locking and change detection on immutable database files. If these query parameter (or the SQLITE_IOCAP_IMMUTABLE bit in xDeviceCharacteristics) asserts that a database file is immutable and that file changes anyhow, then SQLite might return incorrect query results and/or SQLITE_CORRUPT errors.

Would it be possible extend the functionality of better-sqlite3 to support "immutable"?
Since the database can't be changed on a RO filesystem there should be no big concerns around it.
It can only read and there is no need for a lock and any higher logic.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions