在 JSONField 中搜索文本
Search text in JSONField
我使用 peewee
和 SQLite
。我的一个模型包含 JSONField
(docs link),现在我需要查询该字段包含我的字符串的所有行。
class Market(Model):
...
data = JSONField()
class Meta:
database = db
如果我尝试下面的代码,什么都没有 returns:
Market.select().where(Market.data.contains(search))
示例数据:
Market.data
: ['123', '456', '789']
search
: 456
如何查找 Market.data
字段包含 search
文本的所有行?
sqlite json1 扩展不提供“包含”功能。您可能希望使用 json_each()
或 json_tree
table-valued 函数:
https://sqlite.org/json1.html#examples_using_json_each_and_json_tree_
Sqlite json1 扩展文档:
Peewee sqlite json1 扩展文档:
http://docs.peewee-orm.com/en/latest/peewee/sqlite_ext.html#sqlite-json1
我使用 peewee
和 SQLite
。我的一个模型包含 JSONField
(docs link),现在我需要查询该字段包含我的字符串的所有行。
class Market(Model):
...
data = JSONField()
class Meta:
database = db
如果我尝试下面的代码,什么都没有 returns:
Market.select().where(Market.data.contains(search))
示例数据:
Market.data
:['123', '456', '789']
search
:456
如何查找 Market.data
字段包含 search
文本的所有行?
sqlite json1 扩展不提供“包含”功能。您可能希望使用 json_each()
或 json_tree
table-valued 函数:
https://sqlite.org/json1.html#examples_using_json_each_and_json_tree_
Sqlite json1 扩展文档:
Peewee sqlite json1 扩展文档:
http://docs.peewee-orm.com/en/latest/peewee/sqlite_ext.html#sqlite-json1