Skip to content

Instantly share code, notes, and snippets.

@jvanasco

jvanasco/utcnow.py

Created Aug 21, 2020
Embed
What would you like to do?
making sure we send the right timestamp...
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
You can’t perform that action at this time.