2
我有這個column_property
,檢查用戶多少學分允許:的SQLAlchemy和方法
select(
[func.ifnull(func.sum(orders_table.c.quantity), 0)],
orders_table.c.user_id == users_table.c.id
).where(and_(
orders_table.c.date_added < now_unix(),
orders_table.c.date_expires > now_unix(),
orders_table.c.status == STATUS_COMPLETED
)).label('userAllowedCredits'),
deferred = True
的now_unix()
方法返回當前Unix時間戳,但問題是,這種方法只加載一次,每次我調用這個userAllowedCredits
屬性時,查詢都會根據我的應用程序啓動時保存的相同初始值進行搜索。我需要這個now_unix()
方法來在每次調用時返回實際的當前時間戳。
我有什麼意義嗎?
使用'func.CURRENT_TIMESTAMP()'因爲*任何名字都可以給func。如果函數名稱對SQLAlchemy是未知的,它將完全按照原樣呈現。對於SQLAlchemy意識到的常見SQL函數,名稱可能被解釋爲通用函數,該函數將被適當編譯到目標數據庫* –