Skip to content

Commit

Permalink
数据库导出
Browse files Browse the repository at this point in the history
  • Loading branch information
niudai committed Mar 6, 2024
1 parent b104392 commit 8756c3c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/en/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const sidebar: DefaultTheme.Sidebar = {
{ text: 'Find Data', link: '/guide/database/find' },
{ text: 'Update Data', link: '/guide/database/update' },
{ text: 'Delete Data', link: '/guide/database/delete' },
{ text: 'Export Data', link: '/guide/database/export' },
{ text: 'Database API', link: '/reference/server/database-api' },
{
text: 'Advanced',
Expand Down
41 changes: 41 additions & 0 deletions docs/en/src/guide/database/export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Data Export | AirCode Documentation
description: Export data by creating and running a cloud function.
---

# Data Export {#intro}

This document illustrates how to export data by creating a cloud function.
[[toc]]

For demonstration purposes, let's assume there is a table named `inventory` containing the following data:

```js
[
{ item: 'MacBook Air', qty: 15, info: { location: 'Beijing', color: 'Black' } },
{ item: 'MacBook Pro', qty: 35, info: { location: 'Tokyo', color: 'Silver' } },
{ item: 'iPhone 14', qty: 80, info: { location: 'New York', color: 'Blue' } },
{ item: 'iPhone SE', qty: 120, info: { location: 'London', color: 'Red' } },
{ item: 'iPad mini', qty: 95, info: { location: 'Beijing', color: 'Pink' } }
]
```

Data export can be achieved with the following code:

```js
const aircode = require('aircode');

module.exports = async function(params, context) {
// Use `aircode.db.table` to get a table
const InventoryTable = aircode.db.table('inventory');
// Find all records in the table
const allRecords = await InventoryTable
.where()
.find();

return allRecords;
}
```

You can deploy this cloud function and access the online link to achieve data export.

1 change: 1 addition & 0 deletions docs/zh-cn/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const sidebar: DefaultTheme.Sidebar = {
{ text: '查询数据', link: '/guide/database/find' },
{ text: '更新数据', link: '/guide/database/update' },
{ text: '删除数据', link: '/guide/database/delete' },
{ text: '数据导出', link: '/guide/database/export' },
// { text: '在网页中管理数据', link: '/guide/database/web-management' },
{ text: '数据库 API', link: '/reference/server/database-api' },
{
Expand Down
40 changes: 40 additions & 0 deletions docs/zh-cn/src/guide/database/export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: 数据导出 | AirCode 文档
description: 通过创建并运行一个云函数实现数据库数据导出。
---

# 数据导出 {#intro}

本文档将通过示例说明如何通过创建一个云函数的方式来进行数据库数据的导出。
[[toc]]

为了便于演示,我们假定有一张名为 `inventory` 的数据表,包含以下数据:

```js
[
{ item: 'MacBook Air', qty: 15, info: { location: 'Beijing', color: 'Black' } },
{ item: 'MacBook Pro', qty: 35, info: { location: 'Tokyo', color: 'Silver' } },
{ item: 'iPhone 14', qty: 80, info: { location: 'New York', color: 'Blue' } },
{ item: 'iPhone SE', qty: 120, info: { location: 'London', color: 'Red' } },
{ item: 'iPad mini', qty: 95, info: { location: 'Beijing', color: 'Pink' } }
]
```

我们可以通过如下代码实现数据导出:

```js
const aircode = require('aircode');

module.exports = async function(params, context) {
// Use `aircode.db.table` to get a table
const InventoryTable = aircode.db.table('inventory');
// Find all records in the table
const allRecords = await InventoryTable
.where()
.find();

return allRecords;
}
```

可以通过部署该云函数,访问线上链接实现数据导出。

0 comments on commit 8756c3c

Please sign in to comment.