使用Peewee ORM和MySQL日期数学

问题描述 投票:0回答:1

我正在尝试将使用MySQLdb的应用程序转换为使用Peewee。大多数SELECT和INSERT没有问题,但是一类查询让我感到困惑。

原始代码包含:

sql = "SELECT * FROM {tbl} WHERE tail='{tail}' AND flight="+\
    "'{flight}' AND dest='{dest}' AND orig='{orig}' AND "+\
    "oooi='{oooi}' AND report_time > ('{time}' - INTERVAL 2 HOUR) "+\
    "AND report_time < ('{time}' + INTERVAL 2 HOUR)"
cmd = sql.format(tbl = self.table, tail=tail, flight=flight, dest=dest,
     orig=orig, time = report_time, oooi=oooi)

c.execute(cmd)
return c.fetchone()

试图重写使用Peewee,我想出了:

oooi_rec = Oooi_rec.select().where(Oooi_rec.tail == self.tail, 
    Oooi_rec.flight == self.flight, 
    Oooi_rec.dest == self.dest, Oooi_rec.orig == self.orig, 
    Oooi_rec.oooi=self.oooi,
    Oooi_rec.report_time.between(low, high))

取代“低”和“高”的位是我现在困惑的东西。我正在试图弄清楚如何使用Peewee的fn(),但它进展缓慢。

mysql time peewee
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.