Breaking changes for 1.0 #153
Replies: 3 comments 1 reply
-
Virtual File Systems in 1.0Here's some information about what VFS changes are coming. New base class FacadeVFSThe convenience base class VFS.Base has been changed so that all methods (e.g. xOpen, xClose, etc.) now have signatures matching their C counterparts (except for 64-bit ints, which Emscripten legalization passes as two 32-bit arguments). In short, the methods no longer have their arguments converted to JavaScript-friendly types like string, DataView, and Uint8Array. There is now an intermediate base class, FacadeVFS, that handles that conversion, and most VFS writers will want to subclass that instead as all the example VFS classes now do. The new methods to override are named jOpen, jClose, etc., matching one-to-one with the original methods. Asyncify and JSPI unificationThe motivation for most of the VFS changes is to allow the same VFS code to run with both the Asyncify and JSPI builds. Unlike Asyncify, JSPI does not allow choosing at runtime whether a method returns synchronously or asynchronously - a method must be exclusively one or the other, specified at VFS registration time. FacadeVFS takes care of this automatically by examining whether methods are marked async; this behavior can be overridden if you have esoteric needs. The end result is that you should not use handleAsync for asynchronous methods; just define those methods async. New WebLocksMixin to implement VFS locksPreviously there were separate helper classes providing implementation for exclusive and shared VFS locking. Those classes have been replaced with a mix-in for FacadeVFS subclasses that allows configuring locking policy and other options on VFS construction. IDBBatchAtomicVFS and OPFSAdaptiveVFS demonstrate use of WebLocksMixin. By default, WebLocksMixin provides locking policy "exclusive" where only one connection can access the database at a time, but the demos use locking policy "shared" which fully implements the SQLite locking model allowing concurrent read transactions. Note that the SQLite locking model can result in deadlock, signaled by returning SQLITE_BUSY, which is the responsibility of the application to handle. Example classes rewrittenThe most useful/interesting example VFS classes have been reimplemented as FacadeVFS subclasses. The old WebLocks classes to help implement xLock/xUnlock/xCheckReservedLock have been replaced by mix-in classes that implement jLock/jUnlock/jCheckReservedLock for you for common locking models. The VFS base class used to have an The more interesting VFS classes have been rewritten from scratch, so they may behave a bit differently. There is a comparison chart of the example VFS classes here. Here are some of the change details: MemoryVFS and MemoryAsyncVFSThese classes have been ported essentially as-is. IDBBatchAtomicVFSThis VFS no longer supports changing the page size. If you want a specific page size, you must use This VFS used to have a relaxed durability option passed to the constructor. Now this is done via SQL by using Here are demos for Asyncify or JSPI (for JSPI, note that current browser support is Chrome behind a flag). An existing database should be automatically upgraded when first opened by the rewritten VFS. IDBMirrorVFSThis is a new VFS that caches all files in memory and persists database files (only) to IndexedDB. AccessHandlePoolVFSThis VFS has been ported essentially as-is. Here is a demo. OPFSAdaptiveVFSThis is similar to the old OriginPrivateFileSystemVFS. The new one should be more performant with concurrency - it uses the "readwrite-unsafe" proposed mode if available, and falls back to opening and closing the access handle (but only if another connection is waiting for it). If the new mode is not supported then only journaling modes "delete" (default), "memory", and "off" are allowed. Here are demos for Asyncify and JSPI (for JSPI, note that current browser support is Chrome behind a flag). OPFSAdaptiveVFS has filesystem transparency, which means that it should be able to read databases written by the old OriginPrivateFileSystemVFS (but not AccessHandlePoolVFS). OPFSAnyContextVFSThis is a new OPFS VFS that works on any context, not just a dedicated Worker. OPFSAnyContextVFS uses different API calls than other OPFS VFS classes, and these calls are somewhat slower for reading and much slower for writing (and increasingly slower for larger files). It is recommended for applications that rarely need to modify the database. As of 2024-06-11, Safari and Android Chrome (!) do not support FileSystemWritableFileStream, so only reading from a database works on those browsers. Here are demos for Asyncify and JSPI (for JSPI, note that current browser support is Chrome behind a flag). OPFSAnyContextVFS has filesystem transparency. OPFSCoopSyncVFSThis is a new synchronous VFS that persists to OPFS. Because it does not need an Asyncify (or JSPI) build it should have similar performance to AccessHandlePoolVFS when used on a single connection. Unlike AccessHandlePoolVFS, however, it does support multiple connections. One restriction with this VFS is it does not support transactions involving multiple databases (not counting temporary databases). OPFSCoopSyncVFS has filesystem transparency, which means that it should be able to read databases written by the old OriginPrivateFileSystemVFS (but not AccessHandlePoolVFS). Here is a demo. OPFSPermutedVFSThis is a new type of VFS described here. It is a lot like SQLite WAL (write-ahead logging) in that it allows simultaneous read transactions with a write transaction, but it is implemented entirely within a VFS and does not use a separate WAL file. OPFSPermutedVFS uses the OPFS access handle locking modes proposal, which is currently supported only on Chromium browsers. OPFSPermutedVFS does not have filesystem transparency except immediately after VACUUM. Here are demos for asynchronous builds using Asyncify and JSPI (for JSPI, note that current browser support is Chrome behind a flag). |
Beta Was this translation helpful? Give feedback.
-
API changes for 1.0
|
Beta Was this translation helpful? Give feedback.
-
@rhashimoto So based on what's written here OPFSCoopSyncVFS looks like the best of both worlds, speed of accesshandlepool but with multiple connections, is there a catch? |
Beta Was this translation helpful? Give feedback.
-
I'm making some major changes in a branch that I hope will wind up as a 1.0 release at some point this year:
This is going to break some things. Writing a VFS will definitely be different, not conceptually but in the details. The set of example VFS classes will be different.
I'm not expecting many changes in the sqlite3_* API wrappers - if there are any, most likely it will be in functions that take callbacks.There will also be changes in the sqlite3_* wrappers but typical usage should not be a difficult migration.I'm not certain whether I'll continue to support modules, aka virtual tables. Converting those structs and arrays across languages is super detailed and annoying for something I don't need myself, and there is an awkward problem that makes it difficult for one implementation to work on both Asyncify and JSPI. If it doesn't happen and someone really wants it, I can guide a PR or I could do it under a sponsorship or contract.
I'll post updates in this thread as things progress.
Beta Was this translation helpful? Give feedback.
All reactions