CRUD

Creating records

You can create a record that will be stored both locally and in the cloud by calling the cdb_saveRecord() function. When the function completes, the output will contain the unique record id for the saved record. Build an array with keys that match your schema:

put "John" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put cdb_saveRecord(tDataA) into tRecordID

Optionally, we are going to error check the result of our save on the following line:

if not cdb_result() then
     --We encountered an error
     put cdb_result("response") into tWhatHappened
end if

Alternatively, we can save a record in the cloud only by calling the cdb_createCloudRecord() function:

put "John" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put cdb_createCloudRecord(tDataA) into tRecordID
if not cdb_result() then put cdb_result("response") into tWhatHappened

We can also store the record locally only by calling the cdb_createLocalRecord() function:

put "John" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put cdb_createLocalRecord(tDataA) into tRecordID
if not cdb_result() then put cdb_result("response") into tWhatHappened

Read records

We can read a record from the cloud and automatically update our local version of the record if needed by using the cdb_getRecord() function:

put cdb_getRecord("7ba3344d-9b98-4d1b-863a-86be3b57dc76") into tRecordA

Optionally, we are going to error check the result of our get on the following line:

if not cdb_result() then
      --We encountered an error
      put cdb_result("response") into tWhatHappened
end if

tRecordA is an array with your key/values for this record. Using the created data above, this would return the following:

put tRecordA["firstName"]

output: John

put tRecordA["lastName"]

output: Doe

put tRecordA["csiRecordID"]

output: 7ba3344d-9b98-4d1b-863a-86be3b57dc76

We can also read the record from the cloud and not save anything locally by calling the cdb_readCloudRecord() function:

put cdb_readCloudRecord("7ba3344d-9b98-4d1b-863a-86be3b57dc76") into tRecordA
if not cdb_result() then put cdb_result("response") into tWhatHappened

Optionally, we can read the record locally as well by calling the cdb_readLocalRecord() function:

put cdb_readLocalRecord("7ba3344d-9b98-4d1b-863a-86be3b57dc76") into tRecordA
if not cdb_result() then put cdb_result("response") into tWhatHappened

Updating records

You can update an existing record both locally and on the cloud at one time using the cdb_saveRecord() function. By adding the option “csiRecordID” key to your array, the API will store the values in your array over the existing record.

We will update the first name from “John” to “Jane”:

put "Jane" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put "7ba3344d-9b98-4d1b-863a-86be3b57dc76" into tDataA["csiRecordID"]
put cdb_saveRecord(tDataA) into tRecordID

We can also update a record on the cloud only by calling the cdb_updateCloudRecord command. There is no output from using the cdb_updateCloudRecord command.

put "Jane" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put "7ba3344d-9b98-4d1b-863a-86be3b57dc76" into tDataA["csiRecordID"]
put cdb_updateCloudRecord(tDataA) into tRecordID

This time, we will update the record locally:

put "Jane" into tDataA["firstName"]
put "Doe" into tDataA["lastName"]
put "7ba3344d-9b98-4d1b-863a-86be3b57dc76" into tDataA["csiRecordID"]
put cdb_updateLocalRecord(tDataA) into tRecordID

Deleting records

To delete records, provide the record id or a line delimited list of record IDs to the cdb_deleteRecord command.

For example, let’s delete a single record “7ba3344d-9b98-4d1b-863a-86be3b57dc76”:

cdb_deleteRecord "7ba3344d-9b98-4d1b-863a-86be3b57dc76"

Optionally, we are going to error check the result of our delete on the following line:

if not cdb_result() then
     --We encountered an error
     put cdb_result("response") into tWhatHappened
end if

Here is how we would delete all records in a database:

put cdb_listLocalValues() into tAllRecordIDs
cdb_deleteRecord tAllRecordIDs
if not cdb_result() then put cdb_result("response") into tWhatHappened