fix(db): 修复快照查询引擎的 ReferenceError,重构为标准 Drizzle ORM 查询语法
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { db } from '@/db';
|
||||
import { portfolioSnapshots } from '@/db/schema';
|
||||
import { getPortfolioPositions } from './portfolio';
|
||||
import { eq, sql } from 'drizzle-orm';
|
||||
import { desc, eq, gte, sql } from 'drizzle-orm';
|
||||
import Big from 'big.js';
|
||||
|
||||
function getTodayInShanghai(): string {
|
||||
@@ -89,13 +89,16 @@ export async function getSnapshots(params?: {
|
||||
let query = db
|
||||
.select()
|
||||
.from(portfolioSnapshots)
|
||||
.orderBy(sql`"${date}" DESC`);
|
||||
.orderBy(desc(portfolioSnapshots.date))
|
||||
.$dynamic();
|
||||
|
||||
if (startDate) {
|
||||
query = query.where(sql`"${date}" >= ${startDate}`);
|
||||
query = query.where(gte(portfolioSnapshots.date, startDate));
|
||||
}
|
||||
if (endDate) {
|
||||
query = query.where(sql`"${date}" <= ${endDate}`);
|
||||
query = query.where(
|
||||
portfolioSnapshots.date.lte(endDate)
|
||||
);
|
||||
}
|
||||
|
||||
const snapshots = await query.limit(limit);
|
||||
|
||||
Reference in New Issue
Block a user