ic_dbms_api/dbms/foreign_fetcher.rs
1use crate::dbms::table::TableColumns;
2use crate::dbms::value::Value;
3use crate::prelude::{Database, IcDbmsResult};
4
5/// This trait defines the behavior of a foreign fetcher, which is responsible for
6/// fetching data from foreign sources or databases.
7///
8/// It takes a table name and returns the values associated with that table.
9pub trait ForeignFetcher: Default {
10 /// Fetches the data for the specified table and primary key values.
11 ///
12 /// # Arguments
13 ///
14 /// * `database` - The database from which to fetch the data.
15 /// * `table` - The name of the table to fetch data from.
16 /// * `pk_values` - The primary key to look for.
17 ///
18 /// # Returns
19 ///
20 /// A result containing the fetched table columns or an error.
21 fn fetch(
22 &self,
23 database: &impl Database,
24 table: &'static str,
25 local_column: &'static str,
26 pk_value: Value,
27 ) -> IcDbmsResult<TableColumns>;
28}
29
30/// A no-op foreign fetcher that does not perform any fetching.
31#[derive(Default)]
32pub struct NoForeignFetcher;
33
34impl ForeignFetcher for NoForeignFetcher {
35 fn fetch(
36 &self,
37 _database: &impl Database,
38 _table: &'static str,
39 _local_column: &'static str,
40 _pk_value: Value,
41 ) -> IcDbmsResult<TableColumns> {
42 unimplemented!("NoForeignFetcher should have a table without foreign keys");
43 }
44}