angular - 使用 SQLite 代替存储/本地存储 Ionic 4 Native
问题描述
假设我想将聊天消息本地存储在 Ionic 4 应用程序中,但我不想每秒删除和插入,n
我可以使用单独的 SQLite 文件并确保我清理条目并且可以吗?
是的,因此出于安全原因和其他方面的考虑,我正在编写一个聊天应用程序,并得出结论,最好的办法是拥有一个可以存储所有消息的 SQLite 文件。现在我已经听到你的声音了,可能在你开始这部分之前说“嘿!!Ionic 4 和 Cordova 已经有一个插件!它是基于 SQLite 的!!” 您是对的,但是,它存储为键/值对,不允许任何类型的查询或表连接。以下方法可用(get、set、length、delete、forEach)。我想要的是一个简单的 update()。我在这里唯一能看到的是一种 noSQL 方法,其中更新只是删除和重新插入。
以下是存储内容的示例:
{
conversations: [
{id: 1,
people: ["Christian", "Sara"],
messages: [
{id: 1, author: "Christian" content: "hi", date: <date>},
{id: 2, author: "Sara", content: "foo", date: <date>},
{id: 3 ...}
]
},
{id: 2, person: "Laura", messages: [{}, {}, {}]
]
}
所以基本上我想做的是aINSERT INTO messages WHERE id = :id
或类似的东西,而不是类似的东西:
function update(){
const oldMessages = this.storage.forEach('messages')
.then(chat => {
//loop over the chat and store each chat object in the old array,
}
// set an interval that will retrieve the new messages
//and append them into the old messages, then finally delete the old key/value storage and then
db.set('messagesChristianAndSara', messageArrayOfObjects)
}
这是我想我会发现自己的情况。我宁愿只是想将对象推入或插入。
也许有一种方法,但文档并不清楚。
解决方案
推荐阅读
- r - `$<-.data.frame`(`*tmp*`, Predict, value = c(`1` = 1L, `2` = 1L, : 替换有 3500 行,数据有 1500
- sql - 如何通过 informatica 使用 sysdate 删除记录器
- php - 如何从存储在另一个 php 文件中的函数返回变量?
- python - 错误 conda.core.link:_execute(700): 安装包 'defaults::qt-5.9.7-vc14h73c81de_0' 时出错
- regex - 匹配赞比亚 NRC 号码的正则表达式模式是什么
- aws-sdk - Amazon SQS 侦听器 - 在消息失败之前使用消息并设置属性
- angular - 创建 Angular 项目时出错“无法加载,因为在此系统上禁用了运行脚本。”
- angular - 如何准备好提交给后端团队的 Angular 表单
- ruby - 如何在 Activercord 中更改 group_by 键和 group_by 值
- playframework - PPlay 2.6:Config中Configuration.path的等效API