1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-12 16:40:40 +08:00

refactor: 架构升级

This commit is contained in:
小莫唐尼
2026-08-31 07:58:23 +08:00
commit ba5b77568b
693 changed files with 118430 additions and 0 deletions
@@ -0,0 +1,45 @@
# 云数据库 CRUD
## 官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
## 新增数据
```javascript
const db = uniCloud.database()
const users = db.collection('users')
users.add({
name: 'Alice',
age: 20
}).then(res => {
console.log('新增 ID', res.id)
})
```
## 查询数据
```javascript
users.get().then(res => {
console.log(res.data)
})
```
## 更新数据
```javascript
users.doc('doc-id').update({
age: 21
})
```
## 删除数据
```javascript
users.doc('doc-id').remove()
```
## 参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html
@@ -0,0 +1,19 @@
# 云数据库索引
## 官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
## 使用场景
- 提升高频查询性能
- 支持复合索引提升多条件查询效率
## 示例
- 在 uniCloud 控制台为集合创建索引
- 为常用的查询字段(如 userId、createdAt)建立索引
## 参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html
@@ -0,0 +1,23 @@
# 云数据库权限控制
## 官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/
## 说明
- 通过数据库权限规则限制读写
- 配合用户身份(如用户登录态)实现访问控制
## 示例(规则示意)
```json
{
"read": true,
"write": "auth.uid == _id"
}
```
## 参考资源
- https://doc.dcloud.net.cn/uniCloud/
@@ -0,0 +1,40 @@
# 云数据库查询
## 官方文档
参考官方文档:https://doc.dcloud.net.cn/uniCloud/database.html
## 条件查询
```javascript
const db = uniCloud.database()
const users = db.collection('users')
users.where({
age: db.command.gt(18)
}).get().then(res => {
console.log(res.data)
})
```
## 排序与分页
```javascript
users.orderBy('createdAt', 'desc')
.skip(0)
.limit(10)
.get()
```
## 字段筛选
```javascript
users.field({
name: true,
age: true
}).get()
```
## 参考资源
- https://doc.dcloud.net.cn/uniCloud/database.html