迁移 psycopg3 并修复 Postgres 18 兼容性问题

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
fish
2026-05-03 15:29:08 +08:00
parent 961ab8224e
commit d3ec1de275
5 changed files with 24 additions and 17 deletions

View File

@@ -55,23 +55,25 @@ func (s *FuturesStore) ListScores(f ScoreFilter) ([]Score, error) {
q := `SELECT id, ts_code, trade_date, close, oi, oi_chg, short_term, medium_term, long_term,
composite, signal, created_at FROM scores WHERE 1=1`
args := []any{}
n := 0
next := func() string { n++; return fmt.Sprintf("$%d", n) }
if f.TsCode != "" {
q += " AND ts_code = ?"
q += " AND ts_code = " + next()
args = append(args, f.TsCode)
}
if f.Start != "" {
q += " AND trade_date >= ?"
q += " AND trade_date >= " + next()
args = append(args, f.Start)
}
if f.End != "" {
q += " AND trade_date <= ?"
q += " AND trade_date <= " + next()
args = append(args, f.End)
}
q += " ORDER BY trade_date DESC, id DESC"
if f.Limit <= 0 || f.Limit > 500 {
f.Limit = 200
}
q += " LIMIT ?"
q += " LIMIT " + next()
args = append(args, f.Limit)
rows, err := s.db.Query(q, args...)
@@ -93,7 +95,7 @@ func (s *FuturesStore) ListScores(f ScoreFilter) ([]Score, error) {
func (s *FuturesStore) GetScore(id string) (*Score, error) {
row := s.db.QueryRow(`SELECT id, ts_code, trade_date, close, oi, oi_chg, short_term, medium_term,
long_term, composite, signal, detail_json, created_at FROM scores WHERE id = ?`, id)
long_term, composite, signal, detail_json, created_at FROM scores WHERE id = $1`, id)
var x Score
var detail sql.NullString
if err := row.Scan(&x.ID, &x.TsCode, &x.TradeDate, &x.Close, &x.OI, &x.OIChg,
@@ -145,14 +147,16 @@ func (s *FuturesStore) ListCandles(tsCode, start, end string) ([]Candle, error)
COALESCE(open, 0), COALESCE(high, 0), COALESCE(low, 0), COALESCE(close, 0),
COALESCE(vol, 0), COALESCE(amount, 0),
COALESCE(oi, 0), COALESCE(oi_chg, 0), COALESCE(pre_close, 0)
FROM candles WHERE ts_code = ?`
FROM candles WHERE ts_code = $1`
args := []any{tsCode}
n := 1
next := func() string { n++; return fmt.Sprintf("$%d", n) }
if start != "" {
q += " AND trade_date >= ?"
q += " AND trade_date >= " + next()
args = append(args, start)
}
if end != "" {
q += " AND trade_date <= ?"
q += " AND trade_date <= " + next()
args = append(args, end)
}
q += " ORDER BY trade_date ASC LIMIT 1000"