diff options
| author | Jokler <jokler.contact@gmail.com> | 2018-02-25 18:54:16 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2018-02-25 18:54:16 +0100 |
| commit | 92668ad4c53edcc1a317a16aa5ea30ca502f54ee (patch) | |
| tree | 4a93dad53b06f2b4dccfaf0282e8e9ee94b3a070 /src/plugins/factoids/database.rs | |
| parent | 76461addd2fb7ec383123b1efc4368b7662eea04 (diff) | |
| download | frippy-92668ad4c53edcc1a317a16aa5ea30ca502f54ee.tar.gz frippy-92668ad4c53edcc1a317a16aa5ea30ca502f54ee.zip | |
Add Mysql as a possible database to the Tell plugin
Diffstat (limited to 'src/plugins/factoids/database.rs')
| -rw-r--r-- | src/plugins/factoids/database.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/plugins/factoids/database.rs b/src/plugins/factoids/database.rs index 386d3f7..88aa0fd 100644 --- a/src/plugins/factoids/database.rs +++ b/src/plugins/factoids/database.rs @@ -1,6 +1,8 @@ #[cfg(feature = "mysql")] extern crate dotenv; +#[cfg(feature = "mysql")] +use std::sync::Arc; use std::collections::HashMap; #[cfg(feature = "mysql")] @@ -29,8 +31,6 @@ pub struct Factoid { pub created: NaiveDateTime, } -#[cfg(feature = "mysql")] -use self::mysql::factoids; #[cfg_attr(feature = "mysql", derive(Insertable))] #[cfg_attr(feature = "mysql", table_name = "factoids")] pub struct NewFactoid<'a> { @@ -82,10 +82,10 @@ impl Database for HashMap<(String, i32), Factoid> { } } -// Diesel automatically define the factoids module as public. -// For now this is how we keep it private. +// Diesel automatically defines the factoids module as public. +// We create a schema module to keep it private. #[cfg(feature = "mysql")] -mod mysql { +mod schema { table! { factoids (name, idx) { name -> Varchar, @@ -98,7 +98,10 @@ mod mysql { } #[cfg(feature = "mysql")] -impl Database for Pool<ConnectionManager<MysqlConnection>> { +use self::schema::factoids; + +#[cfg(feature = "mysql")] +impl Database for Arc<Pool<ConnectionManager<MysqlConnection>>> { fn insert_factoid(&mut self, factoid: &NewFactoid) -> DbResponse { use diesel; |
