迁移 PostgreSQL 并新增 Python API 服务
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -6,21 +6,22 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
var ErrMissingTsCode = errors.New("ts_code 必填")
|
||||
|
||||
type FuturesStore struct{ db *sql.DB }
|
||||
|
||||
func OpenFutures(path string) (*FuturesStore, error) {
|
||||
dsn := fmt.Sprintf("file:%s?mode=ro&_pragma=query_only(true)", path)
|
||||
db, err := sql.Open("sqlite", dsn)
|
||||
func OpenFutures(databaseURL string) (*FuturesStore, error) {
|
||||
db, err := sql.Open("postgres", databaseURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("open futures.db: %w", err)
|
||||
return nil, fmt.Errorf("open futures db: %w", err)
|
||||
}
|
||||
db.SetMaxOpenConns(4)
|
||||
db.SetMaxOpenConns(8)
|
||||
if err := db.Ping(); err != nil {
|
||||
return nil, fmt.Errorf("ping futures.db: %w", err)
|
||||
return nil, fmt.Errorf("ping futures db: %w", err)
|
||||
}
|
||||
return &FuturesStore{db: db}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user