条件过滤和更新

条件更新包含条件过滤更新两部分内容,后者目前是指对数组的更新。

1. 使用说明

对于主要的增删改查接口,可以通过 condition 入参设置过滤条件,仅当条件满足时,才会返回查询的数据或才执行更新操作,否则返回错误码 COMMON_ERR_CONDITION_NOT_MATCHED

对于修改请求,可以通过 operation 入参设置更新操作,目前是指对数组的插入(PUSH)、删除(POP)、修改(SET)操作。

如:

int TcaplusCoroutinePbApi::FieldSet(
    const std::set<std::string> &dottedpaths, 
    google::protobuf::Message *msg,
    const std::string &operation,
    const std::string &condition);

示例

user u;
// 设置主键
u.set_id(1);
u.set_name("a");

// 设置递增的步长
u.set_rank(1);
// 当rank达到上限100之后,不再对rank递增,否则 +1
std::set<std::string> dottedpaths;
dottedpaths.insert("rank");
ret = api.FieldInc(dottedpaths, &u, "", "rank < 100");

上述 conditionoperation 是类 SQL 的文本,见《条件过滤和更新》。

2. 支持的接口

详情见《条件过滤和更新功能》§3。

在条件过滤、更新的支持下,使用 FieldSetFieldGet 可以实现类 Schema-free 的用法;与字段路径集合配合的具体形态见《部分字段查询和更新》。

3. 注意事项

详情见《条件过滤和更新功能》§7。

results matching ""

    No results matching ""