💿 Client Database
Client Database called CDatabase is used to store data like a common database, but it is done on the client side. To use CDatabase we need to define Collections which we will use when defining objects.
// prepare the collection whitch we want to create
const collections = [
{ collection: 'User', key: 'id', autoIncrement: true },
];
// create collection list from collection
CDatabase.upgrade(collections);
After creating the database object, we can inspect it in our browser's dev tool. If we use Google Chrome or Mozilla Firefox, we can press the ctrl + shift + i button to display the browser developer tools. After opening the dev tools, then for Google Chrome select the Application menu and select IndexedDB, it will appear as shown in the figure below.
For the Mozilla Firefox browser, you can select the Storage menu and select IndexedDB, it will appear as shown in the figure below.
Data Transactions
Add Data
To add data to the database object, we can use the add command, as shown in the example below. To check whether the data has been successfully added, we can check IndexedDB in our browser's dev tools
CDatabase.add('User', { name: 'Indra Jati', email: null });
Update / Set Data
To add data to the database object, we can use the add command, as shown in the example below. To check whether the data has been successfully added, we can check IndexedDB in our browser's dev tools
CDatabase.put('User', 1, { name: 'Indra Jati', email: null });
Get Data
To add data to the database object, we can use the add command, as shown in the example below. To check whether the data has been successfully added, we can check IndexedDB in our browser's dev tools
const collectionData = await CDatabase.get('User');