Fix compatibility with SQlite

Also fixes a bug in plume-models
This commit is contained in:
Bat 2018-10-06 12:35:58 +01:00
parent 5fa7a2a742
commit 4d382d8014
5 changed files with 16 additions and 12 deletions

View File

@ -18,3 +18,7 @@ version = "*"
[dependencies.plume-models] [dependencies.plume-models]
path = "../plume-models" path = "../plume-models"
[features]
postgres = ["plume-models/postgres"]
sqlite = ["plume-models/sqlite"]

View File

@ -1,8 +1,8 @@
use clap::{Arg, ArgMatches, App, SubCommand}; use clap::{Arg, ArgMatches, App, SubCommand};
use diesel::PgConnection;
use std::env; use std::env;
use plume_models::{ use plume_models::{
Connection,
instance::*, instance::*,
safe_string::SafeString, safe_string::SafeString,
}; };
@ -33,7 +33,7 @@ pub fn command<'a, 'b>() -> App<'a, 'b> {
).about("Create a new local instance")) ).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; let conn = conn;
match args.subcommand() { match args.subcommand() {
("new", Some(x)) => new(x, conn), ("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) let domain = args.value_of("domain").map(String::from)
.unwrap_or_else(|| env::var("BASE_URL") .unwrap_or_else(|| env::var("BASE_URL")
.unwrap_or_else(|_| super::ask_for("Domain name"))); .unwrap_or_else(|_| super::ask_for("Domain name")));

View File

@ -5,9 +5,9 @@ extern crate plume_models;
extern crate rpassword; extern crate rpassword;
use clap::App; use clap::App;
use diesel::{Connection, PgConnection}; use diesel::Connection;
use std::io::{self, prelude::*}; use std::io::{self, prelude::*};
use plume_models::DB_URL; use plume_models::{DB_URL, Connection as Conn};
mod instance; mod instance;
mod users; mod users;
@ -22,7 +22,7 @@ fn main() {
let matches = app.clone().get_matches(); let matches = app.clone().get_matches();
dotenv::dotenv().ok(); dotenv::dotenv().ok();
let conn = PgConnection::establish(DB_URL.as_str()); let conn = Conn::establish(DB_URL.as_str());
match matches.subcommand() { match matches.subcommand() {
("instance", Some(args)) => instance::run(args, &conn.expect("Couldn't connect to the database.")), ("instance", Some(args)) => instance::run(args, &conn.expect("Couldn't connect to the database.")),

View File

@ -1,9 +1,9 @@
use clap::{Arg, ArgMatches, App, SubCommand}; use clap::{Arg, ArgMatches, App, SubCommand};
use diesel::PgConnection;
use rpassword; use rpassword;
use std::io::{self, Write}; use std::io::{self, Write};
use plume_models::{ use plume_models::{
Connection,
users::*, users::*,
}; };
@ -45,7 +45,7 @@ pub fn command<'a, 'b>() -> App<'a, 'b> {
).about("Create a new user on this instance")) ).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; let conn = conn;
match args.subcommand() { match args.subcommand() {
("new", Some(x)) => new(x, conn), ("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 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 display_name = args.value_of("display-name").map(String::from).unwrap_or_else(|| super::ask_for("Display name"));
let admin = args.is_present("admin"); let admin = args.is_present("admin");

View File

@ -38,7 +38,7 @@ use diesel::r2d2::ConnectionManager;
use rocket::State; use rocket::State;
use rocket_contrib::Template; use rocket_contrib::Template;
use rocket_csrf::CsrfFairingBuilder; 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}; use workerpool::{Pool, thunk::ThunkWorker};
mod api; mod api;
@ -48,11 +48,11 @@ mod routes;
type Worker<'a> = State<'a, Pool<ThunkWorker<()>>>; type Worker<'a> = State<'a, Pool<ThunkWorker<()>>>;
/// Initializes a database pool. /// Initializes a database pool.
fn init_pool() -> Option<PgPool> { fn init_pool() -> Option<DbPool> {
dotenv::dotenv().ok(); dotenv::dotenv().ok();
let manager = ConnectionManager::<Connection>::new(DB_URL.as_str()); let manager = ConnectionManager::<Connection>::new(DB_URL.as_str());
PgPool::new(manager).ok() DbPool::new(manager).ok()
} }
fn main() { fn main() {