refactor: update examples to remove preludes

This commit is contained in:
Ryan Leckey 2021-01-20 19:41:45 -08:00
parent a0ce421989
commit 02524b24c1
No known key found for this signature in database
GPG Key ID: F8AA68C235AB08C9
9 changed files with 1490 additions and 52 deletions

83
Cargo.lock generated
View File

@ -22,9 +22,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.37"
version = "1.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86"
checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1"
[[package]]
name = "async-channel"
@ -65,12 +65,15 @@ dependencies = [
[[package]]
name = "async-global-executor"
version = "1.4.3"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73079b49cd26b8fd5a15f68fc7707fc78698dc2a3d61430f2a7a9430230dfa04"
checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6"
dependencies = [
"async-channel",
"async-executor",
"async-io",
"async-mutex",
"blocking",
"futures-lite",
"num_cpus",
"once_cell",
@ -96,6 +99,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "async-lock"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1996609732bde4a9988bc42125f55f2af5f3c36370e27c778d5191a4a1b63bfb"
dependencies = [
"event-listener",
]
[[package]]
name = "async-mutex"
version = "1.4.0"
@ -107,15 +119,14 @@ dependencies = [
[[package]]
name = "async-std"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9f84f1280a2b436a2c77c2582602732b6c2f4321d5494d6e799e6c367859a8"
checksum = "d9f06685bad74e0570f5213741bea82158279a4103d988e57bfada11ad230341"
dependencies = [
"async-channel",
"async-global-executor",
"async-io",
"async-mutex",
"blocking",
"async-lock",
"crossbeam-utils",
"futures-channel",
"futures-core",
@ -206,9 +217,9 @@ checksum = "ae44d1a3d5a19df61dd0c8beb138458ac2a53a7ac09eba97d55592540004306b"
[[package]]
name = "bytes"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72"
checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040"
[[package]]
name = "bytestring"
@ -404,24 +415,24 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f01c61843314e95f96cc9245702248733a3a3d744e43e2e755e3c7af8348a0a9"
checksum = "f2d31b7ec7efab6eefc7c57233bb10b847986139d88cc2f5a02a1ae6871a1846"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8d3b0917ff63a2a96173133c02818fac4a746b0a57569d3baca9ec0e945e08"
checksum = "79e5145dde8da7d1b3892dad07a9c98fc04bc39892b1ecc9692cf53e2b780a65"
[[package]]
name = "futures-executor"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ee9ca2f7eb4475772cf39dd1cd06208dce2670ad38f4d9c7262b3e15f127068"
checksum = "e9e59fdc009a4b3096bf94f740a0f2424c082521f20a9b08c5c07c48d90fd9b9"
dependencies = [
"futures-core",
"futures-task",
@ -430,9 +441,9 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e37c1a51b037b80922864b8eed90692c5cd8abd4c71ce49b77146caa47f3253b"
checksum = "28be053525281ad8259d47e4de5de657b25e7bac113458555bb4b70bc6870500"
[[package]]
name = "futures-lite"
@ -451,9 +462,9 @@ dependencies = [
[[package]]
name = "futures-macro"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f8719ca0e1f3c5e34f3efe4570ef2c0610ca6da85ae7990d472e9cbfba13664"
checksum = "c287d25add322d9f9abdcdc5927ca398917996600182178774032e9f8258fedd"
dependencies = [
"proc-macro-hack",
"proc-macro2",
@ -463,18 +474,18 @@ dependencies = [
[[package]]
name = "futures-task"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92a0843a2ff66823a8f7c77bffe9a09be2b64e533562c412d63075643ec0038"
checksum = "13de07eb8ea81ae445aca7b69f5f7bf15d7bf4912d8ca37d6645c77ae8a58d86"
dependencies = [
"once_cell",
]
[[package]]
name = "futures-util"
version = "0.3.9"
version = "0.3.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "036a2107cdeb57f6d7322f1b6c363dad67cd63ca3b7d1b925bdf75bd5d96cda9"
checksum = "632a8cd0f2a4b3fdea1657f08bde063848c3bd00f9bbf6e256b8be78802e624b"
dependencies = [
"futures-core",
"futures-io",
@ -524,9 +535,9 @@ dependencies = [
[[package]]
name = "hermit-abi"
version = "0.1.17"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
dependencies = [
"libc",
]
@ -601,9 +612,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.11"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b"
checksum = "fcf3805d4480bb5b86070dcfeb9e2cb2ebc148adb753c5cca5f884d1d65a42b2"
dependencies = [
"cfg-if 0.1.10",
]
@ -803,9 +814,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project-lite"
version = "0.2.3"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba36e0a6cc5a4c645073f4984f1ed55d09f5857d4de7c14550baa81a39ef5a17"
checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827"
[[package]]
name = "pin-utils"
@ -840,9 +851,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro-nested"
version = "0.1.6"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a"
checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086"
[[package]]
name = "proc-macro2"
@ -954,9 +965,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.118"
version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab"
[[package]]
name = "sha-1"
@ -1164,9 +1175,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd"
checksum = "0ca04cec6ff2474c638057b65798f60ac183e5e79d3448bb7163d36a39cff6ec"
dependencies = [
"autocfg 1.0.1",
"bytes",

1391
examples/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

6
examples/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[workspace]
members = [
"quickstart/mysql+blocking",
"quickstart/mysql+async-std",
"quickstart/mysql+tokio"
]

View File

@ -12,4 +12,4 @@ 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"] }
sqlx = { path = "../../../sqlx", features = [ "async-std", "mysql-async" ] }

View File

@ -1,18 +1,28 @@
use sqlx::mysql::{MySqlConnectOptions, MySqlConnection};
use sqlx::prelude::*;
#[async_std::main]
async fn main() -> anyhow::Result<()> {
env_logger::try_init()?;
// parse the connection URL
// start by parsing the connection URL (typically from an environment variable)
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 to the database (blocking)
.connect()
.await?;
// the following are equivalent to the above:
// let mut conn = MySqlConnection::<AsyncStd>::connect("mysql://root:password@localhost").await?;
// let mut conn = <MySqlConnection>::connect("mysql://root:password@localhost").await?;
// let mut conn = MySqlConnectOptions::<AsyncStd>::new().username("root").password("password").connect().await?;
// let mut conn = <MySqlConnectOptions>::new().username("root").password("password").connect().await?;
// the <...> syntax is an escape into the type syntax
// when writing a *type*, Rust allows default type parameters
// as opposed to writing a *path* where it does not (yet)
// ping, this makes sure the server is still there
// hopefully it is we did just connect to it
conn.ping().await?;

View File

@ -9,6 +9,6 @@ authors = [
[dependencies]
anyhow = "1.0.36"
log = "0.4"
env_logger = "0.8.2"
sqlx = { path = "../../../sqlx", features = [ "blocking", "mysql"] }
log = "0.4"
sqlx = { path = "../../../sqlx", features = [ "blocking", "mysql-blocking" ] }

View File

@ -1,18 +1,28 @@
use sqlx::mysql::{MySqlConnectOptions, MySqlConnection};
use sqlx::prelude::*;
fn main() -> anyhow::Result<()> {
env_logger::try_init()?;
// parse the connection URL
// start by parsing the connection URL (typically from an environment variable)
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()?;
// the following are equivalent to the above:
// let mut conn = MySqlConnection::<Blocking>::connect("mysql://root:password@localhost")?;
// let mut conn = <MySqlConnection>::connect("mysql://root:password@localhost")?;
// let mut conn = MySqlConnectOptions::<Blocking>::new().username("root").password("password").connect()?;
// let mut conn = <MySqlConnectOptions>::new().username("root").password("password").connect()?;
// the <...> syntax is an escape into the type syntax
// when writing a *type*, Rust allows default type parameters
// as opposed to writing a *path* where it does not (yet)
// ping, this makes sure the server is still there
// hopefully it is we did just connect to it
// hopefully it is - we did just connect to it
conn.ping()?;
// close the connection explicitly

View File

@ -9,7 +9,7 @@ authors = [
[dependencies]
anyhow = "1.0.36"
tokio = { version = "1", features = ["full"] }
log = "0.4"
env_logger = "0.8.2"
sqlx = { path = "../../../sqlx", features = [ "tokio", "mysql"] }
log = "0.4"
sqlx = { path = "../../../sqlx", features = [ "tokio", "mysql-async" ] }
tokio = { version = "1", features = [ "full" ] }

View File

@ -1,20 +1,30 @@
use sqlx::mysql::{MySqlConnectOptions, MySqlConnection};
use sqlx::prelude::*;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::try_init()?;
// parse the connection URL
// start by parsing the connection URL (typically from an environment variable)
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 to the database (blocking)
.connect()
.await?;
// the following are equivalent to the above:
// let mut conn = MySqlConnection::<Tokio>::connect("mysql://root:password@localhost").await?;
// let mut conn = <MySqlConnection>::connect("mysql://root:password@localhost").await?;
// let mut conn = MySqlConnectOptions::<Tokio>::new().username("root").password("password").connect().await?;
// let mut conn = <MySqlConnectOptions>::new().username("root").password("password").connect().await?;
// the <...> syntax is an escape into the type syntax
// when writing a *type*, Rust allows default type parameters
// as opposed to writing a *path* where it does not (yet)
// ping, this makes sure the server is still there
// hopefully it is we did just connect to it
// hopefully it is - we did just connect to it
conn.ping().await?;
// close the connection explicitly