Skip to main content

yugendb_core/
capabilities.rs

1//! Driver capability reporting.
2
3/// Feature report exposed by each driver.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub struct Capabilities {
6    /// Driver supports transactional operation groups.
7    pub transactions: bool,
8    /// Driver supports time-to-live expiry.
9    pub ttl: bool,
10    /// Driver supports prefix scans.
11    pub prefix_scan: bool,
12    /// Driver supports atomic increment operations.
13    pub atomic_increment: bool,
14    /// Driver supports batch writes.
15    pub batch_write: bool,
16    /// Driver exposes a raw SQL escape hatch.
17    pub raw_sql: bool,
18    /// Driver exposes a document query escape hatch.
19    pub document_query: bool,
20    /// Driver exposes JSON query behaviour.
21    pub json_query: bool,
22    /// Driver supports migration helpers.
23    pub migrations: bool,
24    /// Driver manages connection pooling.
25    pub connection_pooling: bool,
26    /// Driver supports watch or subscription behaviour.
27    pub watch: bool,
28    /// Driver supports backup helpers.
29    pub backup: bool,
30}
31
32impl Capabilities {
33    /// Minimal capability set required of every driver.
34    #[must_use]
35    pub const fn minimal() -> Self {
36        Self {
37            transactions: false,
38            ttl: false,
39            prefix_scan: false,
40            atomic_increment: false,
41            batch_write: false,
42            raw_sql: false,
43            document_query: false,
44            json_query: false,
45            migrations: false,
46            connection_pooling: false,
47            watch: false,
48            backup: false,
49        }
50    }
51
52    /// Capability shape for the memory driver.
53    #[must_use]
54    pub const fn memory() -> Self {
55        Self {
56            transactions: false,
57            ttl: true,
58            prefix_scan: true,
59            atomic_increment: false,
60            batch_write: true,
61            raw_sql: false,
62            document_query: false,
63            json_query: false,
64            migrations: false,
65            connection_pooling: false,
66            watch: false,
67            backup: false,
68        }
69    }
70
71    /// Capability shape for the SQLite driver.
72    #[must_use]
73    pub const fn sqlite() -> Self {
74        Self {
75            transactions: true,
76            ttl: true,
77            prefix_scan: true,
78            atomic_increment: false,
79            batch_write: true,
80            raw_sql: false,
81            document_query: false,
82            json_query: false,
83            migrations: true,
84            connection_pooling: false,
85            watch: false,
86            backup: false,
87        }
88    }
89}
90
91impl Default for Capabilities {
92    fn default() -> Self {
93        Self::minimal()
94    }
95}