Skip to main content

teaql_runtime/repository/
types.rs

1use teaql_core::{EntityDescriptor, SelectQuery};
2
3use crate::{MetadataStore, UserContext};
4
5pub struct Repository<'a, D, M, E> {
6    pub(super) dialect: &'a D,
7    pub(super) metadata: &'a M,
8    pub(super) executor: &'a E,
9}
10
11pub struct ContextRepository<'a, D, E> {
12    pub(super) metadata: UserContextMetadata<'a>,
13    pub(crate) dialect: &'a D,
14    pub(crate) executor: &'a E,
15}
16
17pub struct ResolvedRepository<'a, D, E> {
18    pub(super) entity: String,
19    pub(super) repository: ContextRepository<'a, D, E>,
20    pub(super) trace_context: Vec<teaql_core::TraceNode>,
21}
22
23impl<'a, D, E> ResolvedRepository<'a, D, E> {
24    pub fn with_trace_context(mut self, trace_context: Vec<teaql_core::TraceNode>) -> Self {
25        self.trace_context = trace_context;
26        self
27    }
28}
29
30#[derive(Debug, Clone, PartialEq)]
31pub struct RelationLoadPlan {
32    pub parent_entity: String,
33    pub relation_name: String,
34    pub path: String,
35    pub target_entity: String,
36    pub local_key: String,
37    pub foreign_key: String,
38    pub many: bool,
39    pub query: Option<SelectQuery>,
40    pub children: Vec<RelationLoadPlan>,
41}
42
43pub(crate) struct UserContextMetadata<'a> {
44    pub(crate) context: &'a UserContext,
45}
46
47impl MetadataStore for UserContextMetadata<'_> {
48    fn entity(&self, name: &str) -> Option<&EntityDescriptor> {
49        self.context.entity(name)
50    }
51
52    fn all_entities(&self) -> Vec<&EntityDescriptor> {
53        self.context
54            .metadata
55            .as_ref()
56            .map(|metadata| metadata.all_entities())
57            .unwrap_or_default()
58    }
59}