Verified Commit a6c6117b authored by Aral Balkan's avatar Aral Balkan
Browse files

Update readme

parent 42bec468
......@@ -201,7 +201,6 @@ Your database tables will be automatically closed if you exit your script. Howev
Here’s what you’d do to close the database in the above example:
async main () {
// … 🠑 the earlier code from the example, above.
......@@ -281,7 +280,7 @@ When you run it, you should see the following result:
## Dispelling the magic and a couple of gotchas
## Dispelling the magic and a pointing out a couple of gotchas
Here are a couple of facts to dispel the magic behind what’s going on:
......@@ -292,10 +291,14 @@ Here are a couple of facts to dispel the magic behind what’s going on:
- When you open a database, you get a Proxy instance back, not an instance of JSDB.
- Similarly, when you reference a table or the data within it, you are referencing proxy objects, not the table instance or the data itself.
### How the sausage is made
When you open a database, JSDB loads in any `.js` files it can find in your database directory. Doing so creates the data structures defined in those files in memory. Alongside, JSDB also creates a structure of [proxies]( that mirrors the data structure and traps (captures) calls to get, set, or delete values. Every time you set or delete a value, the corresponding JavaScript statement is appended to your table on disk.
By calling the `where()` or `whereIsTrue()` methods, you start a [query](#jsql-reference). Queries help you search for specific bits of data. They are implemented using the get traps in the proxy.
### Gotchas and limitations
Given that a core goal for JSDB is to be transparent, you will mostly feel like you’re working with regular JavaScript collections (objects and arrays) instead of a database. That said, there are a couple of gotchas and limitations that arise from the use of proxies and the impedance mismatch between synchronous data manipulation in JavaScript and the asynchronous nature of file handling:
1. __You can only have one copy of a database open at one time.__ Given that tables are append-only logs, having multiple streams writing to them would corrupt your tables. The JSDB class enforces this by forcing you to use the `open()` factory method to create or load in your databases.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment