API References

Easy steps to use Client Data Storage

This session will discuss API reference for clientdatastorage

💾 Client Database

Data Transactions
 Upgrade ( Add Collection )

To create a new collection, you need to upgrade the database in this way. you can use the upgrade function as shown in the example below.

const collections = [
  { collection: 'User', key: 'id', autoIncrement: true },
];

CDatabase.upgrade(collections);

Parameter Desc Type Required
collections collections you want to add array true

Collection format

const collections = [
  { collection: 'User', key: 'id', autoIncrement: true },
];

Parameter Desc Type Required
collections the name of the collection you want to create String true
key the field that will be used as the key. if the insert data is not included, it will be generated automatically, only if autoIncrement is true String true
autoIncrement determines whether id is autoincremented or not. Boolean true
 Add Data

To add data to the database object, we can use the add function, as shown in the example below.

CDatabase.add(collectionName, data);

Parameter Desc Type Required
collectionName
target collection name string true
data
data to be added dynamic true
 Update / Set Data

To update data to the database object, we can use the put function, as shown in the example below. when you use the put function and there is no id available, system will generate the data automatically (set data).

CDatabase.put(collectionName, id, data);

Parameter Desc Type Required
collectionName
target collection name string true
id
id target data to be added string true
data
data to be added dynamic true
 Get Data

To get data to the database object, we can use the get function, as shown in the example below.

const collectionData = await CDatabase.get(collectionName);

Parameter Desc Type Required
collectionName
target collection name string true
Parameter Desc Type Required
collectionName
target collection name string true
Simple Query
 Singgle Condition

To create a simple query, you can use the where function. as shown in the example below.

// query
CDatabase.where(criteria, condition, value);
// get data with query
const data = await CDatabase.get(collection);

Parameter Desc Type Required
criteria the key of collection's data name string true
condition the query condition ( "==" , "<" , "<=" , ">" , ">=" ) string true
value value we want to search string true
 Multi Condition

To create a simple query, you can use the where function. as shown in the example below.

// query
CDatabase.where([[criteria, condition, value], [criteria, condition, value]]);
// get data with query
const data = await CDatabase.get(collection);

Parameter Desc Type Required
criteria the key of collection's data name string true
condition the query condition ( "==" , "<" , "<=" , ">" , ">=" ) string true
value value we want to search string true

💾 Client Storage

Data Transactions for Local Storage
 Add Local Data

To add data to the local storage, we can use the addLocal function, as shown in the example below.

CStorage.addLocal(collectionNamedata);

Parameter Desc Type Required
collectionName
target collection name string true
data
data to be added dynamic true
 Update / Set Local Data

To add data to the database object, we can use the putLocal function, as shown in the example below.

CStorage.putLocal(collectionNameiddata);

Parameter Desc Type Required
collectionName
target collection name string true
id
id target data to be added string true
data
data to be added dynamic true
 Get Local Data

To add data to the database object, we can use the getLocal function, as shown in the example below.

const collectionData = await CStorage.getLocal(collectionName);

Parameter Desc Type Required
collectionName
target collection name string true
Data Transactions for Global Storage
 Add Global Data

To add data to the database object, we can use the addGlobal command, as shown in the example below.

CStorage.addGlobal(collectionNamedata);

Parameter Desc Type Required
collectionName
target collection name string true
data
data to be added dynamic true
 Update / Set Global Data

To add data to the database object, we can use the putGlobal command, as shown in the example below.

CStorage.putGlobal(collectionNameiddata);

Parameter Desc Type Required
collectionName
target collection name string true
id
id target data to be added string true
data
data to be added dynamic true
 Get Global Data

To add data to the database object, we can use the addGlobal command, as shown in the example below.

const collectionData = await CStorage.getGlobal(collectionName);

Parameter Desc Type Required
collectionName
target collection name string true