grafbase_sql_ast/ast/function/
to_jsonb.rs

1use super::Function;
2use crate::ast::Table;
3
4#[derive(Debug, Clone, PartialEq)]
5/// A representation of the `to_jsonb` function in PostgreSQL.
6pub struct ToJsonb<'a> {
7    pub(crate) table: Table<'a>,
8}
9
10/// Return the given table in JSONB.
11pub fn to_jsonb<'a>(table: impl Into<Table<'a>>) -> Function<'a> {
12    let fun = ToJsonb {
13        table: table.into(),
14    };
15
16    fun.into()
17}
18
19impl<'a> From<ToJsonb<'a>> for Function<'a> {
20    fn from(value: ToJsonb<'a>) -> Self {
21        Self {
22            typ_: super::FunctionType::ToJsonb(value),
23            alias: None,
24        }
25    }
26}