Skip to content

Instantly share code, notes, and snippets.

@CjS77
Last active July 3, 2018 11:32
Show Gist options
  • Save CjS77/840a4bc1aa0493232f34f0406c9b3cd0 to your computer and use it in GitHub Desktop.
Save CjS77/840a4bc1aa0493232f34f0406c9b3cd0 to your computer and use it in GitHub Desktop.
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