mirror of
https://github.com/isar/rusqlite.git
synced 2025-02-01 10:50:51 +08:00
Add some documentation
This commit is contained in:
parent
83b9fd0aba
commit
987b06cf79
@ -332,12 +332,16 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Aggregate is the callback interface for user-defined aggregate function.
|
||||||
|
///
|
||||||
|
/// `A` is the type of the aggregation context and `T` is the type of the final result.
|
||||||
|
/// Implementations should be stateless.
|
||||||
pub trait Aggregate<A, T> where T: ToResult {
|
pub trait Aggregate<A, T> where T: ToResult {
|
||||||
/// Initializes the aggregation context.
|
/// Initializes the aggregation context.
|
||||||
fn init(&self) -> A; // TODO Validate: Fn(&Context)
|
fn init(&self) -> A;
|
||||||
/// "step" function called once for each row in an aggregate group.
|
/// "step" function called once for each row in an aggregate group.
|
||||||
fn step(&self, &mut Context, &mut A) -> Result<()>; // TODO Validate: Fn(&Context, A) -> A
|
fn step(&self, &mut Context, &mut A) -> Result<()>;
|
||||||
/// Computes and sets the final result.
|
/// Computes and returns the final result.
|
||||||
fn finalize(&self, &A) -> Result<T>;
|
fn finalize(&self, &A) -> Result<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,6 +389,11 @@ impl Connection {
|
|||||||
self.db.borrow_mut().create_scalar_function(fn_name, n_arg, deterministic, x_func)
|
self.db.borrow_mut().create_scalar_function(fn_name, n_arg, deterministic, x_func)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Attach a user-defined aggregate function to this database connection.
|
||||||
|
///
|
||||||
|
/// # Failure
|
||||||
|
///
|
||||||
|
/// Will return Err if the function could not be attached to the connection.
|
||||||
pub fn create_aggregate_function<A, D, T>(&self,
|
pub fn create_aggregate_function<A, D, T>(&self,
|
||||||
fn_name: &str,
|
fn_name: &str,
|
||||||
n_arg: c_int,
|
n_arg: c_int,
|
||||||
@ -402,7 +411,7 @@ impl Connection {
|
|||||||
/// Removes a user-defined function from this database connection.
|
/// Removes a user-defined function from this database connection.
|
||||||
///
|
///
|
||||||
/// `fn_name` and `n_arg` should match the name and number of arguments
|
/// `fn_name` and `n_arg` should match the name and number of arguments
|
||||||
/// given to `create_scalar_function`.
|
/// given to `create_scalar_function` or `create_aggregate_function`.
|
||||||
///
|
///
|
||||||
/// # Failure
|
/// # Failure
|
||||||
///
|
///
|
||||||
@ -793,9 +802,9 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(4, result);
|
assert_eq!(4, result);
|
||||||
|
|
||||||
let single_sum = "SELECT my_sum(i), my_sum(j) FROM (SELECT 2 AS i, 1 AS j UNION ALL \
|
let dual_sum = "SELECT my_sum(i), my_sum(j) FROM (SELECT 2 AS i, 1 AS j UNION ALL SELECT \
|
||||||
SELECT 2, 1)";
|
2, 1)";
|
||||||
let result: (i64, i64) = db.query_row(single_sum, &[], |r| (r.get(0), r.get(1)))
|
let result: (i64, i64) = db.query_row(dual_sum, &[], |r| (r.get(0), r.get(1)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!((4, 2), result);
|
assert_eq!((4, 2), result);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user