1mod page_bytes;
4
5pub use page_bytes::PageBytes;
6
7pub const HEAD_FENCE_MISMATCH_GROUP: &str = "depot";
8pub const HEAD_FENCE_MISMATCH_CODE: &str = "head_fence_mismatch";
9
10pub fn is_head_fence_mismatch(group: &str, code: &str) -> bool {
11 group == HEAD_FENCE_MISMATCH_GROUP && code == HEAD_FENCE_MISMATCH_CODE
12}
13
14pub const TRANSACTION_TOO_LARGE_GROUP: &str = "sqlite";
17pub const TRANSACTION_TOO_LARGE_CODE: &str = "transaction_too_large";
18
19pub fn is_transaction_too_large(group: &str, code: &str) -> bool {
20 group == TRANSACTION_TOO_LARGE_GROUP && code == TRANSACTION_TOO_LARGE_CODE
21}
22
23pub const SHARD_SIZE: u32 = 64;
27
28pub const COMMIT_SEGMENT_MAX_SHARDS: u32 = 5;
30
31pub const MAX_COMMIT_DIRTY_PAGES: usize = 32_768;
35
36pub fn segment_start_for_page(pgno: u32) -> u32 {
38 pgno / SHARD_SIZE * SHARD_SIZE
39}
40
41pub fn cut_page_segments<T>(pages: &[T], pgno_of: impl Fn(&T) -> u32) -> Vec<(u32, &[T])> {
49 let mut segments = Vec::new();
50 let mut start = 0;
51 while start < pages.len() {
52 let first_shard = pgno_of(&pages[start]) / SHARD_SIZE;
53 let shard_limit = first_shard.saturating_add(COMMIT_SEGMENT_MAX_SHARDS);
56 let end = pages[start..]
57 .iter()
58 .position(|page| pgno_of(page) / SHARD_SIZE >= shard_limit)
59 .map_or(pages.len(), |offset| start + offset);
60 segments.push((first_shard * SHARD_SIZE, &pages[start..end]));
61 start = end;
62 }
63
64 segments
65}
66
67#[derive(Clone, Debug, PartialEq)]
68pub enum BindParam {
69 Null,
70 Integer(i64),
71 Float(f64),
72 Text(String),
73 Blob(Vec<u8>),
74}
75
76#[derive(Clone, Debug, PartialEq)]
77pub struct ExecResult {
78 pub changes: i64,
79}
80
81#[derive(Clone, Debug, PartialEq)]
82pub struct QueryResult {
83 pub columns: Vec<String>,
84 pub rows: Vec<Vec<ColumnValue>>,
85}
86
87#[derive(Clone, Debug, PartialEq)]
88pub struct ExecuteResult {
89 pub columns: Vec<String>,
90 pub rows: Vec<Vec<ColumnValue>>,
91 pub changes: i64,
92 pub last_insert_row_id: Option<i64>,
93}
94
95impl ExecuteResult {
96 pub fn into_query_result(self) -> QueryResult {
97 QueryResult {
98 columns: self.columns,
99 rows: self.rows,
100 }
101 }
102
103 pub fn into_exec_result(self) -> ExecResult {
104 ExecResult {
105 changes: self.changes,
106 }
107 }
108}
109
110#[derive(Clone, Debug, PartialEq)]
111pub enum ColumnValue {
112 Null,
113 Integer(i64),
114 Float(f64),
115 Text(String),
116 Blob(Vec<u8>),
117}
118
119