I just found something quite cool which I thought might be interesting to some of you.
The first thing that I was curious about was: How does it store the database file? Well, it creates a new database when you do SQL.open(). But you can pass data to SQL.open(data) to start with a pre-filled database. So I think using this library would normally look like this:
- fetch the initial database from the server (e.g using AJAX). At least DB schema and some important data.
- open the database with SQL.js
- do some operations on the database, mostly SELECTs probably
- maybe fetch some more data using AJAX from the server when needed
- maybe send some data to the server to save changes using form or ajax
I see two other interesting ways of using this:
- In combination with HTML5 local storage – this would allow to store a persistent client-side database that could be accessed using SQL. Sounds pretty cool and the main usage scenario of SQL.js for me.
- On the server using node.js – but when I think about it: There are better ways to access a database within node.js, so this is probably only showing that it works, but no real usage scenario.
Tell me what you think about it.