Last active
November 8, 2022 08:20
-
-
Save loopmode/c6c0713e5f999a5ad91ce941c4780059 to your computer and use it in GitHub Desktop.
botpress query by json field (knex, sqllite vs postgres)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let query = bp.database('web_messages') | |
if (bp.database.isLite) { | |
query | |
.where('attr_fookey', 'like', `%foo_value%`) | |
.select(bp.database.raw(`web_messages.id, json_extract(web_messages.payload, '$.foo') as attr_fookey`)) | |
} else { | |
query.whereRaw(`web_messages.payload ->>'foo' like '%foo_value%'`) | |
query.select(this.knex.raw(`web_messages.id`)) | |
} | |
console.log('\n', await query, '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment