MCPcopy Create free account
hub / github.com/astercloud/aster / NewMySQLStore

Function NewMySQLStore

pkg/memory/logic/store_mysql.go:35–62  ·  view source on GitHub ↗

NewMySQLStore 创建 MySQL 存储

(config *MySQLStoreConfig)

Source from the content-addressed store, hash-verified

33
34// NewMySQLStore 创建 MySQL 存储
35func NewMySQLStore(config *MySQLStoreConfig) (*MySQLStore, error) {
36 if config == nil {
37 return nil, errors.New("config is required")
38 }
39
40 if config.DB == nil {
41 return nil, errors.New("database connection is required")
42 }
43
44 tableName := config.TableName
45 if tableName == "" {
46 tableName = "logic_memories"
47 }
48
49 store := &MySQLStore{
50 db: config.DB,
51 tableName: tableName,
52 }
53
54 // 自动创建表
55 if config.AutoMigrate {
56 if err := store.migrate(); err != nil {
57 return nil, fmt.Errorf("failed to migrate: %w", err)
58 }
59 }
60
61 return store, nil
62}
63
64// migrate 创建表结构
65func (s *MySQLStore) migrate() error {

Callers

nothing calls this directly

Calls 1

migrateMethod · 0.95

Tested by

no test coverage detected