Copyright (2024) Bytedance Ltd. and/or its affiliates
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
简介
字节跳动鸿蒙生态数据库组件,支撑抖音集团部分鸿蒙应用数据库相关能力。
鸿蒙平台数据库能力以 relationalStore 相关接口提供给开发者,rdbStore 以DTO对象形式来进行数据库操作,封装数据库创建和自动升级、数据库谓词构建、查询结果反序列化、品质调优等能力,实现简单高效地进行数据库操作。
运维方面:完备单元测试、品质数据打点上报、全链路日志等。
仓库地址:https://github.com/bytedance/rdbStore
接入
更多技术支持: 邮件 gongshijie.gongsj@bytedance.com
能力简介
数据库创建
数据库操作
插入
RdbDao#batchInsert 批量插入数据(默认为insert or replace)
RdbDao#insert 插入数据
RdbDao#insertSync 同步主线程插入数据
代码示范:
删除
RdbDao#delete 删除数据
RdbDao#deleteSync 同步主线程删除
RdbDao#batchDelete 批量通过谓词删除
RdbDao#batchDeleteSync 批量通过谓词删除同步
RdbDao#deleteAll 删除所有
RdbDatabase#deleteDb 删除整个 db 文件
代码示范:
修改
RdbDao#update 完整更新数据
RdbDao#updatePartial 局部更新数据列
RdbDao#updateSync 同步更新数据
代码示范:
查找
RdbDao#predicatesBuilder 复杂查询通过 builder 构建
RdbDao#queryPredicate 通过传入谓词来查询且解析为对应 model
RdbDao#querySync 同步进行查询且解析为对应 model
RdbDao#querySql Sql 语句查询且解析为对应 model PredicatesBuilder#where 构建查询谓词
代码示范:
运维
RdbDao#getAllColumns 获取表中所有列
RdbDao#getTableCreateSql 获取表创建语句
RdbDao#getAllIndex 获取所有表索引
RdbDao#getCount 查询数据库中行数量
RdbDao#getPredicatesByKey 获取对应 model 主键的谓词
RdbDatabase#getAllTable 获取所有表
品质
TuneDbParamPlugin#setJournalMode
设置数据库的日志模式
TuneDbParamPlugin#setPageSize 设置数据库页大小,页是 SQLite 用于存储和管理数据的基本单位
TuneDbParamPlugin#setSynchronous
插入操作时的同步模式
TuneDbParamPlugin#setJournalSizeLimit
设置日志文件大小限制
升级
若仍想手动升级,可以通过配置 migration 进行升级
License