Skip to content

Instantly share code, notes, and snippets.

@loopmode
Last active November 8, 2022 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loopmode/c6c0713e5f999a5ad91ce941c4780059 to your computer and use it in GitHub Desktop.
Save loopmode/c6c0713e5f999a5ad91ce941c4780059 to your computer and use it in GitHub Desktop.
botpress query by json field (knex, sqllite vs postgres)
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