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

Function NewPostgreSQLStore

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

NewPostgreSQLStore 创建 PostgreSQL 存储

(config *PostgreSQLStoreConfig)

Source from the content-addressed store, hash-verified

33
34// NewPostgreSQLStore 创建 PostgreSQL 存储
35func NewPostgreSQLStore(config *PostgreSQLStoreConfig) (*PostgreSQLStore, 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 := &PostgreSQLStore{
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 *PostgreSQLStore) migrate() error {

Callers

nothing calls this directly

Calls 1

migrateMethod · 0.95

Tested by

no test coverage detected