Tablestore数据库
1. Serverless Dves 工具安装#
2. 初始化一个模版项目#
s init dk-tablestore
下载完成后请输入 tablestore 的实例名称和公网地址,可前往 tablestore 控制台创建实例, 在实例详情页面可以看到 实例名称
和 公网地址
3. 部署#
s deploy
部署完成之后会返回可访问的域名
访问域名会看到如下界面
4. 本地调试#
cd functions && npm run serve
访问 http://localhost:7002/api
可以看到如下界面
5. curl 测试#
- 创建数据表
curl --location --request POST 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/list/list/' \
--header 'Content-Type: application/json' \
--data-raw '{
"tableName": "dk_user"
}'
返回数据
{
"success": true,
"message": "dk_user表已创建成功"
}
- 获取所有表
curl --location --request GET 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/list/list/'
返回数据
{
"tableNames": ["dk_user"]
}
- 删除数据表
curl --location --request DELETE 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/list/list/?tableName=dk_user'
数据返回
{
"success": true,
"message": "dk_user表已删除成功"
}
以 dk_user 表为例进行增删改查#
- 创建
curl --location --request POST 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/info/info/' \
--header 'Content-Type: application/json' \
--data-raw '{
"tableName": "dk_user",
"name": "shl",
"age": 20
}'
数据返回
{
"data": {
"name": "shl",
"age": 20
},
"message": "数据创建成功"
}
- 更新
curl --location --request PUT 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/info/info/' \
--header 'Content-Type: application/json' \
--data-raw '{
"tableName": "dk_user",
"id": 1622604175120,
"age": 21,
"name": "dk"
}'
数据返回
{
"data": {
"id": 1622604175120,
"name": "dk",
"age": 21
},
"message": "数据更成功"
}
- 查寻
curl --location --request GET 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/info/info/?tableName=dk_user'
数据返回
[
{
primaryKey: [
{
name: 'id',
value: 1622604175120,
},
],
attributes: [
{
columnName: 'age',
columnValue: 21,
timestamp: 1622604557591,
},
{
columnName: 'name',
columnValue: 'dk',
timestamp: 1622604557591,
},
],
},
];
- 删除
curl --location --request DELETE 'https://1694024725952210.cn-hangzhou.fc.aliyuncs.com/2016-08-15/proxy/dk-tablestore-demo/info/info/?id=1622604175120&tableName=dk_user'
数据返回
{
"id": "1622604175120",
"message": "数据删除成功"
}