Skip to main content

diesel/sqlite/
mod.rs

1//! Provides types and functions related to working with SQLite
2//!
3//! Much of this module is re-exported from database agnostic locations.
4//! However, if you are writing code specifically to extend Diesel on
5//! SQLite, you may need to work with this module directly.
6
7mod auto_extension;
8pub(crate) mod backend;
9mod connection;
10pub mod expression;
11mod function_behavior;
12
13pub mod query_builder;
14
15mod types;
16
17pub use self::auto_extension::cancel_auto_extension;
18pub use self::auto_extension::register_auto_extension;
19pub use self::auto_extension::reset_auto_extension;
20pub use self::backend::{Sqlite, SqliteType};
21pub use self::connection::CommitDecision;
22pub use self::connection::ProgressDecision;
23pub use self::connection::SerializedDatabase;
24pub use self::connection::SqliteBindValue;
25pub use self::connection::SqliteConnection;
26pub use self::connection::SqliteLimit;
27pub use self::connection::SqliteValue;
28pub use self::connection::sqlite_blob::SqliteReadOnlyBlob;
29#[cfg(feature = "__sqlite-shared")]
30pub use self::function_behavior::SqliteFunctionBehavior;
31pub use self::query_builder::SqliteQueryBuilder;
32
33/// Trait for the implementation of a SQLite aggregate function
34///
35/// This trait is to be used in conjunction with the `define_sql_function!`
36/// macro for defining a custom SQLite aggregate function. See
37/// the documentation [there](super::prelude::define_sql_function!) for details.
38pub trait SqliteAggregateFunction<Args>: Default {
39    /// The result type of the SQLite aggregate function
40    type Output;
41
42    /// The `step()` method is called once for every record of the query.
43    ///
44    /// This is called through a C FFI, as such panics do not propagate to the caller. Panics are
45    /// caught and cause a return with an error value. The implementation must still ensure that
46    /// state remains in a valid state (refer to [`std::panic::UnwindSafe`] for a bit more detail).
47    fn step(&mut self, args: Args);
48
49    /// After the last row has been processed, the `finalize()` method is
50    /// called to compute the result of the aggregate function. If no rows
51    /// were processed `aggregator` will be `None` and `finalize()` can be
52    /// used to specify a default result.
53    ///
54    /// This is called through a C FFI, as such panics do not propagate to the caller. Panics are
55    /// caught and cause a return with an error value.
56    fn finalize(aggregator: Option<Self>) -> Self::Output;
57}
58
59/// SQLite specific sql types
60pub mod sql_types {
61    #[doc(inline)]
62    pub use super::types::Timestamptz;
63
64    #[cfg(feature = "__sqlite-shared")]
65    #[doc(inline)]
66    pub use super::types::JsonValidFlags;
67}
68
69#[cfg(feature = "__sqlite-shared")]
70pub use self::types::JsonValidFlag;