As JSONStore behaves differently with Relational Database in Native, I am trying to understand JSONStore and how the best way to storing data in it.
For example if I have below JSON response from server and would like to store to offline storage:
{
"CID": "1020",
"CName": "Some names",
"Documents": [
{
"DocumentID": "12987",
"FilePath": "anyPath1",
"Signatures": [
{
"Path": "signPath1"
},
{
"Path": "signPath2"
}
]
},
{
"DocumentID": "12988",
"FilePath": "anyPath2",
"Signatures": [
{
"Path": "signPath3"
},
{
"Path": "signPath4"
}
]
}
]
}
First
What I can learn from other forum, it says to store them linearly, but I believe that it will be redundant to store same CID and DocumentID several times (for example), although I am not sure how to store some (amounts cannot be defined) Signatures:
var collections = {};
var collectionName = 'someName';
collections[collectionName] = {};
collections[collectionName].searchFields =
{CID: 'string', CName: 'string', DocumentID: 'string', FilePath: 'string'};
Second
Or I can do it by usual Relational Database technique:
Customers
var customers = {};
var customersColl = 'customers';
customers[customersColl] = {};
customers[customersColl].searchFields =
{CID: 'string', CName: 'string'};
Documents
var documents = {};
var documentsColl = 'documents';
documents[documentsColl] = {};
documents[documentsColl].searchFields =
{CID: 'string', DocumentID: 'string', FilePath: 'string'};
Signatures
var signatures = {};
var signaturesColl = 'signatures';
signatures[signaturesColl] = {};
signatures[signaturesColl].searchFields =
{DocumentID: 'string', SignaturePath: 'string'};
When use this technique, I believe it will be hard to maintain data removal. For example:
To remove certain customer, I need to get the respected customer in Documents and remove respected document in Signatures and remove the customer in Documents as there are no Foreign Key to 'automate' it.
Please give me advise which one/what is the most efficient way to do it.
Third
Approach from this post which I believe the best to store them linearly too.
You could use additional search fields as to prevent redudancy and you can make your document objects actual JSON objects. I have an example here.
Let me know if there are questions.