ic_dbms_api/dbms/table/
schema.rs1use std::hash::{Hash as _, Hasher as _};
2
3use crate::dbms::foreign_fetcher::ForeignFetcher;
4use crate::dbms::table::column_def::ColumnDef;
5use crate::dbms::table::{InsertRecord, TableRecord, UpdateRecord};
6use crate::memory::Encode;
7
8pub type TableFingerprint = u64;
10
11pub trait TableSchema
15where
16 Self: Encode + 'static,
17{
18 type Record: TableRecord<Schema = Self>;
21 type Insert: InsertRecord<Schema = Self>;
23 type Update: UpdateRecord<Schema = Self>;
25 type ForeignFetcher: ForeignFetcher;
27
28 fn table_name() -> &'static str;
30
31 fn columns() -> &'static [ColumnDef];
33
34 fn primary_key() -> &'static str;
36
37 fn to_values(self) -> Vec<(ColumnDef, crate::dbms::value::Value)>;
39
40 fn foreign_fetcher() -> Self::ForeignFetcher {
42 Default::default()
43 }
44
45 fn fingerprint() -> TableFingerprint {
47 let mut hasher = std::hash::DefaultHasher::new();
48 std::any::TypeId::of::<Self>().hash(&mut hasher);
49 hasher.finish()
50 }
51}