sqlalchemy utcnow实施

时间:2017-11-29 14:04:45

标签: python mysql sqlalchemy

我遇到过这样的实现,取自here

from sqlalchemy.sql import expression
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.types import DateTime

class utcnow(expression.FunctionElement):
    type = DateTime()

@compiles(utcnow, 'mssql')
def ms_utcnow(element, compiler, **kw):
    return "GETUTCDATE()"

我对utcnow()的使用不在文档中提到的orm声明,但是像这样,似乎是合法的:
session.query(TableA).filter(TableA.created_at >= utcnow()).all()

但添加.all().first()会产生错误,如:

{AttributeError}Neither 'utcnow' object nor 'Comparator' object has an attribute 'name'  

知道为什么吗?

0 个答案:

没有答案