关于

Datastore API 是 dropbox 已经废弃的功能,不过 dropbox 将 jssdk 开源,这样对于研究 A-CS 实现有很好的参考价值, 这里将它翻译出来,既当备份也当对 datastore 的设计有个基本的了解

Datastore 介绍

官方的介绍是,应用不仅仅是存储和同步文件,通过 Datastore API , 结构化的数据如联系人列表,任务列表,游戏状态都可以像文件同步一样简单。 并且 Datastore 支持多平台,离线访问,自动冲突解决。并且可以通过浏览器查看所有应用的数据 https://www.dropbox.com/developers-v1/br... 。

应用实例

  1. lists

  2. click the box

总结而言, Datastore 就是结构化数据的 A-CS 的实现

Datastore API 基本概念

Client and datastore manager

用户在客户端通过 app_key 启动 dropbox 认证,认证通过后,就可以在客户端创建 datastore manager 实例, 通过 manager 可以获取 datastores 列表,监听 datastore 的变化, 同步 datastore, 更新 datastore

Datastores and tables

datastores 是应用结构化数据的容器, 每一个 datastore 是一个 tables 的集合,每个 table 是一个 records 的集合。 同数据库一样

  • datastore <-> 数据库

  • table <-> 数据库表

  • record <-> 数据记录

当一个 datastore 被打开过后就会被缓存到本地,这样就可以实现应用数据的离线访问,每个 datastore 是相互独立的, 当一个 datastore 改变的时候,会自动同步数据到 dropbox, 也可能会将 dropbox 的新数据(其他客户端的改变)同步到本地。

用户之间可以分享数据, 分享的基本单元是 datastore ,

Records

records 是应用存储数据的基本单元,每个 record 有一个或任意多个 fields 组成,有一个 ID , 每个 field 是 {key: value} 的组合, value 可以是基本数据,也可以是基本数据的数组, 基本数据

  1. String (String)

  2. Boolean (Boolean)

  3. Integer (Dropbox.Datastore.int64)

  4. Floating point (Number) – IEEE double. All native JavaScript numbers will be interpreted as floating-point numbers. To store integers, use the Dropbox.Datastore.int64 type.

  5. Date (Date) – POSIX-like timestamp stored with millisecond precision.

  6. Bytes (Uint8Array) – Arbitrary data, which is treated as binary, such as thumbnail images or compressed data. Individual records can be up to 100KB, which limits the size of the data.

  7. List (Dropbox.Datastore.List) – A special value that can contain other values, though not other lists

和 SQL 不同的是, datastore 中的 table 不包含 schema , 所以 每个 record 可以有任意数目的 field

查询 records

var results = taskTable.query({completed: false}); var firstResult = results[0];

监听 record 变化

datastore.recordsChanged.addListener(function (event) { // affectedRecordsForTable 判断哪些记录变化了console.log('records changed:', event.affectedRecordsForTable('tasks'));
});

定制冲突解决方案

datastore 会自动的以 field 为基本单位合并改变 , 举个例子, 如果用户在一个客户端上修改了 taskname 和 complete 状态,在另外的一个设备上 datastore api 会没有冲突的自动合并这个改变。

如果同时的改变了相同 record 的相同 field, 这就需要解决冲突了, 可以自定义冲突解决规则

taskTable.setResolutionRule('completed', 'local');

总共有 5个规则

  1. remote – The remote value will be chosen. This is the default behavior for all fields.

  2. local – The local value of the field will be chosen.

  3. max – The greater of the two changes will be chosen.

  4. min – The lesser of the two changes will be chosen.

  5. sum – Additions and subtractions to the value will be preserved and combined.

分享 datastore

// Shareable datastore
datastoreManager.createDatastore(function (error, datastore) {/*** 给一组用户设置角色 (principal)* 第一个参数是表示分享给谁Dropbox.Datastore.PUBLIC – The role will apply to all Dropbox users.Dropbox.Datastore.TEAM – The role will apply to everyone on the user's team (only applicable for Dropbox for Business * 第二个参数表示分享模式Dropbox.Datastore.NONE – The principal has no access to this datastore.Dropbox.Datastore.VIEWER – The principal is able to view this datastore.Dropbox.Datastore.EDITOR – The principal is able to edit this datastore.Dropbox.Datastore.OWNER – The principal is the owner of this datastore. This role cannot be assigned directly. The user who created a datastore is always that datastore's owner.*/datastore.setRole(Dropbox.Datastore.PUBLIC, Dropbox.Datastore.EDITOR);
});// 接受分享的用户
datastoreManager.openDatastore(datastoreId, function (error, datastore) {// The datastore is now shared with this user.
});// 列举 datastore的访问人列表
datastore.listRoles()// 获取当前用户的 role
datastore.getEffectiveRole()

DropBox Datastore API 翻译相关推荐

  1. python运行界面英文翻译_python使用百度api翻译中英文

    python使用百度api翻译中英文 写程序取变量名的时候,常常需要翻译单词,或者将中文翻译成英语.有道词典,必应词典都很好,可是...命令行习惯了还是觉得用在cmd里面调出程序使用起来也许会更爽.于 ...

  2. java使用谷歌api翻译读写Excel

    因为公司做的系统是全球都会使用到,所以我们每个版本可能都会更新一些新的多语言. 有的语言是有专业的人员翻译好过来的,但是还有的语言需要自己这边来进行翻译. 所以下面写了一个读写Excel翻译供大家参考 ...

  3. [译] 使用谷歌Cloud Translation API翻译文本

    CSDN广告邮件太多了,邮箱已经屏蔽了CSDN,留言请转SegmentFault:https://segmentfault.com/a/1190000014205232 原文:Translation ...

  4. Python实现调用百度API翻译文字

    调用百度API翻译文字 最近复制别人的代码实现百度API翻译文字,总是报错: {'error_code': '52003', 'error_msg': 'UNAUTHORIZED USER'} 后来发 ...

  5. 有道云翻译API翻译JavaScript使用教程

    有道云翻译API翻译使用教程 一.注册: 前往有道智云AI开放平台进行注册. 然后填写进入免费体验试用进行资料填写. 二.创建应用: 进入上图1,创建应用如下图:执行1.2. 进入上上图2,创建实例如 ...

  6. Express4.x api 翻译(draft)

    用了一年多的Express了,其实会用的功能也能基本满足业务的需求,但是总是感觉自己对其的掌握还是缺少一种系统性.故翻译其api,以期自己在翻译过程中对其有更深的认识. API 原文地址 翻译的内容还 ...

  7. 【android API】 ListView api 翻译

    ListView虽然常用,可是还没有系统的知道他.先从API开始吧.http://developer.android.com/reference/android/widget/ListView.htm ...

  8. Sizzle 官方API翻译

    Sizzle源码解析[原创内容,欢迎转载,如有错误,概不负责~~] Sizzle官方文档上说,Sizzle Api由三个部分构成. Public API - 用户使用 Extension API - ...

  9. python百度翻译接口_python3 调用百度翻译API翻译英文

    自行申请百度开发者账号import importlib,sys,urllib importlib.reload(sys) import urllib.request import json #导入js ...

最新文章

  1. MySQL面试题 | 附答案解析(一)
  2. 深度学习(二十七)可视化理解卷积神经网络(反池化 pooling unpooling)
  3. [SQL] SQL 基础知识梳理(三) - 聚合和排序
  4. ref 参数与 out 参数
  5. python PyQt5 QMainWindow类(Qt主窗口框架,主窗口提供了用于构建应用程序用户界面的框架)
  6. SSM+Netty项目结合思路
  7. Glusterfs初试
  8. 软键盘弹起,导致底部被顶上去
  9. 【报告分享】华为-5G时代运营商数据和存储架构白皮书.pdf(附下载链接)
  10. 基金投资需要注意什么?
  11. 论文笔记_S2D.01-2018-ICRA_Sparse-to-Dense:从稀疏深度样本+单一图像的深度预测
  12. atitit.基于http json api 接口设计 最佳实践 总结o7
  13. 程序员英文简历范例(通用,含初级、中级和高级)
  14. 为什么俺推荐Python「1」:作为脚本语言的Python
  15. 腾讯优酷土豆爱奇艺视频,视频消重技术批量自动去水印加水印软件 新浪自媒体视频,去重复消重伪原创...
  16. 微软服务器2016各版本区别,Win10系统有几个版本?Windows10各版本区别详细介绍
  17. C++中的五种构造函数
  18. 2022年第二十三届华东杯大学生数学建模竞赛
  19. java scriptrunner,java使用ScriptRunner执行sql文件
  20. 搭建kinect for windows开发平台

热门文章

  1. C++后端开发程序员应该彻底搞懂的【libevent网络库】,libevent组件构成以及编程要领丨Linux服务器开发丨服务端编程
  2. 统计学——独立性与相关性检验
  3. Ubuntu桌面入门指南(转载)
  4. 解决automake1.14编译问题
  5. FTPClient 判断文件是否存在
  6. java 等待池,Java等待池中的所有线程
  7. hbase 数据导出乱码_赶尽杀绝:Stata中文乱码之转码
  8. [数字媒体] PR视频剪辑之自定义音频、视频加速转场和特显停顿
  9. 连发数枪,海尔离“世界中心”仅一步之遥
  10. NetSuite中国- 特瑞格(北京)网络技术有限公司