Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: transform db sdk from database-ql to mongo by AI #1758

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/en/guide/db/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,20 @@ export async function main(ctx: FunctionContext) {

### Null Type

Null is equivalent to a placeholder that indicates a field exists but has no value.
Null is equivalent to a placeholder that indicates a field exists but has no value.

## Intelligent Migration of `cloud.database()` to Native Queries

We can intelligently rewrite cloud functions using `cloud.database()` to utilize native `MongoDB` queries through the following method:

The prompt is as follows: paste the Laf cloud function at the end and send it together to an AI (such as Laf Pilot).

```text
You are a senior programmer, especially skilled in using the official MongoDB SDK under the TypeScript language. Below, I will provide you with a segment of code where the 'db' was originally initialized using cloud.database(). Now, please initialize all instances of 'db' using cloud.mongo.db (this is a variable, not a function), and transform all database operations to conform to the official MongoDB SDK format.

Note:
1. db=cloud.mongo.db; this statement retrieves an already initialized data connection.
2. Regarding the 'id': previously, the 'db' used a string type for 'id', while MongoDB's official 'id' is of the ObjectId type. If necessary, you will need to add parsing/encapsulation conversion logic.
3. Do not modify other parts of the program's code.
Below is the code:
```
17 changes: 17 additions & 0 deletions docs/guide/db/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,20 @@ export async function main(ctx: FunctionContext) {
### Null 类型

Null 相当于一个占位符,表示一个字段存在但是值为空。

## 智能迁移 `cloud.database()` 至原生查询

我们可以使用如下的方法通过 AI 将 `cloud.database()` 写法的云函数智能改写为 `MongoDB` 原生查询:

Prompt 如下,将 Laf 云函数粘贴到末尾,一同发送给 AI(如 Laf Pilot)即可:

```text
你是一个资深程序员,尤其擅长使用TypeScript语言下的官方mongodb sdk。下面我将给你一段代码,代码中的db原来是用cloud.database()初始化的。
现在,请你将所有的db全部使用cloud.mongo.db初始化(这是一个变量,不是一个函数),并且将所有的数据库操作改成符合官方mongodb sdk的形式。
注意:

1. db=cloud.mongo.db,这条语句获取的已经是一个初始化好的数据连接
2. 关于id。之前的db使用的id的类型是string,而mongodb官方的id是ObjectId类型,如有必要,你需要增加解析/封装的转换逻辑
3. 不要改动程序的其他代码部分
下面是代码:
```
Loading