From d8ed9fd25a29893f36f8f67cc26bb3d9dbfb4a6d Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sun, 31 Jan 2021 13:39:00 +0300 Subject: [PATCH] feat(core): add database utils --- migra-core/Cargo.toml | 3 +-- migra-core/src/database.rs | 9 +++++++++ migra-core/src/lib.rs | 10 +++------- 3 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 migra-core/src/database.rs diff --git a/migra-core/Cargo.toml b/migra-core/Cargo.toml index dae38ab..465e9f8 100644 --- a/migra-core/Cargo.toml +++ b/migra-core/Cargo.toml @@ -4,6 +4,5 @@ version = "0.1.0" authors = ["Dmitriy Pleshevskiy "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] +postgres = "0.19.0" diff --git a/migra-core/src/database.rs b/migra-core/src/database.rs new file mode 100644 index 0000000..2971b39 --- /dev/null +++ b/migra-core/src/database.rs @@ -0,0 +1,9 @@ +use postgres::{Client, NoTls, Error}; + +pub fn connect(connection_string: &str) -> Result { + Client::connect(connection_string, NoTls) +} + +pub fn apply_sql(client: &mut Client, sql_content: &str) -> Result<(), Error> { + client.batch_execute(sql_content) +} diff --git a/migra-core/src/lib.rs b/migra-core/src/lib.rs index 31e1bb2..d37e273 100644 --- a/migra-core/src/lib.rs +++ b/migra-core/src/lib.rs @@ -1,7 +1,3 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} +#![deny(clippy::all)] + +pub mod database;