0
由於JSONStore與Native中的Relational Database的行爲不同,我想了解JSONStore以及如何將數據存儲在JSONStore中。在JSONStore中有效存儲
例如,如果我有以下從服務器JSON響應,並想保存到離線存儲:
{
"CID": "1020",
"CName": "Some names",
"Documents": [
{
"DocumentID": "12987",
"FilePath": "anyPath1",
"Signatures": [
{
"Path": "signPath1"
},
{
"Path": "signPath2"
}
]
},
{
"DocumentID": "12988",
"FilePath": "anyPath2",
"Signatures": [
{
"Path": "signPath3"
},
{
"Path": "signPath4"
}
]
}
]
}
首先
我可以從其他論壇上學習,它說以線性方式存儲它們,但我認爲將相同的CID和DocumentID存儲多次(例如)會是多餘的,但我不確定如何存儲一些(金額無法定義)簽名:
var collections = {};
var collectionName = 'someName';
collections[collectionName] = {};
collections[collectionName].searchFields =
{CID: 'string', CName: 'string', DocumentID: 'string', FilePath: 'string'};
二
或者,我可以用通常的關係型數據庫技術,做到這一點:
客戶
var customers = {};
var customersColl = 'customers';
customers[customersColl] = {};
customers[customersColl].searchFields =
{CID: 'string', CName: 'string'};
文件
個var documents = {};
var documentsColl = 'documents';
documents[documentsColl] = {};
documents[documentsColl].searchFields =
{CID: 'string', DocumentID: 'string', FilePath: 'string'};
簽名
var signatures = {};
var signaturesColl = 'signatures';
signatures[signaturesColl] = {};
signatures[signaturesColl].searchFields =
{DocumentID: 'string', SignaturePath: 'string'};
當使用這種技術,我相信這將是難以維持數據刪除。例如:
要刪除某個客戶,我需要在Documents中取得受尊重的客戶,並刪除Signatures中受尊重的文檔,並刪除Documents中的客戶,因爲沒有外鍵可以「自動化」它。
請給我一個建議,哪一個/什麼是最有效的方法。
三
從這個post我認爲最好將它們存儲線性太方法。