迁移 PostgreSQL 并新增 Python API 服务

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
fish
2026-05-03 14:58:01 +08:00
parent 750584e619
commit 220f4acc45
10 changed files with 333 additions and 123 deletions

View File

@@ -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
}