jacob-pro / diesel-repository

(Experimental) An attempt at using the repository pattern with Diesel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Diesel Repository

Build status maintenance-status

An experimental attempt at using the repository pattern with Diesel.

Example

#[derive(Debug, Queryable, Identifiable, AsChangeset)]
pub struct User {
    pub id: i32,
    pub name: String,
    pub email: String,
}

// UserRepositoryImpl = Generated struct name
// User               = The Entity type
// i32                = The Key type
// PgConnection       = The database connection type
implement_crud_repository!(UserRepositoryImpl, User, i32, PgConnection);

fn your_function(conn: &PgConnection) {
    let repository = UserRepositoryImpl::new(&conn);
    let user: Option<User> = repository.find_by_id(5).expect("Database error");
}

About

(Experimental) An attempt at using the repository pattern with Diesel

License:GNU Lesser General Public License v2.1


Languages

Language:Rust 100.0%