我正在将书架/ Knex用于ORM。我有一个MySQL数据库,该数据库的表包含一个称为“数据”的JSON字段。在该字段内,有一个键“标题”和一个键“消息”。我想返回在data.title或data.message中具有子字符串“ searchString”的所有行。我该怎么办?
这项工作吗?
qb.raw(`data->'title' LIKE ${searchString} OR data->'message LIKE ${searchString}`)
此作品:
const results = await new Modelname()
.query((qb) => {
qb.whereRaw(
`JSONColumnName->
'$.JSONFieldName' LIKE "%${searchString}%"`)
})
.fetch();
“ JSONColumnName”是JSON列的名称,“ JSONFieldName”是该列内的某些JSON字段的名称。