Diesel and XDG yak-shaving.
This commit is contained in:
parent
44eb261b95
commit
600415ff5d
@ -18,5 +18,6 @@ pub fn run() -> Result<()> {
|
|||||||
let foo = args;
|
let foo = args;
|
||||||
info!("{:?}", foo);
|
info!("{:?}", foo);
|
||||||
|
|
||||||
|
::init()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
49
src/lib.rs
49
src/lib.rs
@ -3,18 +3,24 @@
|
|||||||
extern crate structopt;
|
extern crate structopt;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate structopt_derive;
|
extern crate structopt_derive;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate loggerv;
|
extern crate loggerv;
|
||||||
extern crate reqwest;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate diesel_codegen;
|
||||||
|
|
||||||
// use diesel::prelude::*;
|
extern crate xdg;
|
||||||
|
extern crate reqwest;
|
||||||
|
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
@ -24,16 +30,55 @@ pub mod errors {
|
|||||||
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use diesel::migrations::RunMigrationsError;
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
foreign_links {
|
foreign_links {
|
||||||
ReqError(reqwest::Error);
|
ReqError(reqwest::Error);
|
||||||
IoError(io::Error);
|
IoError(io::Error);
|
||||||
Log(::log::SetLoggerError);
|
Log(::log::SetLoggerError);
|
||||||
|
MigrationError(RunMigrationsError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use errors::*;
|
||||||
|
use diesel::prelude::*;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
embed_migrations!("migrations/");
|
||||||
|
|
||||||
|
lazy_static!{
|
||||||
|
|
||||||
|
static ref HAMMOND_XDG: xdg::BaseDirectories = {
|
||||||
|
xdg::BaseDirectories::with_prefix("Hammond").unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
|
static ref HAMMOND_DATA: PathBuf = HAMMOND_XDG.create_data_directory(HAMMOND_XDG.get_data_home()).unwrap();
|
||||||
|
static ref HAMMOND_CONFIG: PathBuf = HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap();
|
||||||
|
static ref HAMMOND_CACHE: PathBuf = HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap();
|
||||||
|
|
||||||
|
static ref DB_PATH: std::path::PathBuf = HAMMOND_XDG.place_data_file("hammond.db").unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init() -> Result<()> {
|
||||||
|
&HAMMOND_DATA;
|
||||||
|
let conn = establish_connection();
|
||||||
|
// embedded_migrations::run(&conn)?;
|
||||||
|
embedded_migrations::run_with_output(&conn, &mut std::io::stdout())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn establish_connection() -> SqliteConnection {
|
||||||
|
let database_url = DB_PATH.to_str().unwrap();
|
||||||
|
// let database_url = &String::from(".random/foo.db");
|
||||||
|
SqliteConnection::establish(database_url).expect(&format!(
|
||||||
|
"Error connecting to {}",
|
||||||
|
database_url
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user