nodedb_sql/resolver/expr/convert/
builtins.rs1use sqlparser::ast::Expr;
7
8use crate::error::Result;
9use crate::resolver::ColumnScope;
10use crate::types::*;
11
12use super::entry::convert_expr_depth;
13
14pub(super) fn convert_trim(
16 expr: &Expr,
17 depth: &mut usize,
18 scope: &ColumnScope<'_>,
19) -> Result<SqlExpr> {
20 Ok(SqlExpr::Function {
21 name: "trim".into(),
22 args: vec![convert_expr_depth(expr, depth, scope)?],
23 distinct: false,
24 })
25}
26
27pub(super) fn convert_ceil(
29 expr: &Expr,
30 depth: &mut usize,
31 scope: &ColumnScope<'_>,
32) -> Result<SqlExpr> {
33 Ok(SqlExpr::Function {
34 name: "ceil".into(),
35 args: vec![convert_expr_depth(expr, depth, scope)?],
36 distinct: false,
37 })
38}
39
40pub(super) fn convert_floor(
42 expr: &Expr,
43 depth: &mut usize,
44 scope: &ColumnScope<'_>,
45) -> Result<SqlExpr> {
46 Ok(SqlExpr::Function {
47 name: "floor".into(),
48 args: vec![convert_expr_depth(expr, depth, scope)?],
49 distinct: false,
50 })
51}
52
53pub(super) fn convert_substring(
55 expr: &Expr,
56 substring_from: Option<&Expr>,
57 substring_for: Option<&Expr>,
58 depth: &mut usize,
59 scope: &ColumnScope<'_>,
60) -> Result<SqlExpr> {
61 let mut args = vec![convert_expr_depth(expr, depth, scope)?];
62 if let Some(from) = substring_from {
63 args.push(convert_expr_depth(from, depth, scope)?);
64 }
65 if let Some(len) = substring_for {
66 args.push(convert_expr_depth(len, depth, scope)?);
67 }
68 Ok(SqlExpr::Function {
69 name: "substring".into(),
70 args,
71 distinct: false,
72 })
73}