grafbase_sql_ast/ast/function/
row_to_json.rs

1use super::Function;
2use crate::ast::{FunctionType, Table};
3
4#[derive(Debug, Clone, PartialEq)]
5#[cfg(feature = "postgresql")]
6/// A representation of the `ROW_TO_JSON` function in the database.
7/// Only for `Postgresql`
8pub struct RowToJson<'a> {
9    pub(crate) expr: Table<'a>,
10    pub(crate) pretty_print: bool,
11}
12
13/// Return the given table in `JSON` format.
14#[cfg(feature = "postgresql")]
15pub fn row_to_json<'a, T>(expr: T, pretty_print: bool) -> Function<'a>
16where
17    T: Into<Table<'a>>,
18{
19    let fun = RowToJson {
20        expr: expr.into(),
21        pretty_print,
22    };
23
24    fun.into()
25}
26
27impl<'a> From<RowToJson<'a>> for Function<'a> {
28    fn from(value: RowToJson<'a>) -> Self {
29        Self {
30            typ_: FunctionType::RowToJson(value),
31            alias: None,
32        }
33    }
34}