Skip to main content

ferrox_database_core/
lib.rs

1use async_trait::async_trait;
2use ferrox_errors::AppError;
3
4/// Core Repository Trait
5/// This is the equivalent of the base repository in TypeORM/NestJS.
6/// Implementations (like SeaORM or Mongo) will implement this trait for specific entities.
7#[async_trait]
8pub trait Repository<Entity, Id> {
9    /// Finds a single entity by its primary key
10    async fn find_by_id(&self, id: Id) -> Result<Option<Entity>, AppError>;
11    
12    /// Finds all entities
13    async fn find_all(&self) -> Result<Vec<Entity>, AppError>;
14    
15    /// Inserts a new entity
16    async fn insert(&self, entity: Entity) -> Result<Entity, AppError>;
17    
18    /// Updates an existing entity
19    async fn update(&self, id: Id, entity: Entity) -> Result<Entity, AppError>;
20    
21    /// Deletes an entity by its primary key
22    async fn delete(&self, id: Id) -> Result<(), AppError>;
23}
24
25pub fn setup() {
26    println!("ferrox-database-core initialized: Provides Repository traits.");
27}