refactor: split <Connection> into <Connect>, <Close>, <Acquire>, and <Connection>

This commit is contained in:
Ryan Leckey
2021-01-09 16:37:36 -08:00
parent e0e5b76f79
commit d2b31950cf
17 changed files with 250 additions and 1040 deletions

View File

@@ -8,11 +8,11 @@ authors = [
]
[dependencies]
actix-web = "3.3.2"
#actix-web = "3.3.2"
anyhow = "1.0.36"
async-std = { version = "1.8.0", features = ["attributes"] }
#async-std = { version = "1.8.0", features = ["attributes"] }
tokio = { version = "1.0.1", features = ["rt", "rt-multi-thread", "macros"] }
log = "0.4"
env_logger = "0.8.2"
#sqlx = { path = "../../sqlx", features = ["tokio", "mysql"] }
sqlx = { path = "../../sqlx", features = ["blocking", "mysql"] }
sqlx = { path = "../../sqlx", features = ["blocking", "tokio", "mysql"] }

View File

@@ -1,11 +1,19 @@
// use sqlx::prelude::*;
use sqlx::blocking::{prelude::*, Blocking};
use sqlx::mysql::MySqlConnection;
use sqlx::prelude::*;
// #[tokio::main]
// async fn main() -> anyhow::Result<()> {
// env_logger::try_init()?;
//
// let _conn = <MySqlConnection>::connect("mysql://root:password@localhost").await?;
// // connect to the database
// let mut conn = <MySqlConnection>::connect("mysql://root:password@localhost").await?;
//
// // ping, say HAI
// conn.ping().await?;
//
// // , and now close the connection explicitly
// conn.close().await?;
//
// Ok(())
// }
@@ -13,7 +21,10 @@ use sqlx::prelude::*;
fn main() -> anyhow::Result<()> {
env_logger::try_init()?;
let _conn = <MySqlConnection>::connect("mysql://root:password@localhost")?;
let mut conn = <MySqlConnection<Blocking>>::connect("mysql://root:password@localhost")?;
conn.ping()?;
conn.close()?;
Ok(())
}