Skip to content

Commit 236e8c2

Browse files
AI Translate 00-drivers to Simplified-Chinese (#2523)
* [INIT] Start translation to Simplified-Chinese * 🌐 Translate 00-golang.md to Simplified-Chinese --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 109fc5a commit 236e8c2

File tree

2 files changed

+58
-62
lines changed

2 files changed

+58
-62
lines changed

.translation-init

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Translation initialization: 2025-07-19T00:49:39.498428
1+
Translation initialization: 2025-07-22T02:24:51.851102

docs/cn/developer/00-drivers/00-golang.md

Lines changed: 57 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,77 @@ title: Golang
55
import StepsWrap from '@site/src/components/StepsWrap';
66
import StepContent from '@site/src/components/Steps/step-content';
77

8-
Databend 提供了一个用 Golang 编写的驱动程序 (databend-go),它有助于使用 Golang 编程语言开发应用程序并建立与 Databend 的连接
8+
Databend 提供了一个用 Golang 编写的驱动程序databend-go),方便使用 Golang 编程语言开发应用程序并与 Databend 建立连接
99

1010
有关安装说明、示例和源代码,请参阅 GitHub [databend-go](https://github.com/databendlabs/databend-go) 仓库。
1111

1212
## 数据类型映射
1313

14-
下表说明了 Databend 数据类型与其对应的 Go 等效项之间的对应关系
14+
下表说明了 Databend 数据类型与其对应的 Go 等效类型之间的对应关系
1515

16-
| Databend | Go |
17-
| ------------------ | --------------- |
18-
| TINYINT | int8 |
19-
| SMALLINT | int16 |
20-
| INT | int32 |
21-
| BIGINT | int64 |
22-
| TINYINT UNSIGNED | uint8 |
23-
| SMALLINT UNSIGNED | uint16 |
24-
| INT UNSIGNED | uint32 |
25-
| BIGINT UNSIGNED | uint64 |
26-
| Float32 | float32 |
27-
| Float64 | float64 |
28-
| Bitmap | string |
29-
| Decimal | decimal.Decimal |
30-
| String | string |
31-
| Date | time.Time |
32-
| DateTime | time.Time |
33-
| Array(T) | string |
34-
| Tuple(T1, T2, ...) | string |
35-
| Variant | string |
16+
| Databend | Go |
17+
| --- | --- |
18+
| TINYINT | int8 |
19+
| SMALLINT | int16 |
20+
| INT | int32 |
21+
| BIGINT | int64 |
22+
| TINYINT UNSIGNED | uint8 |
23+
| SMALLINT UNSIGNED | uint16 |
24+
| INT UNSIGNED | uint32 |
25+
| BIGINT UNSIGNED | uint64 |
26+
| Float32 | float32 |
27+
| Float64 | float64 |
28+
| Bitmap | string |
29+
| Decimal | decimal.Decimal |
30+
| String | string |
31+
| Date | time.Time |
32+
| DateTime | time.Time |
33+
| Array(T) | string |
34+
| Tuple(T1, T2, ...) | string |
35+
| Variant | string |
3636

37-
## Databend Go 驱动程序行为摘要
37+
## Databend Go 驱动行为摘要
3838

39-
Databend Go 驱动程序与 ["database/sql"](https://pkg.go.dev/database/sql) 接口规范兼容。以下是一些常见的行为,以及涉及的关键函数及其背后的原理
39+
Databend Go 驱动与 ["database/sql"](https://pkg.go.dev/database/sql) 接口规范兼容。以下是一些常见的基本行为,以及涉及的关键函数和其背后的原理
4040

41-
| 基本行为 | 涉及的关键函数 | 原理 |
42-
| ---------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
43-
| 创建连接 | `DB.Open` | 使用 DSN 字符串和 `DB.Open` 方法建立与 Databend 的连接。<br /><br />DSN 字符串格式为 `https://user:password@host/database?<query_option>=<value>` |
44-
| 执行语句 | `DB.Exec` | `DB.Exec` 方法使用 `v1/query` 接口执行 SQL 语句,用于创建、删除表和插入数据。 |
45-
| 批量插入 | `DB.Begin`, `Tx.Prepare`, `Stmt.Exec`, `Tx.Commit` | 批量插入/替换数据(`INSERT INTO``REPLACE INTO`)通过事务处理。<br /><br />使用 `Stmt.Exec` 将尽可能多的数据添加到预处理语句对象;数据将附加到文件中。<br /><br />执行 `Tx.Commit()` 最终会将数据上传到内置的 Stage 并执行插入/替换操作,使用 [Stage Attachment](/developer/apis/http#stage-attachment)|
46-
| 查询单行 | `DB.QueryRow`, `Row.Scan` | 使用 `DB.QueryRow` 方法查询单行数据并返回 `*sql.Row`,然后调用 `Row.Scan` 将列数据映射到变量。 |
47-
| 迭代行 | `DB.Query`, `Rows.Next`, `Rows.Scan` | 使用 `DB.Query` 方法查询多行数据并返回 `*sql.Rows` 结构,使用 `Rows.Next` 方法迭代行,并使用 `Rows.Scan` 将数据映射到变量。 |
48-
| 上传到内部 Stage | `APIClient.UploadToStage` | 将数据上传到 Stage。默认情况下,使用 `PRESIGN UPLOAD` 获取 URL,如果禁用 PRESIGN,则使用 `v1/upload_to_stage` API。 |
41+
| 基本行为 | 涉及的关键函数 | 原理 |
42+
| --- | --- | --- |
43+
| 创建连接 | `DB.Open` | 使用 DSN 字符串和 `DB.Open` 方法建立与 Databend 的连接。<br /><br />DSN 字符串格式为 `https://user:password@host/database?<query_option>=<value>`|
44+
| 执行语句 | `DB.Exec` | `DB.Exec` 方法使用 `v1/query` 接口执行 SQL 语句,用于创建、删除表和插入数据。 |
45+
| 批量插入 | `DB.Begin`, `Tx.Prepare`, `Stmt.Exec`, `Tx.Commit` | 批量插入/替换数据(`INSERT INTO``REPLACE INTO`)通过事务处理。<br /><br />使用 `Stmt.Exec` 将尽可能多的数据添加到预处理语句对象中;数据将被附加到一个文件中。<br /><br />执行 `Tx.Commit()` 将最终把数据上传到内置的暂存区(Stage并执行插入/替换操作,使用[暂存区附件(Stage Attachment](/developer/apis/http#stage-attachment)|
46+
| 查询单行 | `DB.QueryRow`, `Row.Scan` | 使用 `DB.QueryRow` 方法查询单行数据并返回一个 `*sql.Row`,然后调用 `Row.Scan` 将列数据映射到变量。 |
47+
| 遍历多行 | `DB.Query`, `Rows.Next`, `Rows.Scan` | 使用 `DB.Query` 方法查询多行数据并返回一个 `*sql.Rows` 结构,使用 `Rows.Next` 方法遍历行,并使用 `Rows.Scan` 将数据映射到变量。 |
48+
| 上传到内部暂存区(Stage | `APIClient.UploadToStage` | 将数据上传到暂存区(Stage。默认情况下,使用 `PRESIGN UPLOAD` 获取 URL,如果 PRESIGN 被禁用,则使用 `v1/upload_to_stage` API。 |
4949

50-
## 教程 1:使用 Golang 与 Databend 集成
50+
## 教程一:使用 Golang 与 Databend 集成
5151

52-
在开始之前,请确保已成功安装本地 Databend。有关详细说明,请参阅 [本地和 Docker 部署](/guides/deploy/deploy/non-production/deploying-local)
52+
在开始之前,请确保您已成功在本地安装 Databend。有关详细说明,请参阅[本地和 Docker 部署](/guides/deploy/deploy/non-production/deploying-local)
5353

54-
### 步骤 1. 准备一个 SQL 用户帐户
54+
### 步骤一:准备一个 SQL 用户帐户
5555

56-
要将程序连接到 Databend 并执行 SQL 操作,必须在代码中提供具有适当权限的 SQL 用户帐户。如果需要, Databend 中创建一个,并确保 SQL 用户仅具有必要的权限以确保安全
56+
要将您的程序连接到 Databend 并执行 SQL 操作,您必须在代码中提供一个具有适当权限的 SQL 用户帐户。如果需要,请在 Databend 中创建一个,并确保该 SQL 用户仅拥有必要的权限以确保安全
5757

58-
本教程使用名为“user1”且密码为“abc123的 SQL 用户作为示例。由于程序会将数据写入 Databend,因此用户需要所有权限。有关如何管理 SQL 用户及其权限的信息,请参阅 [用户 & 角色](/sql/sql-commands/ddl/user/)
58+
本教程以一个名为 'user1'、密码为 'abc123' 的 SQL 用户为例。由于程序将向 Databend 写入数据,该用户需要 ALL 权限。有关如何管理 SQL 用户及其权限的信息,请参阅[用户和角色](/sql/sql-commands/ddl/user/)
5959

6060
```sql
6161
CREATE USER user1 IDENTIFIED BY 'abc123';
6262
GRANT ALL on *.* TO user1;
6363
```
6464

65-
### 步骤 2. 编写 Golang 程序
65+
### 步骤二:编写一个 Golang 程序
6666

67-
在此步骤中,你将创建一个简单的 Golang 程序,该程序与 Databend 通信。该程序将涉及创建表、插入数据和执行数据查询等任务。
67+
在此步骤中,您将创建一个与 Databend 通信的简单 Golang 程序。该程序将涉及创建表、插入数据和执行数据查询等任务。
6868

6969
<StepsWrap>
7070

7171
<StepContent number="1">
7272

73-
### 将以下代码复制并粘贴到文件 main.go
73+
### 将以下代码复制并粘贴到 main.go 文件中
7474

7575
:::note
7676

77-
- 以下代码连接到本地 Databend,其中 SQL 用户名为“user1”,密码为abc123”作为示例。你可以随意使用自己的值,同时保持相同的格式
78-
- 以下代码中 `hostname` 的值必须与 Databend 查询服务的 HTTP 处理程序设置一致
77+
- 下面的代码以一个名为 'user1'、密码为 'abc123' 的 SQL 用户连接到本地 Databend 为例。您可以随意使用自己的值,但请保持格式相同
78+
- 下面代码中 `hostname` 的值必须与您的 Databend 查询服务的 HTTP 处理器设置保持一致
7979
:::
8080

8181
```go title='main.go'
@@ -102,7 +102,7 @@ type Book struct {
102102
}
103103

104104
func dsn() string {
105-
return fmt.Sprintf("http://%s:%s@%s", username, password, hostname)
105+
return fmt.Sprintf("databend://%s:%s@%s?sslmode=disable", username, password, hostname)
106106
}
107107

108108
func main() {
@@ -119,38 +119,36 @@ func main() {
119119
}
120120
log.Println("Connected")
121121

122-
// Create db if do not exist
122+
// 如果数据库不存在,则创建
123123
dbSql := "CREATE DATABASE IF NOT EXISTS book_db"
124124
_, err = db.Exec(dbSql)
125125
if err != nil {
126126
log.Fatal(err)
127127
}
128128
log.Println("Create database book_db success")
129129

130-
// Use book_db database
130+
// 使用 book_db 数据库
131131
_, err = db.Exec("USE book_db")
132132
if err != nil {
133133
log.Fatal(err)
134134
}
135135

136-
// Create table.
136+
// 创建表。
137137
sql := "create table if not exists books(title VARCHAR, author VARCHAR, date VARCHAR)"
138138
_, err = db.Exec(sql)
139139
if err != nil {
140140
log.Fatal(err)
141141
}
142142
log.Println("Create table: books")
143143

144-
// Insert 1 row.
144+
// 插入 1 行。
145145
_, err = db.Exec("INSERT INTO books VALUES(?, ?, ?)", "mybook", "author", "2022")
146146
if err != nil {
147147
log.Fatal(err)
148148
}
149149
log.Println("Insert 1 row")
150-
```
151150

152-
```go
153-
// Select.
151+
// 查询。
154152
res, err := db.Query("SELECT * FROM books")
155153
if err != nil {
156154
log.Fatal(err)
@@ -219,27 +217,27 @@ go run main.go
219217

220218
</StepsWrap>
221219

222-
## Tutorial-2: 使用 Golang 与 Databend Cloud 集成
220+
## 教程二:使用 Golang 与 Databend Cloud 集成
223221

224-
在开始之前,请确保您已成功创建计算集群并获得连接信息。有关如何执行此操作,请参见 [连接到计算集群](/guides/cloud/using-databend-cloud/warehouses#connecting)
222+
在开始之前,请确保您已成功创建了一个计算集群(Warehouse)并获取了连接信息。有关如何操作,请参阅[连接到计算集群(Warehouse)](/guides/cloud/using-databend-cloud/warehouses#connecting)
225223

226-
### Step 1. 创建一个 Go Module
224+
### 步骤一:创建一个 Go 模块
227225

228226
```shell
229227
$ mkdir sample
230228
$ cd sample
231229
$ go mod init cloud.databend.com/sample
232230
```
233231

234-
### Step 2. 安装依赖
232+
### 步骤二:安装依赖
235233

236234
```go
237235
$ go get github.com/databendcloud/databend-go
238236
```
239237

240-
### Step 3. 使用 databend-go 连接
238+
### 步骤三:使用 databend-go 连接
241239

242-
创建一个名为 `main.go` 的文件,其中包含以下代码
240+
创建一个名为 `main.go` 的文件,内容如下
243241

244242
```go
245243
package main
@@ -298,13 +296,11 @@ func main() {
298296
```
299297

300298
:::tip
301-
将代码中的 `{USER}, {PASSWORD}, {HOST}, {WAREHOUSE_NAME} and {DATABASE}` 替换为您的连接信息。有关如何
302-
获取连接信息,
303-
请参见 [连接到计算集群](/guides/cloud/using-databend-cloud/warehouses#connecting)
299+
将代码中的 `{USER}, {PASSWORD}, {HOST}, {WAREHOUSE_NAME} 和 {DATABASE}` 替换为您的连接信息。有关如何获取连接信息,请参阅[连接到计算集群(Warehouse)](/guides/cloud/using-databend-cloud/warehouses#connecting)
304300
:::
305301

306-
### Step 4. 运行 main.go
302+
### 步骤四:运行 main.go
307303

308304
```shell
309305
$ go run main.go
310-
```
306+
```

0 commit comments

Comments
 (0)