Skip to main content

pop_fork/
models.rs

1use crate::schema::{blocks, local_keys, local_values, prefix_scans, storage};
2use diesel::{Insertable, Queryable, Selectable};
3
4#[derive(Insertable, Clone)]
5#[diesel(table_name = storage)]
6pub(crate) struct NewStorageRow<'a> {
7	pub block_hash: &'a [u8],
8	pub key: &'a [u8],
9	pub value: Option<&'a [u8]>,
10	pub is_empty: bool,
11}
12
13/// Local key row for insertions
14#[derive(Insertable, Clone)]
15#[diesel(table_name = local_keys)]
16pub(crate) struct NewLocalKeyRow<'a> {
17	pub key: &'a [u8],
18}
19
20/// Local key row for query results
21#[derive(Queryable, Selectable, Clone, Debug)]
22#[diesel(table_name = local_keys)]
23pub struct LocalKeyRow {
24	pub id: i32,
25	pub key: Vec<u8>,
26}
27
28/// Local value row for insertions
29#[derive(Insertable, Clone)]
30#[diesel(table_name = local_values)]
31pub(crate) struct NewLocalValueRow {
32	pub key_id: i32,
33	pub value: Option<Vec<u8>>,
34	pub valid_from: i64,
35	pub valid_until: Option<i64>,
36}
37
38/// Block row for insertions (uses borrowed data to avoid allocations)
39#[derive(Insertable, Clone)]
40#[diesel(table_name = blocks)]
41pub(crate) struct NewBlockRow<'a> {
42	pub hash: &'a [u8],
43	pub number: i64,
44	pub parent_hash: &'a [u8],
45	pub header: &'a [u8],
46}
47
48/// Block row for query results (uses owned data).
49#[derive(Queryable, Selectable, Clone, Debug)]
50#[diesel(table_name = blocks)]
51pub struct BlockRow {
52	/// Block hash (32 bytes).
53	pub hash: Vec<u8>,
54	/// Block number.
55	pub number: i64,
56	/// Parent block hash (32 bytes).
57	pub parent_hash: Vec<u8>,
58	/// SCALE-encoded block header.
59	pub header: Vec<u8>,
60}
61
62/// Prefix scan row for insertions (uses borrowed data to avoid allocations)
63#[derive(Insertable, Clone)]
64#[diesel(table_name = prefix_scans)]
65pub(crate) struct NewPrefixScanRow<'a> {
66	pub(crate) block_hash: &'a [u8],
67	pub(crate) prefix: &'a [u8],
68	pub(crate) last_scanned_key: Option<&'a [u8]>,
69	pub(crate) is_complete: bool,
70}