sajad torkamani

In a nutshell

Assuming a state table like this:

idstate_keystate_value
1has_accepted_cookies{ “value”: true, “cookieTypes”: [“Foo”, “Bar” }
2has_used_chat{ “value”: true, “date”: “2023-02-01 }
3has_used_chat{ “value”: true, “date”: “2023-05-04 }

You can query the rows by specific JSON fields like so:

SELECT *
FROM state
where state_key = 'has_used_chat'
  and state_value -> '$.value' = true;

OR:

SELECT *
FROM state
where state_key = 'has_used_chat'
  and state_value -> '$.date' = '2023-02-01';

Sources

Tagged: MySQL

Leave a comment

Your email address will not be published. Required fields are marked *