is it possible to override the default type.DateTime behaviour when using sqlalchemy with raw sql expressions?
for example when using
myconnection.execute(text("select * from mytable where mydate > :mydate), {'mydate': mypythondatetimeobject)}
, i would like to have type.DateTime to automatically strip the TimeZone from the DateTime object.
UPDATE: i found out, that it works by using bindparam and a Typedecorator on the query like this:
class MyType(types.TypeDecorator):
impl = types.DateTime
def process_bind_param(self, value, dialect):
if value is not None:
return value.replace(tzinfo=None)
session.execute(
text(myquery, bindparams=[bindparam('mydateparam',
type_=MyType())]),
{'mydateparam':mydate}
)
but i really dont want to use "bindparams" on every query. isnt it possible to simply replace or override the default types.DateTime behaviour somehow?