DallasHoff / sqlocal

SQLocal makes it easy to run SQLite3 in the browser, backed by the origin private file system.
https://sqlocal.dallashoffman.com
MIT License
322 stars 15 forks source link

sqlocal easy connect/disconnect #2

Closed MigFerreira closed 1 year ago

MigFerreira commented 1 year ago

I have a use case where I have to connect and disconnect on demand from databases. Because of this I have created a wrapper to manage this, as a singleton.

I think it could be useful if the sqlocal client wouldn't actually connect to database on construction if fileName param was empty, and add the ability to connect on demand.

Any thoughts?

DallasHoff commented 1 year ago

I'd like to understand your use case a bit more. Could you describe it in more detail? Why do you need to frequently connect to and disconnect from the same database file?

MigFerreira commented 1 year ago

I have a syncable (cloud storage) database per user. Basically each db will be .db connectable on login. Only thing remaining is check how I can add encryption.

DallasHoff commented 1 year ago

That's still not much to go on. I ask for more details so I can understand your use case and keep it in mind to potentially better support it as I work on the library. However, what you have described so far does not seem to necessitate adding an extra step to initialize the SQLocal client. As it is set up now, the SQLocal class essentially is your connection; you initialize it to connect, and call SQLocal.destroy() to disconnect. To make a new connection, you initialize another instance of SQLocal. I feel like this keeps things simple, but please let me know if there is something that you feel that I am not accounting for.

MigFerreira commented 1 year ago

Fair enough, what you described is basically what Im doing, I built a singleton wrapper with connect and disconnect that manages SQLocal instance. Understandable you want to keep sqlocal clean and simple.