diff --git a/Cargo.lock b/Cargo.lock index ce8acb6e..642a234d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1115,17 +1115,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "sqlx-example-quickstart" -version = "0.0.0" -dependencies = [ - "anyhow", - "async-std", - "env_logger", - "log", - "sqlx", -] - [[package]] name = "sqlx-mysql" version = "0.6.0-pre" @@ -1150,6 +1139,38 @@ dependencies = [ "url", ] +[[package]] +name = "sqlx_example_quickstart_mysql_async-std" +version = "0.0.0" +dependencies = [ + "anyhow", + "async-std", + "env_logger", + "log", + "sqlx", +] + +[[package]] +name = "sqlx_example_quickstart_mysql_blocking" +version = "0.0.0" +dependencies = [ + "anyhow", + "env_logger", + "log", + "sqlx", +] + +[[package]] +name = "sqlx_example_quickstart_mysql_tokio" +version = "0.0.0" +dependencies = [ + "anyhow", + "env_logger", + "log", + "sqlx", + "tokio", +] + [[package]] name = "subtle" version = "2.4.0" @@ -1250,15 +1271,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd" dependencies = [ "autocfg 1.0.1", + "bytes", "libc", + "memchr", "mio", + "num_cpus", "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", + "tokio-macros", "winapi", ] +[[package]] +name = "tokio-macros" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42517d2975ca3114b22a16192634e8241dc5cc1f130be194645970cc1c371494" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "typenum" version = "1.12.0" diff --git a/Cargo.toml b/Cargo.toml index a084688a..11c8d32c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,9 @@ members = [ "sqlx-core", "sqlx-mysql", "sqlx", - "examples/quickstart" + + # examples + "examples/quickstart/mysql+blocking", + "examples/quickstart/mysql+async-std", + "examples/quickstart/mysql+tokio" ] diff --git a/examples/quickstart/Cargo.toml b/examples/quickstart/Cargo.toml deleted file mode 100644 index 0d282eea..00000000 --- a/examples/quickstart/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "sqlx-example-quickstart" -version = "0.0.0" -license = "MIT OR Apache-2.0" -edition = "2018" -authors = [ - "LaunchBadge " -] - -[dependencies] -#actix-web = "3.3.2" -anyhow = "1.0.36" -#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", "tokio", "mysql"] } diff --git a/examples/quickstart/mysql+async-std/Cargo.toml b/examples/quickstart/mysql+async-std/Cargo.toml new file mode 100644 index 00000000..31b95cad --- /dev/null +++ b/examples/quickstart/mysql+async-std/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "sqlx_example_quickstart_mysql_async-std" +version = "0.0.0" +license = "MIT OR Apache-2.0" +edition = "2018" +authors = [ + "LaunchBadge " +] + +[dependencies] +anyhow = "1.0.36" +async-std = { version = "1.8.0", features = ["attributes"] } +log = "0.4" +env_logger = "0.8.2" +sqlx = { path = "../../../sqlx", features = [ "async-std", "mysql"] } diff --git a/examples/quickstart/mysql+async-std/src/main.rs b/examples/quickstart/mysql+async-std/src/main.rs new file mode 100644 index 00000000..d1369fa5 --- /dev/null +++ b/examples/quickstart/mysql+async-std/src/main.rs @@ -0,0 +1,26 @@ +use sqlx::mysql::{MySqlConnectOptions, MySqlConnection}; +use sqlx::prelude::*; + +#[async_std::main] +async fn main() -> anyhow::Result<()> { + env_logger::try_init()?; + + // parse the connection URL + let mut conn: MySqlConnection = MySqlConnectOptions::parse("mysql://root@localhost")? + // set a password (perhaps from somewhere else than the rest of the URL) + .password("password") + // connect to the database (asynchronously) + .connect() + .await?; + + // ping, this makes sure the server is still there + // hopefully it is – we did just connect to it + conn.ping().await?; + + // close the connection explicitly + // this kindly informs the database server that we'll be terminating + // while not strictly required, the server will dispose of connection resources faster + conn.close().await?; + + Ok(()) +} diff --git a/examples/quickstart/mysql+blocking/Cargo.toml b/examples/quickstart/mysql+blocking/Cargo.toml new file mode 100644 index 00000000..e7706a44 --- /dev/null +++ b/examples/quickstart/mysql+blocking/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "sqlx_example_quickstart_mysql_blocking" +version = "0.0.0" +license = "MIT OR Apache-2.0" +edition = "2018" +authors = [ + "LaunchBadge " +] + +[dependencies] +anyhow = "1.0.36" +log = "0.4" +env_logger = "0.8.2" +sqlx = { path = "../../../sqlx", features = [ "blocking", "mysql"] } diff --git a/examples/quickstart/mysql+blocking/src/main.rs b/examples/quickstart/mysql+blocking/src/main.rs new file mode 100644 index 00000000..2999c684 --- /dev/null +++ b/examples/quickstart/mysql+blocking/src/main.rs @@ -0,0 +1,24 @@ +use sqlx::mysql::{MySqlConnectOptions, MySqlConnection}; +use sqlx::prelude::*; + +fn main() -> anyhow::Result<()> { + env_logger::try_init()?; + + // parse the connection URL + let mut conn: MySqlConnection = MySqlConnectOptions::parse("mysql://root@localhost")? + // set a password (perhaps from somewhere else than the rest of the URL) + .password("password") + // connect to the database (blocking) + .connect()?; + + // ping, this makes sure the server is still there + // hopefully it is – we did just connect to it + conn.ping()?; + + // close the connection explicitly + // this kindly informs the database server that we'll be terminating + // while not strictly required, the server will dispose of connection resources faster + conn.close()?; + + Ok(()) +} diff --git a/examples/quickstart/mysql+tokio/Cargo.toml b/examples/quickstart/mysql+tokio/Cargo.toml new file mode 100644 index 00000000..59cf6674 --- /dev/null +++ b/examples/quickstart/mysql+tokio/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "sqlx_example_quickstart_mysql_tokio" +version = "0.0.0" +license = "MIT OR Apache-2.0" +edition = "2018" +authors = [ + "LaunchBadge " +] + +[dependencies] +anyhow = "1.0.36" +tokio = { version = "1", features = ["full"] } +log = "0.4" +env_logger = "0.8.2" +sqlx = { path = "../../../sqlx", features = [ "tokio", "mysql"] } diff --git a/examples/quickstart/mysql+tokio/src/main.rs b/examples/quickstart/mysql+tokio/src/main.rs new file mode 100644 index 00000000..05c727ed --- /dev/null +++ b/examples/quickstart/mysql+tokio/src/main.rs @@ -0,0 +1,26 @@ +use sqlx::mysql::{MySqlConnectOptions, MySqlConnection}; +use sqlx::prelude::*; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + env_logger::try_init()?; + + // parse the connection URL + let mut conn: MySqlConnection = MySqlConnectOptions::parse("mysql://root@localhost")? + // set a password (perhaps from somewhere else than the rest of the URL) + .password("password") + // connect to the database (asynchronously) + .connect() + .await?; + + // ping, this makes sure the server is still there + // hopefully it is – we did just connect to it + conn.ping().await?; + + // close the connection explicitly + // this kindly informs the database server that we'll be terminating + // while not strictly required, the server will dispose of connection resources faster + conn.close().await?; + + Ok(()) +} diff --git a/examples/quickstart/src/main.rs b/examples/quickstart/src/main.rs deleted file mode 100644 index dc5a6fcb..00000000 --- a/examples/quickstart/src/main.rs +++ /dev/null @@ -1,30 +0,0 @@ -// use sqlx::prelude::*; -use sqlx::blocking::{prelude::*, Blocking}; -use sqlx::mysql::MySqlConnection; - -// #[tokio::main] -// async fn main() -> anyhow::Result<()> { -// env_logger::try_init()?; -// -// // connect to the database -// let mut conn = ::connect("mysql://root:password@localhost").await?; -// -// // ping, say HAI -// conn.ping().await?; -// -// // , and now close the connection explicitly -// conn.close().await?; -// -// Ok(()) -// } - -fn main() -> anyhow::Result<()> { - env_logger::try_init()?; - - let mut conn = >::connect("mysql://root:password@localhost")?; - - conn.ping()?; - conn.close()?; - - Ok(()) -}