Skip to content

Instantly share code, notes, and snippets.

@jvanasco
Created August 21, 2020 21:36
Show Gist options
  • Save jvanasco/1140ae275338fab5a32cd1c0e340d99b to your computer and use it in GitHub Desktop.
Save jvanasco/1140ae275338fab5a32cd1c0e340d99b to your computer and use it in GitHub Desktop.
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