B4J Question [SithasoDaisy5] IndexedDB

aeric

Expert
Licensed User
Longtime User
Hi @Mashiane
You mentioned in this thread
that you are using IndexedDB as Back-End.

Q1: Is this only for developer's use during development? I mean not for end clients?

Q2: If the answer for Q1 is No, I assume multiple end users also share or accessing the same Back-End storage. What if one user deleted the db, would it applies to all users?
 

Mashiane

Expert
Licensed User
Longtime User
Thanks for your question, from the horses mouth

IndexedDB is a way for you to persistently store data inside a user's browser. Because it lets you create web applications with rich query abilities regardless of network availability, these applications can work both online and offline. IndexedDB is useful for applications that store a large amount of data (for example, a catalog of DVDs in a lending library) and applications that don't need persistent internet connectivity to work (for example, mail clients, to-do lists, and notepads).

IndexedDB lets you store and retrieve objects that are indexed with a "key." All changes that you make to the database happen within transactions. Like most web storage solutions, IndexedDB follows a same-origin policy. So while you can access stored data within a domain, you cannot access data across different domains.

So

A1. Yes, it can be used by clients, but on a same domain, as the data is stored on the client browser, other users CANNOT access it unless you sync it to some other back-end. Multiple tabs on the same browser can access it though but they will have to sync data in some way I guess.

Usually, when your app starts, it creates the DB on the user browser space including the tables etc if they dont exist. With BANano this is through BANanoSQL aka AlaSQL

A2. Multiple users cannot access the IndexedDB on your browser. (As explained in Q1 above)

As the browser can "delete" your data when it sees fit / automatic eviction or when you clear browser data, usually the best option is to use CouchDB, which is an indexedDB with sync functionality.

For example, you can use IndexedDB for offline use and then sync data to PocketBase, MySQL or other databases. In my examples, the use of IndexedDB is just for demonstration and not for fully fledged apps due to the examples not having any sync functionality. For the LowCode tool, I have now added a download functionality so that one can download their projects & upload them. This acts as a manual backup/restore kinda functionality.

Yes, one can tell the browser not to evict your DB by using the storage api. One can also add functionality on their app to check if your db is empty when the app starts for example.

Overall, using IndexedDB without sync functionality is a risky proposition.

I hope that helps.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
  1. The IndexedDB is not suitable as a data storage for sharing across multiple users such as in enterprise environment web app?
  2. However you mentioned in same domain. Do you mean by domain name or network domain such as Lan or VPN? Is it like CORS where different port numbers are different domain even on same host?
  3. This low code solution is better if extended to use with another backend solution. You have covered this on another tutorial?
  4. There is a restriction on the CORS to handle. It is possible if this can be solved but I don't see it is trivial as I am clear about the "server" part that allow to configure this. Maybe some kind of reverse proxy thing that I don't understand.
  5. Is the IndexedDB a NoSQL db and we need to use some kind of build in functions?
  6. There is no way to hide any of the tables inside the database from certain users. So better not to store any sensitive data. Maybe need to implement some encryption methods.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
The IndexedDB is not suitable as a data storage for sharing across multiple users such as in enterprise environment web app?
Directly, it's not suitable and not possible.

With CouchDB, 100% yes. CouchDB is more like SupaBase/PocketBase/FireBase. It uses IndexedDB with sync functionality and you can use it online directly or offline with sync in whatever intervals. This needs VPS hosting as you run it on a particular port. You have an admin panel to create your DB and schemas and anyone who accesses it will have their own version of the DB from last time they sync. Its has a very good replicating model.

Do you mean by domain name or network domain such as Lan or VPN? Is it like CORS where different port numbers are different domain even on same host?
An origin is defined by the scheme, host, and port of a URL, so yes.

This low code solution is better if extended to use with another backend solution. You have covered this on another tutorial?
Yes, the LowCode tool will support generated code that will work with (1) MySQL/SQLServer/PostGres/SQLite (PHP), (2) PocketBase (VPS), (3) FireBase, (4) CouchBase (VPS). This is on the cards.

The numbers before the supported back-ends are based on how I will release the LowCode tool for the upcoming versions.

(1) - This will be PHP and based on https://github.com/mevdschee/php-crud-api (with some tweaks I made)

For how the LowCode tools works internally in terms of storing your project definitions etc, for now, it uses IndexedDB. These can be backed up and restored. I will however extend it to use a multi-user database for those who want to teach others like a school of children etc etc.

I think 4,5,6 are more related to IndexedDB.

Encryption is possible, yes its NOSQL key-value storage. AlaSQL makes it work like a normal sqlite db as you execute normal sql commands with that. I guess access you can control at app level. All these are possible with the CouchDB version of IndexedDB.
 
Upvote 0
Top