teaql_runtime/repository/
types.rs1use 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}
21
22#[derive(Debug, Clone, PartialEq)]
23pub struct RelationLoadPlan {
24 pub parent_entity: String,
25 pub relation_name: String,
26 pub path: String,
27 pub target_entity: String,
28 pub local_key: String,
29 pub foreign_key: String,
30 pub many: bool,
31 pub query: Option<SelectQuery>,
32 pub children: Vec<RelationLoadPlan>,
33}
34
35pub(crate) struct UserContextMetadata<'a> {
36 pub(crate) context: &'a UserContext,
37}
38
39impl MetadataStore for UserContextMetadata<'_> {
40 fn entity(&self, name: &str) -> Option<&EntityDescriptor> {
41 self.context.entity(name)
42 }
43
44 fn all_entities(&self) -> Vec<&EntityDescriptor> {
45 self.context
46 .metadata
47 .as_ref()
48 .map(|metadata| metadata.all_entities())
49 .unwrap_or_default()
50 }
51}