存储区:可以理解为数据库;
对象类型:可以理解为表结构;
数据:就是表中的记录;
完整的云数据库开发流程及初始化配置,请参见官方文档:
1.指定存储区NMSS
db-config.json文件如下:
{
"defaultCloudDBZoneName": "NMSS",
"defaultDataStorageLocation": "CN"
}
2.定义病虫害Pest对象类型
{
"objectTypeName": "Pest",
"fields": [
{
"fieldName": "AGID",
"fieldType": "Integer",
"notNull": true,
"belongPrimaryKey": true
},
{
"fieldName": "ID",
"fieldType": "String"
},
{
"fieldName": "Type",
"fieldType": "String"
},
{
"fieldName": "Img",
"fieldType": "String"
},
{
"fieldName": "PestName",
"fieldType": "String"
},
{
"fieldName": "PestDesc",
"fieldType": "String"
},
{
"fieldName": "PestCtrl",
"fieldType": "Text"
},
{
"fieldName": "UpdateDate",
"fieldType": "Date"
},
{
"fieldName": "UserId",
"fieldType": "String"
}
],
"indexes": [
{
"indexName": "UpdateDateIndex",
"indexList": [
{
"fieldName": "UpdateDate",
"sortType": "DESC"
}
]
},
{
"indexName": "AGIDIndex",
"indexList": [
{
"fieldName": "AGID",
"sortType": "ASC"
}
]
}
],
"permissions": [
{
"role": "World",
"rights": [
"Read"
]
},
{
"role": "Authenticated",
"rights": [
"Read",
"Upsert",
"Delete"
]
},
{
"role": "Creator",
"rights": [
"Read",
"Upsert",
"Delete"
]
},
{
"role": "Administrator",
"rights": [
"Read",
"Upsert",
"Delete"
]
}
]
}
3.自动生成客户端侧工程引用的Pest实体对象(生成的是ts文件)
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
* Generated by the CloudDB ObjectType compiler. DO NOT EDIT!
*/
import { cloudDatabase } from '@kit.CloudFoundationKit';
class Pest extends cloudDatabase.DatabaseObject {
AGID: number;
ID: string;
Type: string;
Img: string;
PestName: string;
PestDesc: string;
PestCtrl: string;
UpdateDate: Date;
UserId: string;
naturalbase_ClassName(): string {
return 'Pest';
}
}
export { Pest };
下一篇:使用cloudDatabase.DatabaseZone对象的upsert方法,保存数据到云数据库