Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Last active September 13, 2020 22:25
Show Gist options
  • Select an option

  • Save jayhuang75/a7251c9bfb7746c75e3d3a54d4da37ff to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/a7251c9bfb7746c75e3d3a54d4da37ff to your computer and use it in GitHub Desktop.
rust sqlite implementation
pub struct DbContext<'a> {
pub conn: &'a SqliteConnection,
}
impl<'a> DbContext<'a> {
pub fn new(conn: &'a SqliteConnection) -> Self {
return DbContext { conn };
}
pub fn count(&mut self) -> Result<i64, Error> {
let app_count: i64 = apps.count().get_result(self.conn)?;
Ok(app_count)
}
pub fn insert(&mut self, item: &NewApp) -> Result<(), Error> {
diesel::insert_into(apps).values(item).execute(self.conn)?;
Ok(())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment