sqlint/ast/function/
json_unquote.rs

1use super::Function;
2use crate::ast::Expression;
3
4#[derive(Debug, Clone, PartialEq)]
5pub struct JsonUnquote<'a> {
6    pub(crate) expr: Box<Expression<'a>>,
7}
8
9/// Converts a JSON expression into string and unquotes it.
10///
11/// ```rust
12/// # use sqlint::{ast::*, col, visitor::{Visitor, Mysql}};
13/// # fn main() -> Result<(), sqlint::error::Error> {
14/// let query = Select::from_table("users").value(json_unquote(col!("json")));
15/// let (sql, _) = Mysql::build(query)?;
16/// assert_eq!("SELECT JSON_UNQUOTE(`json`) FROM `users`", sql);
17/// # Ok(())
18/// # }
19/// ```
20pub fn json_unquote<'a, E>(expr: E) -> Function<'a>
21where
22    E: Into<Expression<'a>>,
23{
24    let fun = JsonUnquote { expr: Box::new(expr.into()) };
25
26    fun.into()
27}