table:
id(integer primary key)
data(blob)
I use mysql and sqlalchemy.
To insert data I use:
o = Demo()
o.data = mydata
session.add(o)
session.commit()
I would like to insert to table like that:
INSERT INTO table(data) VALUES(COMPRESS(mydata))
How can I do this using sqlalchemy?
you can assign a SQL function to the attribute:
Here’s an example using a more DB-agnostic lower() function:
you can make it automatic with @validates:
if you want it readable in python before the flush, you’d need to memoize it locally and use a descriptor to access it.