def withdata(model_column):
"""Returns a filter argument for returning instances with values of
`model_column` NOT *empty* nor *null*. `model_column` type must be STRING or BLOB
:param model_column: A valid column name, e.g. an attribute Column defined in some
sqlalchemy orm model class (e.g., 'User.data'). **The type of the column must be STRING or
BLOB**, otherwise result is undefined. For instance, numeric column with zero as value
are *not* empty (as the sql length function applied to numeric returns the number of
bytes)
:example:
# given a table User, return empty or none via "~"
session.query(User.id).filter(~withdata(User.data)).all()
# return "valid" columns:
session.query(User.id).filter(withdata(User.data)).all()
```
"""
return (model_column.isnot(None)) & (func.length(model_column) > 0)
http://stackoverflow.com/questions/13712381/how-to-turn-on-pragma-foreign-keys-on-in-sqlalchemy-migration-script-or-conf
for setting foreign keys in sqlite:
```