docs(NOTES): adding ideas about how to do the dynamic repositories

This commit is contained in:
Gabor Körber 2023-12-30 22:46:20 +01:00
parent da01827419
commit e3e8e55bf6

View File

@ -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 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<Self::Item>;
fn get_list(&self) -> Self::List;
}
struct AdminRegistry {
repositories: HashMap<String, Box<dyn Any>>,
}
impl AdminRegistry {
fn register<R: AdminRepository + 'static>(&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<User>;
fn get_item(&self, id: usize) -> Option<User> {
// Retrieve a single user
}
fn get_list(&self) -> Vec<User> {
// Retrieve a list of users
}
}
```