Last active
July 3, 2018 11:32
-
-
Save CjS77/840a4bc1aa0493232f34f0406c9b3cd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait Commitable<Class=Self:Insertable> { | |
type Committed:Queryable, table; | |
pub fn commit(&self, conn: PgConnection) -> Result<Committed,DatabaseError> { | |
DatabaseError::wrap(diesel::insert_into(table).values(self).get_result(conn)) | |
} | |
} | |
#[derive(Queryable)] | |
struct Artist {..} | |
#[derive(Insertable, Commitable)] | |
struct NewArtist {...} | |
// commit is automatically created | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment