sqlint/ast/function/
concat.rs

1use super::Function;
2use crate::ast::Expression;
3
4/// A representation of the `Concat` function in the database.
5#[derive(Debug, Clone, PartialEq)]
6pub struct Concat<'a> {
7    pub(crate) exprs: Vec<Expression<'a>>,
8}
9
10/// Concat several expressions.
11///
12/// ```rust
13/// # use sqlint::{ast::*, visitor::{Visitor, Sqlite}};
14/// # fn main() -> Result<(), sqlint::error::Error> {
15/// let query = Select::from_table("users").value(concat(vec!["firstname", "lastname"]));
16/// let (sql, params) = Sqlite::build(query)?;
17/// assert_eq!("SELECT (? || ?) FROM `users`", sql);
18/// assert_eq!(params, vec![Value::from("firstname"), Value::from("lastname")]);
19/// # Ok(())
20/// # }
21/// ```
22pub fn concat<'a, T>(exprs: Vec<T>) -> Function<'a>
23where
24    T: Into<Expression<'a>>,
25{
26    let fun = Concat { exprs: exprs.into_iter().map(Into::into).collect() };
27
28    fun.into()
29}