From e3e8e55bf6232f295fa238c5b685e3e41e1d3aa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabor=20K=C3=B6rber?= Date: Sat, 30 Dec 2023 22:46:20 +0100 Subject: [PATCH] docs(NOTES): adding ideas about how to do the dynamic repositories --- NOTES.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/NOTES.md b/NOTES.md index 1972d82..93016dc 100644 --- a/NOTES.md +++ b/NOTES.md @@ -49,3 +49,50 @@ It's not like that is a bad thing, given this is also one of the downsides I wit sea-orm-cli generate entity -u postgresql://miniweb:miniweb@localhost:54321/miniweb -o entity/src --lib + + +## Admin Registry + +### Dynamic index functions + + +### Dynamic Repo Traits + +```rust +trait AdminRepository { + type Item; + type List; + + fn get_item(&self, id: usize) -> Option; + fn get_list(&self) -> Self::List; +} + +struct AdminRegistry { + repositories: HashMap>, +} + +impl AdminRegistry { + fn register(&mut self, name: &str, repository: R) { + self.repositories.insert(name.to_string(), Box::new(repository)); + } +} +``` + + +```rust +struct UserRepository; + +impl AdminRepository for UserRepository { + type Item = User; + type List = Vec; + + fn get_item(&self, id: usize) -> Option { + // Retrieve a single user + } + + fn get_list(&self) -> Vec { + // Retrieve a list of users + } +} + +``` \ No newline at end of file