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