JSON LIKE

is_exist = HelperInfoModel.query.filter(and_("json_extract(content,'$.cn'" == content.get('cn'), 
HelperInfoModel.type == type, HelperInfoModel.status == Constants.DB_STATE_NORMAL)).first()

if content:
base_query = base_query.filter(or_("upper(json_extract(content,'$.cn')) like '%{}%'".format(content),
"upper(json_extract(content,'$.en')) like '%{}%'".format(content),
"upper(json_extract(content,'$.th')) like '%{}%'".format(content)))

如果是字符串like不区分大小写的话,设置表中的该字符串类型未不区分大小写就可以了

discount_info_list = DiscountInfoModel.query.filter(or_(
and_(DiscountInfoModel.discount_expiry_start_time <= today,
DiscountInfoModel.discount_expiry_end_time >= today,
DiscountInfoModel.discount_time_type == 0,
"JSON_CONTAINS(shop_id->'$', '{}')".format(shop_info.get('shop_id'))),
and_(DiscountInfoModel.discount_expiry_start_time <= today1,
DiscountInfoModel.discount_expiry_end_time >= today1,
DiscountInfoModel.discount_time_type == 1,
"JSON_CONTAINS(shop_id->'$', '{}')".format(shop_info.get('shop_id')))
)).all()
filter(DiscountInfoModel.shop_id.contains(shop_id)) 
 
原文地址:https://www.cnblogs.com/fengff/p/9282690.html