针对实体和扩展存储数据

针对实体和扩展存储数据

数据存储:根据实体和扩展程序存储数据

在为 Zoho Projects 构建扩展程序时,您可能需要将扩展程序的数据存储在某个地方。我们使用键值对来根据实体和扩展程序存储此类数据。因此,无需使用 RDBMS 等以行和列形式存储数据的传统数据库。

实体属性

什么是键值对?

“键值”是一种存储数据的格式。您可以将实体或扩展程序的属性 (property) 存储在键值对中。键是一个唯一的字符串,值是一个 JSON 对象。会话信息、用户资料和偏好设置等数据都可以存储为键值对。您可以根据我们支持的实体以及您为 Zoho Projects 开发的扩展程序存储数据。

 

根据实体存储数据

Zoho Projects 支持项目、任务和问题实体。您可以根据各自的实体存储特定于项目、特定于任务或特定于问题的数据。键是一个唯一的字符串,数据是一个 JSON 对象,将来必须使用该键进行标识。您可以分别使用以下方法存储、检索、更新和删除根据实体存储的数据。

 


 

entity.store

存储实体的数据。

var value = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample.png"}
];
var count = 1;
zohoprojects.entity.store("6573492", value, count).then(function(response)
/* Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"sample.png\"}]",
      "count" : 1,
      "id": 1587134426
    }
  ]
}
*/
); 


Arguments

Argument name

Data type

Description

key

string

用于标识实体属性的唯一字符串。稍后只能使用此键来检索数据。

Note: Max length: <200> TBD

value

JSONObject

必须针对实体存储的属性/数据。

count

Integer

针对实体存储的发生次数。

 

entity.retrieve

检索针对实体存储的数据。此方法的参数应为存储相同数据时使用的键。


zohoprojects.entity.retrieve("6573492").then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"update.png\"}]",
      "id": 1587134426,
      "count: 1
    }
  ]
}
*/
);

 

entity.update  

更新针对实体存储的数据。此方法的参数是一个 JSON 对象,具有以下四个预定义键:

Argument name

Data type

Description

id

string

The ID that was generated as the output while storing the current key against the entity using the entity.store() method.

key

string

The new key has to be mapped against the entity. You can also choose to retain the old/current key.

value

JSON Object

The data or property that has to be updated against the entity.

count

Integer

Number of occurrences updated against the entity.

 

var valueObj = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample_New.png"}
];
zohoprojects.entity.update({id:"1587134426",key:"6573492",value:valueObj,count:2}).then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"Sample_New.png\"}]",
      "id": 1587134426,
      "count" : 2
    }
  ]
}
*/
);

 

entity.remove  

删除针对特定实体存储的数据。此方法的参数是使用“entity.store()”方法存储相同数据时生成的输出 ID。


zohoprojects.entity.remove(1587134426).then(function(response)
/* Output
{
  "status": "success"
}
*/
);


实体属性的限制

每个键存储的值一次不应超过 50KB。

此方法不能在“app_settings”、“attachment_picker”、“blueprint_during”和“top_band”位置调用。

存储在实体属性中的值应采用有效的 JSON 格式。

并发编辑实体属性无法确保一致性。例如,当两个不同的用户同时更改同一实体属性时,只会保存最新的更改,而之前的更改将丢失/被覆盖。


app.store
  
根据扩展存储数据。

var value = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample.png"}
];
zohoprojects.app.store("6573492", value).then(function(response)
/* Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"sample.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

 

Arguments

Argument name

Data type

Description

key

string

Unique string used to identify the extension property.

value

JSONObject

Property/Data that has to be stored against the extension.


app.retrieve  

检索扩展程序存储的数据。此方法的参数应为存储数据时使用的键。仅当从存储数据的扩展程序调用此方法时,才能检索数据。卸载扩展程序后,数据将被删除。

zohoprojects.app.retrieve("6573492").then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"update.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

 

app.update  

更新针对扩展程序存储的数据。此方法的参数是一个 JSON 对象,具有以下预定义键:


Argument name

Data type

Description

id

string

使用 app.store() 方法针对扩展存储当前密钥时作为输出生成的 ID。

key

string

必须与分机映射的新密钥。您也可以选择保留旧/当前密钥。

value

JSON Object

必须根据扩展更新的数据或属性。

 

var valueObj = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample_New.png"}
];
zohoprojects.app.update({id:"1587134426",key:"6573492",value:valueObj}).then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"Sample_New.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

 

app.remove  

删除针对特定扩展程序存储的数据。此方法的参数是使用 app.store() 方法存储相同数据时生成的输出 ID。


zohoprojects.app.remove(1587134426).then(function(response)
/* Output
{
  "status": "success"
}
*/
);

 

扩展属性的限制

  • 针对每个键存储的值一次不得超过 50KB。

  • 每个扩展最多只能存储 100 个键值对。

  • 存储在扩展属性中的值应采用有效的 JSON 格式。

  • 同时编辑扩展属性无法确保一致性。例如,当两个不同的用户同时更改同一扩展属性时,只会保存最新的更改,而前者的更改将被丢失/覆盖。

您可以分别使用以下方法存储、检索、更新和删除您在扩展中存储的数据。