ic_dbms_api/dbms/table/
schema.rs1use std::hash::{Hash as _, Hasher as _};
2
3use candid::CandidType;
4
5use crate::dbms::foreign_fetcher::ForeignFetcher;
6use crate::dbms::table::column_def::ColumnDef;
7use crate::dbms::table::{InsertRecord, TableRecord, UpdateRecord};
8use crate::memory::Encode;
9
10pub type TableFingerprint = u64;
12
13pub trait TableSchema
17where
18 Self: Encode + CandidType + 'static,
19{
20 type Record: TableRecord<Schema = Self>;
23 type Insert: InsertRecord<Schema = Self>;
25 type Update: UpdateRecord<Schema = Self>;
27 type ForeignFetcher: ForeignFetcher;
29
30 fn table_name() -> &'static str;
32
33 fn columns() -> &'static [ColumnDef];
35
36 fn primary_key() -> &'static str;
38
39 fn to_values(self) -> Vec<(ColumnDef, crate::dbms::value::Value)>;
41
42 fn foreign_fetcher() -> Self::ForeignFetcher {
44 Default::default()
45 }
46
47 fn fingerprint() -> TableFingerprint {
49 let mut hasher = std::hash::DefaultHasher::new();
50 std::any::TypeId::of::<Self>().hash(&mut hasher);
51 hasher.finish()
52 }
53}