@@ -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)
781777sessionService , 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
792787sessionService , 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
850841sessionService , 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)
862853sessionService , 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)
868859sessionService , 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
884875sessionService , 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
901892sessionService , 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
11191109sessionService , 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