1#![warn(missing_docs)]
8#![warn(rustdoc::bare_urls)]
9#![warn(clippy::large_futures)]
10#![allow(clippy::mutable_key_type)] use std::sync::Arc;
13
14pub use nostr;
15
16mod collections;
17mod error;
18mod events;
19#[cfg(feature = "flatbuf")]
20pub mod flatbuffers;
21pub mod memory;
22pub mod prelude;
23pub mod profile;
24mod wipe;
25
26pub use self::collections::events::Events;
27pub use self::error::DatabaseError;
28pub use self::events::helper::{DatabaseEventResult, DatabaseHelper};
29pub use self::events::{
30 DatabaseEventStatus, IntoNostrEventsDatabase, NostrEventsDatabase, NostrEventsDatabaseExt,
31 RejectedReason, SaveEventStatus,
32};
33#[cfg(feature = "flatbuf")]
34pub use self::flatbuffers::{FlatBufferBuilder, FlatBufferDecode, FlatBufferEncode};
35pub use self::memory::{MemoryDatabase, MemoryDatabaseOptions};
36pub use self::profile::Profile;
37pub use self::wipe::NostrDatabaseWipe;
38
39#[derive(Debug, Clone, PartialEq, Eq)]
41pub enum Backend {
42 Memory,
44 RocksDB,
46 LMDB,
48 SQLite,
50 IndexedDB,
52 Custom(String),
54}
55
56impl Backend {
57 pub fn is_persistent(&self) -> bool {
61 !matches!(self, Self::Memory)
62 }
63}
64
65#[doc(hidden)]
66pub trait IntoNostrDatabase {
67 fn into_nostr_database(self) -> Arc<dyn NostrDatabase>;
68}
69
70impl IntoNostrDatabase for Arc<dyn NostrDatabase> {
71 fn into_nostr_database(self) -> Arc<dyn NostrDatabase> {
72 self
73 }
74}
75
76impl<T> IntoNostrDatabase for T
77where
78 T: NostrDatabase + Sized + 'static,
79{
80 fn into_nostr_database(self) -> Arc<dyn NostrDatabase> {
81 Arc::new(self)
82 }
83}
84
85impl<T> IntoNostrDatabase for Arc<T>
86where
87 T: NostrDatabase + 'static,
88{
89 fn into_nostr_database(self) -> Arc<dyn NostrDatabase> {
90 self
91 }
92}
93
94pub trait NostrDatabase: NostrEventsDatabase + NostrDatabaseWipe {
96 fn backend(&self) -> Backend;
98}
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn test_backend_is_persistent() {
106 assert!(!Backend::Memory.is_persistent());
107 assert!(Backend::RocksDB.is_persistent());
108 assert!(Backend::LMDB.is_persistent());
109 assert!(Backend::SQLite.is_persistent());
110 assert!(Backend::IndexedDB.is_persistent());
111 assert!(Backend::Custom("custom".to_string()).is_persistent());
112 }
113}