Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
8115ea78
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5992
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
8115ea78
编写于
9月 14, 2023
作者:
雪洛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:(uniCloud): clientDB
上级
00cc3793
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
408 addition
and
0 deletion
+408
-0
pages.json
pages.json
+9
-0
pages/API/unicloud-database/unicloud-database.uvue
pages/API/unicloud-database/unicloud-database.uvue
+312
-0
pages/tabBar/API.uvue
pages/tabBar/API.uvue
+4
-0
uniCloud-aliyun/database/foreign.schema.json
uniCloud-aliyun/database/foreign.schema.json
+25
-0
uniCloud-aliyun/database/local.schema.json
uniCloud-aliyun/database/local.schema.json
+28
-0
uniCloud-aliyun/database/type.schema.json
uniCloud-aliyun/database/type.schema.json
+30
-0
未找到文件。
pages.json
浏览文件 @
8115ea78
...
...
@@ -900,6 +900,15 @@
}
}
,{
"path"
:
"pages/API/unicloud-database/unicloud-database"
,
"style"
:
{
"navigationBarTitleText"
:
""
,
"enablePullDownRefresh"
:
false
}
}
],
"globalStyle"
:
{
"pageOrientation"
:
"portrait"
,
...
...
pages/API/unicloud-database/unicloud-database.uvue
0 → 100644
浏览文件 @
8115ea78
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="dbAdd">新增单条数据</button>
<button type="primary" @click="dbBatchAdd">新增多条数据</button>
<button type="primary" @click="dbUpdate">更新数据</button>
<button type="primary" @click="dbGet">where传字符串获取数据</button>
<button type="primary" @click="dbGetWithCommand">where传对象获取数据</button>
<button type="primary" @click="dbRemove">删除数据</button>
<button type="primary" @click="dbLookupInit">初始化联表查询数据</button>
<button type="primary" @click="dbLookup">联表查询</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: 'ClientDB'
}
},
onLoad() {
},
onUnload() {
},
methods: {
dbAdd: function () {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.add({
num: 1,
tag: 'default-tag',
date: new Date(),
point: new db.Geo.Point(116, 38)
})
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `新增成功,id: ${res.id}`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbBatchAdd() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.add([{
num: 2,
tag: 'default-tag',
}, {
num: 3,
tag: 'default-tag',
}])
.then<void>((res) => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `新增成功,id列表: ${res.ids.join(',')}`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbUpdate() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.update({
num: 4
})
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `更新成功,更新了${res.updated}条数据`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbGet() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `获取成功,取到了${res.data.length}条数据`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbGetWithCommand() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where({
num: db.command.gt(2)
})
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `获取成功,取到了${res.data.length}条数据`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbRemove() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.remove()
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `删除成功,删掉了${res.deleted}条数据`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbLookupInit() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('local')
.where('tag == "default-tag"')
.remove()
.then(() : Promise<UniCloudDBRemoveResult> => {
return db.collection('foreign')
.where('tag == "default-tag"')
.remove()
})
.then(() : Promise<UniCloudDBBatchAddResult> => {
return db.collection('local')
.add([{
id: "local_1",
name: "local_1_name",
tag: "default-tag",
foreign_id: "foreign_1"
}, {
id: "local_2",
name: "local_2_name",
tag: "default-tag",
foreign_id: "foreign_2"
}])
})
.then(() : Promise<UniCloudDBBatchAddResult> => {
return db.collection('foreign')
.add([{
id: "foreign_1",
name: "foreign_1_name",
tag: "default-tag"
}, {
id: "foreign_2",
name: "foreign_2_name",
tag: "default-tag"
}])
})
.then<void>((_) : void => {
uni.hideLoading()
uni.showModal({
content: '数据初始化成功',
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
console.error(err)
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
},
dbLookup() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
const local = db.collection('local')
.where('tag == "default-tag"')
.getTemp()
const foreign = db.collection('foreign')
.where('tag == "default-tag"')
.getTemp()
db.collection(local, foreign)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
uni.showModal({
content: `联表查询成功,取到了${res.data.length}条数据`,
showCancel: false
})
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
pages/tabBar/API.uvue
浏览文件 @
8115ea78
...
...
@@ -390,6 +390,10 @@
name: '云存储',
url: 'unicloud-file-api',
},
{
name: 'clientDB',
url: 'unicloud-database',
},
] as Page[],
},
/* {
...
...
uniCloud-aliyun/database/foreign.schema.json
0 → 100644
浏览文件 @
8115ea78
//
文档教程:
https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType"
:
"object"
,
"required"
:
[],
"permission"
:
{
"read"
:
true
,
"create"
:
true
,
"update"
:
true
,
"delete"
:
true
},
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
},
"id"
:
{
"bsonType"
:
"string"
},
"name"
:
{
"bsonType"
:
"string"
},
"tag"
:
{
"bsonType"
:
"string"
}
}
}
\ No newline at end of file
uniCloud-aliyun/database/local.schema.json
0 → 100644
浏览文件 @
8115ea78
//
文档教程:
https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType"
:
"object"
,
"required"
:
[],
"permission"
:
{
"read"
:
true
,
"create"
:
true
,
"update"
:
true
,
"delete"
:
true
},
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
},
"id"
:
{
"bsonType"
:
"string"
},
"name"
:
{
"bsonType"
:
"string"
},
"tag"
:
{
"bsonType"
:
"string"
},
"foreign_id"
:
{
"foreignKey"
:
"foreign.id"
}
}
}
\ No newline at end of file
uniCloud-aliyun/database/type.schema.json
0 → 100644
浏览文件 @
8115ea78
//
文档教程:
https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType"
:
"object"
,
"required"
:
[],
"permission"
:
{
"read"
:
true
,
"create"
:
true
,
"update"
:
true
,
"delete"
:
true
},
"properties"
:
{
"_id"
:
{
"description"
:
"ID,系统自动生成"
},
"num"
:
{
"bsonType"
:
"int"
},
"tag"
:
{
"bsonType"
:
"string"
,
"maxLength"
:
50
,
"minLength"
:
0
},
"date"
:
{
"bsonType"
:
"date"
},
"point"
:
{
"bsonType"
:
"object"
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录