2 ms·
> What's the reason that it can't act like a filesystem image, and keep everything in one file? SQLite actually provides an example VFS which stores everything
by skissane 6y ago
> What's the reason that it can't act like a filesystem image, and keep everything in one file?
SQLite actually provides an example VFS which stores everything in one file, except the one file has to be of fixed size – https://www.sqlite.org/src/doc/trunk/src/test_onefile.c https://www.sqlite.org/src/doc/trunk/src/test_onefile.c
It is intended as an example of how SQLite can be used on an embedded system which has no filesystem, just a raw disk.
I think someone could create a VFS which stored everything in one file without the fixed size limitation. I think you'd need to have three types of pages in the file – data, journal, and metadata (which marks which pages are of which type, using a bitmap or extent list or whatever). The VFS would present two separate files, data and journal, but actually store them as one file containing these three types of pages. You'd need to think carefully about the ordering of updates to the three page types to ensure atomicity in the case of a crash. A fair amount of work, but doable if someone wanted to. (Maybe even the SQLite developers might do it if they thought it was a good idea, or if someone was willing to pay them to do it.)