Created
August 21, 2020 21:36
-
-
Save jvanasco/1140ae275338fab5a32cd1c0e340d99b to your computer and use it in GitHub Desktop.
making sure we send the right timestamp...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlalchemy.types | |
from sqlalchemy.sql import expression | |
from sqlalchemy.ext.compiler import compiles | |
class utcnow(expression.FunctionElement): | |
type = sqlalchemy.types.DateTime() | |
@compiles(utcnow) | |
def utcnow__default(element, compiler, **kw): | |
# sqlite uses UTC by default | |
return "CURRENT_TIMESTAMP" | |
@compiles(utcnow, "postgresql") | |
def utcnow__postgresql(element, compiler, **kw): | |
return "TIMEZONE('utc', CURRENT_TIMESTAMP)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment