Skip to content

Commit 8b3ffe5

Browse files
committed
chore: 更新 pardnchiu/go-logger 版本
1 parent 1d2781a commit 8b3ffe5

File tree

14 files changed

+116
-419
lines changed

14 files changed

+116
-419
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 指定文件的語言
2+
*.go linguist-language=Go
3+
4+
# 將以下的所有文件與檔案視為第三方代碼,不計入語言統計
5+
test/** linguist-vendored
6+
*.html linguist-vendored
7+
*.js linguist-vendored
8+
*.mod linguist-vendored
9+
*.sum linguist-vendored
10+
11+
# 視文件為文檔類型,忽略語言統計
12+
*.md linguist-documentation
13+
*.txt linguist-documentation
14+
LICENSE linguist-documentation

README.md

Lines changed: 76 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,63 @@
1-
# MySQL Connection Pool (Golang)
2-
> A Chainable MySQL connection wrapper for Golang with read-write separation, query builder, and automatic logging, featuring comprehensive connection management.<br>
3-
>> version Node.js can get [here](https://github.com/pardnchiu/node-mysql-pool)<br>
4-
>> version PHP can get [here](https://github.com/pardnchiu/php-mysql-pool)
1+
# MySQL Pool
2+
> 一個支持鏈式呼叫的 Golang MySQL 包裝器,具備讀寫分離設置、查詢建構器等功能,提供完整的連線管理。<br>
3+
> A Golang MySQL wrapper with chainable calls, featuring read-write separation, query builder, and complete connection management.<br>
4+
>
5+
> Node.js version [here](https://github.com/pardnchiu/node-mysql-pool) | PHP version [here](https://github.com/pardnchiu/php-mysql-pool)
56
6-
[![license](https://img.shields.io/github/license/pardnchiu/go-mysql-pool)](https://github.com/pardnchiu/go-mysql-pool/blob/main/LICENSE)
7-
[![version](https://img.shields.io/github/v/tag/pardnchiu/go-mysql-pool)](https://github.com/pardnchiu/go-mysql-pool/releases)
8-
[![readme](https://img.shields.io/badge/readme-中文-blue)](https://github.com/pardnchiu/go-mysql-pool/blob/main/README.zh.md)
7+
![lang](https://img.shields.io/github/languages/top/pardnchiu/go-mysql)
8+
[![license](https://img.shields.io/github/license/pardnchiu/go-mysql)](LICENSE)
9+
[![version](https://img.shields.io/github/v/tag/pardnchiu/go-mysql)](https://github.com/pardnchiu/go-mysql/releases)
910

10-
## Three key features
11+
## 三大主軸 / Three Core Features
1112

12-
- **Read-Write Separation**: Support for independent read and write connection pool configurations to enhance database performance
13-
- **Query Builder**: Fluent SQL query building interface to prevent SQL injection
14-
- **CRUD Operations**: Complete Create, Read, Update, Delete operation support
13+
### 讀寫分離配置 / Read-Write Separation
14+
支援讀寫連線池配置,增加資料庫預連接,提高連接效率<br>
15+
Supports read-write connection pool configuration with database pre-connections to improve connection efficiency
1516

16-
## Dependencies
17+
### 查詢建構器 / Query Builder
18+
支持鏈式語法的 SQL 查詢建構介面,防止 SQL 注入攻擊<br>
19+
Chainable SQL query interface that prevents SQL injection attacks
1720

18-
- [`github.com/go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql)
19-
- [`github.com/pardnchiu/go-logger`](https://github.com/pardnchiu/go-logger)
21+
### CRUD 操作 / CRUD Operation
22+
完整的新增、查詢、更新、刪除操作支援<br>
23+
Complete support for Create, Read, Update, and Delete operations
24+
25+
## 依賴套件 / Dependencies
2026

27+
- [`github.com/go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql)
28+
- [`github.com/pardnchiu/go-logger`](https://github.com/pardnchiu/go-logger)<br>
29+
如果你不需要,你可以 fork 然後使用你熟悉的取代。更可以到[這裡](https://forms.gle/EvNLwzpHfxWR2gmP6)進行投票讓我知道。<br>
30+
If you don't need this, you can fork the project and replace it. You can also vote [here](https://forms.gle/EvNLwzpHfxWR2gmP6) to let me know your thought.
2131

22-
## How to use
32+
## 使用方法 / How to use
2333

24-
### Installation
34+
### 安裝 / Installation
2535
```bash
26-
go get github.com/pardnchiu/go-mysql-pool
36+
go get github.com/pardnchiu/go-mysql
2737
```
2838

29-
### Initialization
39+
### 初始化 / Initialization
3040
```go
3141
package main
3242

3343
import (
3444
"fmt"
3545
"log"
3646

37-
mysqlPool "github.com/pardnchiu/go-mysql-pool"
47+
mp "github.com/pardnchiu/go-mysql"
3848
)
3949

4050
func main() {
41-
// Create configuration
42-
config := mysqlPool.Config{
43-
Read: &mysqlPool.DBConfig{
51+
config := mp.Config{
52+
Read: &mp.DBConfig{
4453
Host: "localhost",
4554
Port: 3306,
4655
User: "root",
4756
Password: "password",
4857
Charset: "utf8mb4",
4958
Connection: 10,
5059
},
51-
Write: &mysqlPool.DBConfig{
60+
Write: &mp.DBConfig{
5261
Host: "localhost",
5362
Port: 3306,
5463
User: "root",
@@ -58,8 +67,8 @@ func main() {
5867
},
5968
}
6069

61-
// Initialize connection pool
62-
pool, err := mysqlPool.New(config)
70+
// Initialize
71+
pool, err := mp.New(config)
6372
if err != nil {
6473
log.Fatal(err)
6574
}
@@ -80,7 +89,7 @@ func main() {
8089
log.Fatal(err)
8190
}
8291

83-
fmt.Printf("Inserted user with ID: %d\n", lastID)
92+
fmt.Printf("插入使用者 ID: %d\n", lastID)
8493

8594
// Query data
8695
rows, err := pool.Read.
@@ -108,7 +117,7 @@ func main() {
108117
}
109118
```
110119

111-
### Configuration Details
120+
## 配置介紹 / Configuration
112121

113122
```go
114123
type Config struct {
@@ -123,21 +132,21 @@ type DBConfig struct {
123132
User string // Database username
124133
Password string // Database password
125134
Charset string // Character set (default: utf8mb4)
126-
Connection int // Maximum number of connections
135+
Connection int // Maximum connections
127136
}
128137

129138
type Log struct {
130-
Path string // Log directory path (default: ./logs/mysqlPool)
139+
Path string // Log directory path (default: ./logs/goMysql)
131140
Stdout bool // Enable console output (default: false)
132-
MaxSize int64 // Maximum file size before rotation (default: 16*1024*1024)
141+
MaxSize int64 // Maximum size before file rotation (default: 16*1024*1024)
133142
MaxBackup int // Number of log files to retain (default: 5)
143+
Type string // Output format: "json" for slog standard, "text" for tree format (default: "text")
134144
}
135145
```
136146

137-
## Supported Operations
138-
139-
### Query Builder
147+
## 支持操作 / Operations
140148

149+
### 查詢 / Queries
141150
```go
142151
// Basic query
143152
rows, err := pool.Read.
@@ -180,8 +189,7 @@ rows, err := pool.Read.
180189
Get()
181190
```
182191

183-
### CRUD Operations
184-
192+
### CRUD
185193
```go
186194
// Insert data
187195
data := map[string]interface{}{
@@ -223,7 +231,7 @@ lastID, err := pool.Write.
223231
Table("users").
224232
Upsert(data, updateData)
225233

226-
// Increment value
234+
// Increment values
227235
result, err := pool.Write.
228236
DB("database_name").
229237
Table("users").
@@ -232,8 +240,7 @@ result, err := pool.Write.
232240
Update()
233241
```
234242

235-
### SQL Operations
236-
243+
### SQL
237244
```go
238245
// Direct query
239246
rows, err := pool.Read.Query("SELECT * FROM users WHERE age > ?", 18)
@@ -242,79 +249,81 @@ rows, err := pool.Read.Query("SELECT * FROM users WHERE age > ?", 18)
242249
result, err := pool.Write.Exec("UPDATE users SET last_login = NOW() WHERE id = ?", userID)
243250
```
244251

245-
## Core Features
246-
247-
### Connection Pool Management
252+
## 可用函式 / Functions
248253

249-
- **New** - Create new connection pool instance
254+
### 連線池管理 / Pool Management
255+
- **New** - 建立新的連線池 / Create new connection
250256
```go
251-
pool, err := mysqlPool.New(config)
257+
pool, err := mp.New(config)
252258
```
253-
- Initialize read-write separated connection pools
254-
- Setup logging system and slow query recording
255-
- Validate database connection availability
259+
- 初始化讀寫分離的連線池<br>
260+
Initialize read-write separated connection pool
261+
- 驗證資料庫連線可用性<br>
262+
Validate database connection availability
256263

257-
- **Close** - Close connection pool
264+
- **Close** - 關閉連線池 / Close connection
258265
```go
259266
err := pool.Close()
260267
```
261-
- Gracefully close all connections
262-
- Wait for ongoing queries to complete
263-
- Release system resources
264-
265-
### Query Building
266-
267-
- **DB** - Specify database
268+
- 關閉所有連線<br>
269+
Close all connections
270+
- 等待進行中的查詢完成<br>
271+
Wait for ongoing queries to complete
272+
- 釋放系統資源<br>
273+
Release system resources
274+
275+
### 查詢建構 / Query Building
276+
- **DB** - 指定資料庫 / Select database
268277
```go
269278
builder := pool.Read.DB("database_name")
270279
```
271280

272-
- **Table** - Specify table
281+
- **Table** - 指定資料表 / Select table
273282
```go
274283
builder := builder.Table("table_name")
275284
```
276285

277-
- **Select** - Select columns
286+
- **Select** - 選擇欄位 / Select columns
278287
```go
279288
builder := builder.Select("col1", "col2", "col3")
280289
```
281290

282-
- **Where** - Filter conditions
291+
- **Where** - 篩選條件 / Filter data
283292
```go
284293
builder := builder.Where("column", "value")
285294
builder := builder.Where("column", ">", "value")
286295
builder := builder.Where("column", "LIKE", "pattern")
287296
```
288297

289-
- **Join** - Table joins
298+
- **Join** - 資料表聯結 / Table joins
290299
```go
291300
builder := builder.LeftJoin("table2", "table1.id", "table2.foreign_id")
292301
builder := builder.RightJoin("table2", "table1.id", "table2.foreign_id")
293302
builder := builder.InnerJoin("table2", "table1.id", "table2.foreign_id")
294303
```
295304

296-
### Data Operations
297-
298-
- **Insert** - Insert data
305+
### 資料操作 / Data
306+
- **Insert** - 插入資料 / Insert data
299307
```go
300308
lastID, err := builder.Insert(data)
301309
```
302310

303-
- **Update** - Update data
311+
- **Update** - 更新資料 / Update data
304312
```go
305313
result, err := builder.Update(data)
306314
```
307315

308-
- **Upsert** - Insert or update
316+
- **Upsert** - 插入或更新 / Insert or update
309317
```go
310318
lastID, err := builder.Upsert(insertData, updateData)
311319
```
312320

313-
## License
321+
## 授權條款 / License
314322

315-
This source code project is licensed under the [MIT](https://github.com/pardnchiu/go-mysql-pool/blob/main/LICENSE) License.
323+
此原始碼專案採用 [MIT](LICENSE) 授權條款。<br>
324+
This source code project is licensed under the [MIT](LICENSE) license.
316325

317-
## Author
326+
## 作者 / Author
318327

319328
<img src="https://avatars.githubusercontent.com/u/25631760" align="left" width="96" height="96" style="margin-right: 0.5rem;">
320329

@@ -328,4 +337,4 @@ This source code project is licensed under the [MIT](https://github.com/pardnchi
328337

329338
***
330339

331-
©️ 2025 [邱敬幃 Pardn Chiu](https://pardn.io)
340+
©️ 2025 [邱敬幃 Pardn Chiu](https://pardn.io)

0 commit comments

Comments
 (0)