From 4d382d80142dba9e844b0b85caa84339f44ee09b Mon Sep 17 00:00:00 2001 From: Bat Date: Sat, 6 Oct 2018 12:35:58 +0100 Subject: [PATCH] Fix compatibility with SQlite Also fixes a bug in plume-models --- plume-cli/Cargo.toml | 4 ++++ plume-cli/src/instance.rs | 6 +++--- plume-cli/src/main.rs | 6 +++--- plume-cli/src/users.rs | 6 +++--- src/main.rs | 6 +++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/plume-cli/Cargo.toml b/plume-cli/Cargo.toml index 3a96ce4..d203a43 100644 --- a/plume-cli/Cargo.toml +++ b/plume-cli/Cargo.toml @@ -18,3 +18,7 @@ version = "*" [dependencies.plume-models] path = "../plume-models" + +[features] +postgres = ["plume-models/postgres"] +sqlite = ["plume-models/sqlite"] diff --git a/plume-cli/src/instance.rs b/plume-cli/src/instance.rs index bc6c1b5..80aea30 100644 --- a/plume-cli/src/instance.rs +++ b/plume-cli/src/instance.rs @@ -1,8 +1,8 @@ use clap::{Arg, ArgMatches, App, SubCommand}; -use diesel::PgConnection; use std::env; use plume_models::{ + Connection, instance::*, safe_string::SafeString, }; @@ -33,7 +33,7 @@ pub fn command<'a, 'b>() -> App<'a, 'b> { ).about("Create a new local instance")) } -pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { +pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) { let conn = conn; match args.subcommand() { ("new", Some(x)) => new(x, conn), @@ -41,7 +41,7 @@ pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { } } -fn new<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { +fn new<'a>(args: &ArgMatches<'a>, conn: &Connection) { let domain = args.value_of("domain").map(String::from) .unwrap_or_else(|| env::var("BASE_URL") .unwrap_or_else(|_| super::ask_for("Domain name"))); diff --git a/plume-cli/src/main.rs b/plume-cli/src/main.rs index be012fc..557e58b 100644 --- a/plume-cli/src/main.rs +++ b/plume-cli/src/main.rs @@ -5,9 +5,9 @@ extern crate plume_models; extern crate rpassword; use clap::App; -use diesel::{Connection, PgConnection}; +use diesel::Connection; use std::io::{self, prelude::*}; -use plume_models::DB_URL; +use plume_models::{DB_URL, Connection as Conn}; mod instance; mod users; @@ -22,7 +22,7 @@ fn main() { let matches = app.clone().get_matches(); dotenv::dotenv().ok(); - let conn = PgConnection::establish(DB_URL.as_str()); + let conn = Conn::establish(DB_URL.as_str()); match matches.subcommand() { ("instance", Some(args)) => instance::run(args, &conn.expect("Couldn't connect to the database.")), diff --git a/plume-cli/src/users.rs b/plume-cli/src/users.rs index b3bcee1..a00f857 100644 --- a/plume-cli/src/users.rs +++ b/plume-cli/src/users.rs @@ -1,9 +1,9 @@ use clap::{Arg, ArgMatches, App, SubCommand}; -use diesel::PgConnection; use rpassword; use std::io::{self, Write}; use plume_models::{ + Connection, users::*, }; @@ -45,7 +45,7 @@ pub fn command<'a, 'b>() -> App<'a, 'b> { ).about("Create a new user on this instance")) } -pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { +pub fn run<'a>(args: &ArgMatches<'a>, conn: &Connection) { let conn = conn; match args.subcommand() { ("new", Some(x)) => new(x, conn), @@ -53,7 +53,7 @@ pub fn run<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { } } -fn new<'a>(args: &ArgMatches<'a>, conn: &PgConnection) { +fn new<'a>(args: &ArgMatches<'a>, conn: &Connection) { let username = args.value_of("name").map(String::from).unwrap_or_else(|| super::ask_for("Username")); let display_name = args.value_of("display-name").map(String::from).unwrap_or_else(|| super::ask_for("Display name")); let admin = args.is_present("admin"); diff --git a/src/main.rs b/src/main.rs index 3296152..802b7cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,7 @@ use diesel::r2d2::ConnectionManager; use rocket::State; use rocket_contrib::Template; use rocket_csrf::CsrfFairingBuilder; -use plume_models::{DB_URL, Connection, db_conn::PgPool}; +use plume_models::{DB_URL, Connection, db_conn::DbPool}; use workerpool::{Pool, thunk::ThunkWorker}; mod api; @@ -48,11 +48,11 @@ mod routes; type Worker<'a> = State<'a, Pool>>; /// Initializes a database pool. -fn init_pool() -> Option { +fn init_pool() -> Option { dotenv::dotenv().ok(); let manager = ConnectionManager::::new(DB_URL.as_str()); - PgPool::new(manager).ok() + DbPool::new(manager).ok() } fn main() {