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;
9pub(crate) mod 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::AutoVacuumMode;
22pub use self::connection::BusyDecision;
23pub use self::connection::CommitDecision;
24pub use self::connection::ProgressDecision;
25pub use self::connection::SerializedDatabase;
26pub use self::connection::SqliteBindValue;
27pub use self::connection::SqliteConnection;
28pub use self::connection::SqliteLimit;
29pub use self::connection::SqliteTraceEvent;
30pub use self::connection::SqliteTraceFlags;
31pub use self::connection::SqliteValue;
32pub use self::connection::authorizer;
33pub use self::connection::sqlite_blob::SqliteReadOnlyBlob;
34pub use self::connection::{AuthorizerContext, AuthorizerDecision};
35pub use self::connection::{CollationNeededContext, SqliteTextRep};
36#[cfg(feature = "i-implement-a-third-party-backend-and-opt-into-breaking-changes")]
37pub use self::connection::{
38    OwnedSqliteBindValue, SqliteBindCollector, SqliteBindCollectorData, SqliteBindValueRef,
39};
40pub use self::connection::{
41    SqliteChangeEvent, SqliteChangeOp, SqliteChangeOps, SqliteUpdateRouter,
42};
43#[cfg(feature = "__sqlite-shared")]
44pub use self::function_behavior::SqliteFunctionBehavior;
45pub use self::query_builder::SqliteQueryBuilder;
46
47/// Trait for the implementation of a SQLite aggregate function
48///
49/// This trait is to be used in conjunction with the `define_sql_function!`
50/// macro for defining a custom SQLite aggregate function. See
51/// the documentation [there](super::prelude::define_sql_function!) for details.
52pub trait SqliteAggregateFunction<Args>: Default {
53    /// The result type of the SQLite aggregate function
54    type Output;
55
56    /// The `step()` method is called once for every record of the query.
57    ///
58    /// This is called through a C FFI, as such panics do not propagate to the caller. Panics are
59    /// caught and cause a return with an error value. The implementation must still ensure that
60    /// state remains in a valid state (refer to [`std::panic::UnwindSafe`] for a bit more detail).
61    fn step(&mut self, args: Args);
62
63    /// After the last row has been processed, the `finalize()` method is
64    /// called to compute the result of the aggregate function. If no rows
65    /// were processed `aggregator` will be `None` and `finalize()` can be
66    /// used to specify a default result.
67    ///
68    /// This is called through a C FFI, as such panics do not propagate to the caller. Panics are
69    /// caught and cause a return with an error value.
70    fn finalize(aggregator: Option<Self>) -> Self::Output;
71}
72
73/// SQLite specific sql types
74pub mod sql_types {
75    #[doc(inline)]
76    pub use super::types::Timestamptz;
77
78    #[cfg(feature = "__sqlite-shared")]
79    #[doc(inline)]
80    pub use super::types::JsonValidFlags;
81}
82
83#[cfg(feature = "__sqlite-shared")]
84pub use self::types::JsonValidFlag;