I ended up doing this so I could search for specific values for keys inside the JSON.
def JSON_KEY_EXPRESSION(field, key, value_type='string'):
db = field._db
def op(first, second):
return "%s->>'%s'" % (db._adapter.expand(first), db._adapter.expand(second))
return Expression(db, op, field, key, value_type)
Then I could do:
db(JSON_KEY_EXPRESSION(
db.category.name, 'pt').like('%bol%', case_sensitive=False)).select()
And it worked.
is this reasonable? I think that something like this could be inside Expression like day, month, year except you could refer to json keys.
Either way, the regular like should probably cast json columns into text so people could use the regular like if that's what they want.
I would fix it myself, but I don't feel like I understand the DAL codebase well enough to contribute to it, it needs some kind of technical documentation or even just a small "intro to DAL development" so people can more easily get into the code since it has very little in the way of comments.