From 685b47247aad71468f190c42929ca6f0dce843fa Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Wed, 16 Jun 2021 12:36:47 -0600 Subject: make database backends generic --- src/cli/migrate.rs | 19 +++++++++++++++++++ src/cli/mod.rs | 9 ++++++--- src/cli/run_server.rs | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 src/cli/migrate.rs (limited to 'src/cli') diff --git a/src/cli/migrate.rs b/src/cli/migrate.rs new file mode 100644 index 0000000..4b5123a --- /dev/null +++ b/src/cli/migrate.rs @@ -0,0 +1,19 @@ +use structopt::StructOpt; + +use crate::{Settings, UrlMap, db::backend::{Connectable, Connection}}; + +#[derive(StructOpt)] +/// Perform database migrations +pub struct Migrate { +} + +impl Migrate { + pub fn execute(self, _urls: UrlMap, settings: Settings) { + let database = settings.database; + let connection = database.connect().unwrap(); + + let migration_table_vibe_check = connection.transaction::<(), diesel::result::Error, _>(|| { + todo!() + }); + } +} diff --git a/src/cli/mod.rs b/src/cli/mod.rs index c656c1c..a11fd48 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -1,23 +1,26 @@ use structopt::StructOpt; -use crate::{Settings, UrlMap}; +use crate::{Settings, UrlMap, db::backend::Connectable}; +mod migrate; mod run_server; #[derive(StructOpt)] enum Command { + Migrate(migrate::Migrate), RunServer(run_server::RunServer), } impl Command { - fn execute(self, urls: UrlMap, settings: Settings) { + fn execute(self, urls: UrlMap, settings: Settings) { match self { + Command::Migrate(command) => command.execute(urls, settings), Command::RunServer(command) => command.execute(urls, settings), } } } -pub fn main(urls: UrlMap, settings: Settings) { +pub fn main(urls: UrlMap, settings: Settings) { let command = Command::from_args(); command.execute(urls, settings); } diff --git a/src/cli/run_server.rs b/src/cli/run_server.rs index 242c824..66e6fe1 100644 --- a/src/cli/run_server.rs +++ b/src/cli/run_server.rs @@ -1,6 +1,6 @@ use structopt::StructOpt; -use crate::{Settings, UrlMap}; +use crate::{Settings, UrlMap, db::backend::Connectable}; #[derive(StructOpt)] /// Run an HTTP server @@ -11,7 +11,7 @@ pub struct RunServer { } impl RunServer { - pub fn execute(self, urls: UrlMap, _settings: Settings) { + pub fn execute(self, urls: UrlMap, _settings: Settings) { println!("Starting server at http://127.0.0.1:{}/", self.port); let server_task = warp::serve(urls).run(([127, 0, 0, 1], self.port)); -- cgit v1.2.3