toasty_core/stmt/expr_func.rs
1use super::{Expr, FuncCount, FuncJsonExtract, FuncLastInsertId, FuncUnnest};
2
3/// A function call expression.
4///
5/// Represents aggregate, scalar, and set-returning functions applied to
6/// expressions.
7///
8/// # Examples
9///
10/// ```text
11/// count(*) // counts all rows
12/// count(field) // counts non-null values
13/// last_insert_id() // MySQL: get the last auto-increment ID
14/// unnest(array) // PostgreSQL: expands an array into rows
15/// ```
16#[derive(Clone, Debug, PartialEq)]
17pub enum ExprFunc {
18 /// The `count` aggregate function.
19 Count(FuncCount),
20
21 /// The `LAST_INSERT_ID()` function (MySQL-specific).
22 ///
23 /// Returns the first auto-increment ID that was generated for an INSERT statement.
24 /// When multiple rows are inserted, this returns the ID of the first row.
25 LastInsertId(FuncLastInsertId),
26
27 /// Extracts a value at a key path from a document-stored value (a JSON
28 /// extraction on the SQL backends). Produced when filtering on a field
29 /// inside a `#[document]` embed.
30 JsonExtract(FuncJsonExtract),
31
32 /// Expands a PostgreSQL array into a set of rows.
33 Unnest(FuncUnnest),
34}
35
36impl From<ExprFunc> for Expr {
37 fn from(value: ExprFunc) -> Self {
38 Self::Func(value)
39 }
40}