【发布时间】:2018-09-09 11:31:32
【问题描述】:
我正在尝试将使用 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() 但它进展缓慢。
【问题讨论】: