Skip to content

Commit b2a6637

Browse files
authored
docs/session: fix mysql session docs (#702)
1 parent 01dcb43 commit b2a6637

File tree

2 files changed

+18
-40
lines changed

2 files changed

+18
-40
lines changed

docs/mkdocs/en/session.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,7 @@ Suitable for production environments and applications requiring complex queries,
740740

741741
**Connection Configuration:**
742742

743-
- **`WithHost(host string)`**: MySQL server address. Default is `localhost`.
744-
- **`WithPort(port int)`**: MySQL server port. Default is `3306`.
745-
- **`WithUser(user string)`**: Database username. Default is `root`.
746-
- **`WithPassword(password string)`**: Database password. Default is empty string.
747-
- **`WithDatabase(database string)`**: Database name. Default is `trpc_sessions`.
743+
- **`WithMySQLClientDSN(dsn string)`**:MySQL config
748744
- **`WithInstanceName(name string)`**: Use pre-configured MySQL instance.
749745

750746
**Session Configuration:**
@@ -779,8 +775,7 @@ import "trpc.group/trpc-go/trpc-agent-go/session/mysql"
779775

780776
// Default configuration (minimal)
781777
sessionService, err := mysql.NewService(
782-
mysql.WithHost("localhost"),
783-
mysql.WithPassword("your-password"),
778+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
784779
)
785780
// Effect:
786781
// - Connect to localhost:3306, database trpc_sessions
@@ -791,11 +786,7 @@ sessionService, err := mysql.NewService(
791786
// Complete production environment configuration
792787
sessionService, err := mysql.NewService(
793788
// Connection configuration
794-
mysql.WithHost("localhost"),
795-
mysql.WithPort(3306),
796-
mysql.WithUser("root"),
797-
mysql.WithPassword("your-password"),
798-
mysql.WithDatabase("trpc_sessions"),
789+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
799790

800791
// Session configuration
801792
mysql.WithSessionEventLimit(1000),
@@ -848,7 +839,7 @@ MySQL supports table prefix configuration for multi-application shared database
848839
```go
849840
// Use table prefix
850841
sessionService, err := mysql.NewService(
851-
mysql.WithHost("localhost"),
842+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
852843
mysql.WithTablePrefix("app1_"), // Table name: app1_session_states
853844
)
854845
```
@@ -860,13 +851,13 @@ sessionService, err := mysql.NewService(
860851
```go
861852
// Enable soft delete (default)
862853
sessionService, err := mysql.NewService(
863-
mysql.WithHost("localhost"),
854+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
864855
mysql.WithSoftDelete(true),
865856
)
866857

867858
// Disable soft delete (physical delete)
868859
sessionService, err := mysql.NewService(
869-
mysql.WithHost("localhost"),
860+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
870861
mysql.WithSoftDelete(false),
871862
)
872863
```
@@ -882,7 +873,7 @@ sessionService, err := mysql.NewService(
882873

883874
```go
884875
sessionService, err := mysql.NewService(
885-
mysql.WithHost("localhost"),
876+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
886877
mysql.WithSessionTTL(30*time.Minute), // Session expires after 30 minutes
887878
mysql.WithAppStateTTL(24*time.Hour), // App state expires after 24 hours
888879
mysql.WithUserStateTTL(7*24*time.Hour), // User state expires after 7 days
@@ -899,8 +890,7 @@ sessionService, err := mysql.NewService(
899890

900891
```go
901892
sessionService, err := mysql.NewService(
902-
mysql.WithHost("localhost"),
903-
mysql.WithPassword("your-password"),
893+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
904894
mysql.WithSessionEventLimit(1000),
905895
mysql.WithSessionTTL(30*time.Minute),
906896

@@ -1117,8 +1107,7 @@ sessionService, err := postgres.NewService(
11171107

11181108
// MySQL storage
11191109
sessionService, err := mysql.NewService(
1120-
mysql.WithHost("localhost"),
1121-
mysql.WithPassword("your-password"),
1110+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
11221111
mysql.WithSummarizer(summarizer),
11231112
mysql.WithAsyncSummaryNum(2),
11241113
mysql.WithSummaryQueueSize(100),

docs/mkdocs/zh/session.md

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,7 @@ CREATE TABLE user_states (
740740

741741
**连接配置:**
742742

743-
- **`WithHost(host string)`**:MySQL 服务器地址。默认值为 `localhost`
744-
- **`WithPort(port int)`**:MySQL 服务器端口。默认值为 `3306`
745-
- **`WithUser(user string)`**:数据库用户名。默认值为 `root`
746-
- **`WithPassword(password string)`**:数据库密码。默认值为空字符串。
747-
- **`WithDatabase(database string)`**:数据库名称。默认值为 `trpc_sessions`
743+
- **`WithMySQLClientDSN(dsn string)`**:MySQL 链接配置
748744
- **`WithInstanceName(name string)`**:使用预配置的 MySQL 实例。
749745

750746
**会话配置:**
@@ -779,8 +775,7 @@ import "trpc.group/trpc-go/trpc-agent-go/session/mysql"
779775

780776
// 默认配置(最简)
781777
sessionService, err := mysql.NewService(
782-
mysql.WithHost("localhost"),
783-
mysql.WithPassword("your-password"),
778+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
784779
)
785780
// 效果:
786781
// - 连接 localhost:3306,数据库 trpc_sessions
@@ -791,11 +786,7 @@ sessionService, err := mysql.NewService(
791786
// 生产环境完整配置
792787
sessionService, err := mysql.NewService(
793788
// 连接配置
794-
mysql.WithHost("localhost"),
795-
mysql.WithPort(3306),
796-
mysql.WithUser("root"),
797-
mysql.WithPassword("your-password"),
798-
mysql.WithDatabase("trpc_sessions"),
789+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
799790

800791
// 会话配置
801792
mysql.WithSessionEventLimit(1000),
@@ -848,7 +839,7 @@ MySQL 支持表前缀配置,适用于多应用共享数据库的场景:
848839
```go
849840
// 使用表前缀
850841
sessionService, err := mysql.NewService(
851-
mysql.WithHost("localhost"),
842+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
852843
mysql.WithTablePrefix("app1_"), // 表名:app1_session_states
853844
)
854845
```
@@ -860,13 +851,13 @@ sessionService, err := mysql.NewService(
860851
```go
861852
// 启用软删除(默认)
862853
sessionService, err := mysql.NewService(
863-
mysql.WithHost("localhost"),
854+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
864855
mysql.WithSoftDelete(true),
865856
)
866857

867858
// 禁用软删除(物理删除)
868859
sessionService, err := mysql.NewService(
869-
mysql.WithHost("localhost"),
860+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
870861
mysql.WithSoftDelete(false),
871862
)
872863
```
@@ -882,7 +873,7 @@ sessionService, err := mysql.NewService(
882873

883874
```go
884875
sessionService, err := mysql.NewService(
885-
mysql.WithHost("localhost"),
876+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
886877
mysql.WithSessionTTL(30*time.Minute), // 会话 30 分钟后过期
887878
mysql.WithAppStateTTL(24*time.Hour), // 应用状态 24 小时后过期
888879
mysql.WithUserStateTTL(7*24*time.Hour), // 用户状态 7 天后过期
@@ -899,8 +890,7 @@ sessionService, err := mysql.NewService(
899890

900891
```go
901892
sessionService, err := mysql.NewService(
902-
mysql.WithHost("localhost"),
903-
mysql.WithPassword("your-password"),
893+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
904894
mysql.WithSessionEventLimit(1000),
905895
mysql.WithSessionTTL(30*time.Minute),
906896

@@ -1117,8 +1107,7 @@ sessionService, err := postgres.NewService(
11171107

11181108
// MySQL 存储
11191109
sessionService, err := mysql.NewService(
1120-
mysql.WithHost("localhost"),
1121-
mysql.WithPassword("your-password"),
1110+
mysql.WithMySQLClientDSN("user:password@tcp(localhost:3306)/db?charset=utf8mb4&parseTime=True&loc=Local"),
11221111
mysql.WithSummarizer(summarizer),
11231112
mysql.WithAsyncSummaryNum(2),
11241113
mysql.WithSummaryQueueSize(100),

0 commit comments

Comments
 (0)