Skip to content

How to select json in MySQL? #364

Answered by billy1624
lz1998 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @lz1998, we don't have native support for it but you could do it like below.

use sea_query::Expr;

assert_eq!(
    cake::Entity::find()
        .filter(Expr::cust("category->'$.id' = 1"))
        .filter(Expr::cust("category->'$.id'").equals(Expr::val(1)))
        .build(DbBackend::MySql)
        .to_string(),
    "SELECT `cake`.`id`, `cake`.`name` FROM `cake` WHERE category->'$.id' = 1 AND category->'$.id' = 1"
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lz1998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants