• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with cdb_sync - What is the local table?
#1
I am not understanding cdb_sync. This is really the only function that I do not understand and I believe it is probably the most useful of them all. So any help would be greatly appreciated! 

In the documentation for the command, it says:

--
Summary

This function will sync all records in a specified table between local and cloud. 
--

My question is: What is a local table? Is this a field or datagrid on a card? Do I export this table from the cloud to my local Livecode project? Or, do I create this local table from scratch and, if so, do all rows and columns have to match? I guess what I am asking is what constitutes a local table?


Many thanks in advance!
  Reply
#2
Hi JereMiami,

A table is just an internal container for a collection of records. Tables exist both on the device, "local", and on the cloud, "cloud". Records can be in a "local" table, a "cloud" table, or both. A table can be created through LCM or with cdb_createTable.

A lot of the APIs have a pTarget parameter that can either be "local" or "cloud", this specifies whether the API should be performed on a "local" table or a table on the "cloud". Let's use cdb_create(pDataA, pTable, pTarget, pInternalA) and cdb_update pDataA, pTable, pRecordID, pTarget, pInternalA as an example.

If we pass "local" to cdb_create, the record will be stored on the device itself. If we pass "cloud", the record will be sent to our servers where it'll be stored. If we create a record on the cloud, there is no "local" record. This means that if we want to update the record, we need to pass "cloud" to cdb_update as well so the record on the cloud can be updated.

cdb_sync can copy the record from the "cloud" table to the "local" table. This allows us to modify the record on the device, without the need to wait for a network transaction. This means we can modify the "local" record all we want, faster than modifying the "cloud" record since there is no wait, then copy it back to the cloud using cdb_sync again when we choose to.

Sorry for the long response. Hopefully I answered your questions. Let me know if you need further clarification.
  Reply
#3
Excellent response. Thank you!
  Reply
#4
(12-05-2019, 09:28 PM)efrain.c Wrote: If we pass "local" to cdb_create, the record will be stored on the device itself. If we pass "cloud", the record will be sent to our servers where it'll be stored. 

Hi @efrain.c -- just to clarify...

If i download the LiveCloud Toolkit as per normal and pass 'local' to cdb_create, it will will replicate the table structure on disk? 
I won't have to first create a table locally with cdb_createTable?

On a related note, if i do create a new local table with cdb_createTable, and use cdb_sync, will it create a new table in the cloud?

Many thanks for clarifying,
Stam
  Reply
#5
Hi stamatis,

cdb_createTable (https://docs.livecloud.io/CreateTable/) does not have a parameter for "local" or "cloud" and requires internet access so you cannot create local tables. All tables are created on the cloud and a config file defines your table structure on disk. The LiveCloud Toolkit has the config files that contains the structure of your project and all the tables in it. Because of this, cdb_create and cdb_sync can only be used on tables that already exist on the cloud.
  Reply
#6
(09-08-2020, 08:13 PM)efrain.c Wrote: Hi stamatis,

cdb_createTable (https://docs.livecloud.io/CreateTable/) does not have a parameter for "local" or "cloud" and requires internet access so you cannot create local tables. All tables are created on the cloud and a config file defines your table structure on disk. The LiveCloud Toolkit has the config files that contains the structure of your project and all the tables in it. Because of this, cdb_create and cdb_sync can only be used on tables that already exist on the cloud.

Thanks efrain.c - ok that's beginning to make sense then. 
In effect it's only possible to create databases in the cloud and to have local database these would have to to be synced to local with cdb_sync or cdb_batchsync?


Just a question about standalone LiveCloud apps with local DBs then 
The copied CanelaDB folder will be included at root folder of the app and will contain the local database, but this may not be a writeable location which would make it a read-only presumably.

If there is no internet access, what would be the strategy to maintain a local DB, if that's even possible? Can the CanelaDB be maintained in a writeable location such as Documents?
  Reply
#7
Yes, it's only possible to create databases in the cloud but records can be created locally or in the cloud. cdb_sync and cdb_batchSync are used to sync records between local and cloud. If you use cdb_create and pass "local" to it, the record will be created on the device. You can then use cdb_sync to upload this record to the cloud.

The location needs to be writable to create local records.

Can you elaborate more on what you mean by "maintaining" a local database?
  Reply
#8
(09-10-2020, 06:02 PM)efrain.c Wrote: Yes, it's only possible to create databases in the cloud but records can be created locally or in the cloud. cdb_sync and cdb_batchSync are used to sync records between local and cloud. If you use cdb_create and pass "local" to it, the record will be created on the device. You can then use cdb_sync to upload this record to the cloud.

The location needs to be writable to create local records.

Can you elaborate more on what you mean by "maintaining" a local database?

Thank you efrain.c - the question was basically summarised in your last two sentences. If the /Applications folder is not writeable then a local DB cannot be used - the app would need to be stored elsewhere, which is not desirable. Or use a cloud based DB, but that would require internet access.

This is different from other solutions where i can for example create and maintain a SQLite file in the user's Documents folder which is always writeable (and by maintain i mean performing CRUD operations, if that wasn't clear).

I'm basically asking if the LiveCloud database can be saved in a writeable location separate from the app?
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)