Last active
September 13, 2020 22:25
-
-
Save jayhuang75/a7251c9bfb7746c75e3d3a54d4da37ff to your computer and use it in GitHub Desktop.
rust sqlite implementation
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 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