-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an optional options argument to Database constructor #448
Conversation
Looks like the build failed due to some sort of network problem. I don't think this is related to my code; it's after the tests succeeded. Is there any way to retry it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I relaunched the build.
On the PR itself, I'm not sure the design is exactly right. Adding a second argument that makes the first argument illegal in some cases, but not all, referring to "file names" and ":memory:" even when everything is in memory, and referring to other file-related things is a little confusing. Also, there is no reason to disable export with other VFS, right ? The VFS can always be used to export the database as bytes.
And how would this PR articulate with the actual VFS creation ?
What I think would be more developer-friendly would be a design that would allow writing code like
const vfs = new IndexedDBVFS({ ...my_options });
const db = Database.with_vfs(vfs);
Thanks for retrying the build! I think we want the ability to specify the filename for a database; it's not a property of the VFS. And why not provide access to all the // This is outside the project domain.
const vfs = new IndexedDbVFS(whatever);
// This would call sqlite3_vfs_register.
Database.register_vfs("aName", vfs);
// Opening a database references VFS by name (not object).
// filename is required, flags is optional.
const db = Database.with_vfs("aName", filename, flags); And how would I implement this? Can I add a secret unsupported argument to the Somewhat off-topic, does the ES5 code style still make sense? The optimized builds go through the Closure compiler anyway and couldn't we presume that developers using debug builds would be working with something a bit more recent? |
I still don't think "filenames" do not make sense. The backend doesn't need to have (and in most cases won't have) a notion of file. Same for registering the VFS. This is an implementation detail that the user shouldn't have to worry about. For flags, they don't make sense for most VFS on the web, but if they do for one in particular, they can take care of it. Maybe I shouldn't call the javascript interface a "VFS", maybe just "backend". If there is a backend that is backed by actual files (on node.js, for instance), then it can offer the options to set a file name, file permissions, and so on. For the code style, yes, I agree working with modern js would be more pleasant ! We would have to make sure the result is still compiled to es5, though. |
About VFS registration, I think it should be handled by the library directly, not the user. The backend interface we define should expose a VFS, and sql.js will handle registering the VFS if it's absent when creating the database. |
I don't see filename as an implementation detail. I see it as part of the SQLite API. And the same with VFS. The Minimizing the abstraction also makes things easier for you, the maintainer. There's a lot less thought required if you're just exposing SQLite concepts and not inventing new ones. What's the naming convention? I see |
Yes, the SQLite API shouldn't be inaccessible to the developer, it should just not be directly visible in the cases where it is not relevant. I think the largest use case for this work is going to be the indexedDB backend, for which the notions of filename or file permissions don't make sense. We will simply let those who want to interact with sqlite at a lower level implement the Backend interface. An interface implementation could still wrap another one. About the naming convention: yes, we haven't been consistent in the past, when accepting the PR for create_function. I think we should go with camelCase. |
I don't agree, but it's certainly your prerogative to define the API. Given that this API is not the one that I would be using, perhaps it makes more sense for someone else to implement it. |
This replaces
sqlite3_open
withsqlite3_open_v2
and adds an optional options object argument to the Database constructor. The options object has 3 optional properties that match up with thesqlite3_open_v2
function:Providing the ability to select a VFS is prep for #447.