question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support conditions inside json

See original GitHub issue

Is there a way adding search conditions that apply to json? I mean, let’s say I have Users table with a JSON column called email (the json should be 2 fields - ‘address’ and ‘isVerified’). Now, if I want to search for a user with a specific email I would use the raw query - select * from "Users" where email->>'address' = 'abc@gmail.com'; Is there a way doing that using knex syntax?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elhigucommented, May 7, 2017

With knex the only way how to do jsonb queries is knex.raw.

You can limit the part of raw to where it is needed like:

knex('Users').where(knex.raw(`??->>'address'`, ['email']), 'abc@gmail.com');

Only knex based DB library that I know which supports jsonb queries is objection.js. With that you can do:

// note: this doesn't work with knex
.where('email:address', 'abc@gmail.com');
0reactions
elhigucommented, Jan 13, 2021

No.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use if statement inside JSON? - Stack Overflow
Validating the JSON Schema Draft-07, JSON now supports the if...then...else keywords for conditional data representation.
Read more >
JSON Conditions
Use the JSON_EXISTS condition to test whether a specified JSON value exists in JSON data. This condition returns TRUE if the JSON value...
Read more >
Solved: I want to put if else condition in json payload
I have json payload in response . Except: If speed >50 i want to print "speed:""high" or "low". The rest of the data...
Read more >
How to make IF conditions in JSON request body - ServiceNow
You should create json request based on IF condition rather than trying to add If condition within json request. 0 Helpful.
Read more >
JSON Syntax - W3Schools
JSON syntax is derived from JavaScript object notation syntax: Data is in name/value pairs ... In JSON, keys must be strings, written with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found