pub trait AggregateFunction: Send + Sync {
type State: Send;
// Required methods
fn initial_state(&self) -> Self::State;
fn step(&self, state: &mut Self::State, args: &[SqliteValue]) -> Result<()>;
fn finalize(&self, state: Self::State) -> Result<SqliteValue>;
fn num_args(&self) -> i32;
fn name(&self) -> &str;
// Provided methods
fn min_args(&self) -> i32 { ... }
fn max_args(&self) -> Option<i32> { ... }
fn accepts_arg_count(&self, num_args: i32) -> bool { ... }
}Expand description
An aggregate SQL function (e.g. SUM, COUNT, AVG).
This trait is open (user-implementable). Extension authors implement this trait to register custom aggregate functions.
§State Lifecycle
initial_statecreates a fresh accumulator.stepis called once per row.finalizeconsumes the state and returns the result.
§Send + Sync
The function object itself is shared across threads via Arc. The
State type must be Send so it can be moved between threads.
Required Associated Types§
Required Methods§
Sourcefn initial_state(&self) -> Self::State
fn initial_state(&self) -> Self::State
Create a fresh accumulator (zero/identity state).
Sourcefn step(&self, state: &mut Self::State, args: &[SqliteValue]) -> Result<()>
fn step(&self, state: &mut Self::State, args: &[SqliteValue]) -> Result<()>
Process one row, updating the accumulator.
Sourcefn finalize(&self, state: Self::State) -> Result<SqliteValue>
fn finalize(&self, state: Self::State) -> Result<SqliteValue>
Consume the accumulator and produce the final result.
Provided Methods§
Sourcefn min_args(&self) -> i32
fn min_args(&self) -> i32
Minimum accepted SQL argument count for variadic functions.
Fixed-arity functions default to their exact arity. Variadic functions default to accepting zero arguments unless an implementation tightens the bound to match SQLite’s function surface.
Sourcefn max_args(&self) -> Option<i32>
fn max_args(&self) -> Option<i32>
Maximum accepted SQL argument count, or None for unbounded variadic
functions.
Sourcefn accepts_arg_count(&self, num_args: i32) -> bool
fn accepts_arg_count(&self, num_args: i32) -> bool
Return whether this function accepts num_args SQL arguments.