1#[derive(Debug, Clone, Copy)]
5pub enum DurabilityMode {
6 Immediate,
7 PeriodicMs(u64),
8 None,
9}
10
11#[derive(Debug, Clone)]
12pub struct OutboxConfig {
13 pub enabled: bool,
14 pub retry_interval_ms: u64,
15 pub max_retries: u32,
16 pub batch_size: usize,
17}
18
19impl Default for OutboxConfig {
20 fn default() -> Self {
21 Self {
22 enabled: true,
23 retry_interval_ms: 5000,
24 max_retries: 10,
25 batch_size: 100,
26 }
27 }
28}
29
30#[derive(Debug, Clone)]
31pub struct SharedSubscriptionConfig {
32 pub num_partitions: u8,
33 pub consumer_timeout_ms: u64,
34}
35
36impl Default for SharedSubscriptionConfig {
37 fn default() -> Self {
38 Self {
39 num_partitions: 8,
40 consumer_timeout_ms: 30_000,
41 }
42 }
43}
44
45#[cfg(not(target_arch = "wasm32"))]
46mod native {
47 use super::{DurabilityMode, OutboxConfig, SharedSubscriptionConfig};
48 use std::path::PathBuf;
49
50 #[derive(Debug, Clone)]
51 pub struct DatabaseConfig {
52 pub path: PathBuf,
53 pub durability: DurabilityMode,
54 pub event_channel_capacity: usize,
55 pub max_list_results: Option<usize>,
56 pub max_subscriptions: Option<usize>,
57 pub ttl_cleanup_interval_secs: Option<u64>,
58 pub max_cursor_buffer: usize,
59 pub max_sort_buffer: usize,
60 pub outbox: OutboxConfig,
61 pub shared_subscription: SharedSubscriptionConfig,
62 pub spawn_background_tasks: bool,
63 pub passphrase: Option<String>,
64 }
65
66 impl DatabaseConfig {
67 pub fn new<P: Into<PathBuf>>(path: P) -> Self {
68 Self {
69 path: path.into(),
70 durability: DurabilityMode::Immediate,
71 event_channel_capacity: 1000,
72 max_list_results: Some(10_000),
73 max_subscriptions: Some(1_000),
74 ttl_cleanup_interval_secs: Some(60),
75 max_cursor_buffer: 100,
76 max_sort_buffer: 10_000,
77 outbox: OutboxConfig::default(),
78 shared_subscription: SharedSubscriptionConfig::default(),
79 spawn_background_tasks: true,
80 passphrase: None,
81 }
82 }
83
84 #[must_use]
85 pub fn without_background_tasks(mut self) -> Self {
86 self.spawn_background_tasks = false;
87 self
88 }
89
90 #[must_use]
91 pub fn with_durability(mut self, mode: DurabilityMode) -> Self {
92 self.durability = mode;
93 self
94 }
95
96 #[must_use]
97 pub fn with_event_capacity(mut self, capacity: usize) -> Self {
98 self.event_channel_capacity = capacity;
99 self
100 }
101
102 #[must_use]
103 pub fn with_max_list_results(mut self, max: Option<usize>) -> Self {
104 self.max_list_results = max;
105 self
106 }
107
108 #[must_use]
109 pub fn with_max_subscriptions(mut self, max: Option<usize>) -> Self {
110 self.max_subscriptions = max;
111 self
112 }
113
114 #[must_use]
115 pub fn with_ttl_cleanup_interval(mut self, interval_secs: Option<u64>) -> Self {
116 self.ttl_cleanup_interval_secs = interval_secs;
117 self
118 }
119
120 #[must_use]
121 pub fn with_outbox(mut self, outbox: OutboxConfig) -> Self {
122 self.outbox = outbox;
123 self
124 }
125
126 #[must_use]
127 pub fn with_shared_subscription(mut self, config: SharedSubscriptionConfig) -> Self {
128 self.shared_subscription = config;
129 self
130 }
131
132 #[must_use]
133 pub fn with_passphrase(mut self, passphrase: String) -> Self {
134 self.passphrase = Some(passphrase);
135 self
136 }
137 }
138
139 impl Default for DatabaseConfig {
140 fn default() -> Self {
141 Self::new("./data/mqdb")
142 }
143 }
144}
145
146#[cfg(not(target_arch = "wasm32"))]
147pub use native::DatabaseConfig;