From d2b31950cfcd6bc27c13abb9d7a85e6f015e2cc7 Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sat, 9 Jan 2021 16:37:36 -0800 Subject: [PATCH] refactor: split into , , , and --- Cargo.lock | 920 +-------------------------- examples/quickstart/Cargo.toml | 6 +- examples/quickstart/src/main.rs | 17 +- sqlx-core/src/acquire.rs | 46 ++ sqlx-core/src/blocking.rs | 9 + sqlx-core/src/blocking/acquire.rs | 28 + sqlx-core/src/blocking/close.rs | 12 + sqlx-core/src/blocking/connect.rs | 13 + sqlx-core/src/blocking/connection.rs | 25 +- sqlx-core/src/blocking/options.rs | 6 +- sqlx-core/src/close.rs | 12 + sqlx-core/src/connect.rs | 15 + sqlx-core/src/connection.rs | 59 +- sqlx-core/src/lib.rs | 15 +- sqlx-core/src/options.rs | 2 +- sqlx-core/src/pool.rs | 13 + sqlx-mysql/src/connection.rs | 92 ++- 17 files changed, 250 insertions(+), 1040 deletions(-) create mode 100644 sqlx-core/src/acquire.rs create mode 100644 sqlx-core/src/blocking/acquire.rs create mode 100644 sqlx-core/src/blocking/close.rs create mode 100644 sqlx-core/src/blocking/connect.rs create mode 100644 sqlx-core/src/close.rs create mode 100644 sqlx-core/src/connect.rs create mode 100644 sqlx-core/src/pool.rs diff --git a/Cargo.lock b/Cargo.lock index 58af64bd..4cd1e476 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,87 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "actix-codec" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78d1833b3838dbe990df0f1f87baf640cf6146e898166afe401839d1b001e570" -dependencies = [ - "bitflags", - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project 0.4.27", - "tokio 0.2.24", - "tokio-util", -] - -[[package]] -name = "actix-connect" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-utils", - "derive_more", - "either", - "futures-util", - "http", - "log", - "trust-dns-proto", - "trust-dns-resolver", -] - -[[package]] -name = "actix-http" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874" -dependencies = [ - "actix-codec", - "actix-connect", - "actix-rt", - "actix-service", - "actix-threadpool", - "actix-utils", - "base64", - "bitflags", - "brotli2", - "bytes 0.5.6", - "cookie", - "copyless", - "derive_more", - "either", - "encoding_rs", - "flate2", - "futures-channel", - "futures-core", - "futures-util", - "fxhash", - "h2", - "http", - "httparse", - "indexmap", - "itoa", - "language-tags", - "lazy_static", - "log", - "mime", - "percent-encoding", - "pin-project 1.0.3", - "rand", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "sha-1", - "slab", - "time 0.2.23", -] - [[package]] name = "actix-macros" version = "0.1.3" @@ -92,19 +10,6 @@ dependencies = [ "syn", ] -[[package]] -name = "actix-router" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd1f7dbda1645bf7da33554db60891755f6c01c1b2169e2f4c492098d30c235" -dependencies = [ - "bytestring 0.1.5", - "http", - "log", - "regex", - "serde", -] - [[package]] name = "actix-rt" version = "1.1.1" @@ -120,50 +25,6 @@ dependencies = [ "tokio 0.2.24", ] -[[package]] -name = "actix-server" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45407e6e672ca24784baa667c5d32ef109ccdd8d5e0b5ebb9ef8a67f4dfb708e" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "actix-utils", - "futures-channel", - "futures-util", - "log", - "mio 0.6.23", - "mio-uds", - "num_cpus", - "slab", - "socket2", -] - -[[package]] -name = "actix-service" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0052435d581b5be835d11f4eb3bce417c8af18d87ddf8ace99f8e67e595882bb" -dependencies = [ - "futures-util", - "pin-project 0.4.27", -] - -[[package]] -name = "actix-testing" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47239ca38799ab74ee6a8a94d1ce857014b2ac36f242f70f3f75a66f691e791c" -dependencies = [ - "actix-macros", - "actix-rt", - "actix-server", - "actix-service", - "log", - "socket2", -] - [[package]] name = "actix-threadpool" version = "0.3.3" @@ -179,103 +40,6 @@ dependencies = [ "threadpool", ] -[[package]] -name = "actix-tls" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24789b7d7361cf5503a504ebe1c10806896f61e96eca9a7350e23001aca715fb" -dependencies = [ - "actix-codec", - "actix-service", - "actix-utils", - "futures-util", -] - -[[package]] -name = "actix-utils" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9022dec56632d1d7979e59af14f0597a28a830a9c1c7fec8b2327eb9f16b5a" -dependencies = [ - "actix-codec", - "actix-rt", - "actix-service", - "bitflags", - "bytes 0.5.6", - "either", - "futures-channel", - "futures-sink", - "futures-util", - "log", - "pin-project 0.4.27", - "slab", -] - -[[package]] -name = "actix-web" -version = "3.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86" -dependencies = [ - "actix-codec", - "actix-http", - "actix-macros", - "actix-router", - "actix-rt", - "actix-server", - "actix-service", - "actix-testing", - "actix-threadpool", - "actix-tls", - "actix-utils", - "actix-web-codegen", - "awc", - "bytes 0.5.6", - "derive_more", - "encoding_rs", - "futures-channel", - "futures-core", - "futures-util", - "fxhash", - "log", - "mime", - "pin-project 1.0.3", - "regex", - "serde", - "serde_json", - "serde_urlencoded", - "socket2", - "time 0.2.23", - "tinyvec", - "url", -] - -[[package]] -name = "actix-web-codegen" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "addr2line" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" - [[package]] name = "aho-corasick" version = "0.7.15" @@ -291,16 +55,6 @@ version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86" -[[package]] -name = "async-attributes" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd3d156917d94862e779f356c5acae312b08fd3121e792c857d7928c8088423" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "async-channel" version = "1.5.1" @@ -399,7 +153,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f9f84f1280a2b436a2c77c2582602732b6c2f4321d5494d6e799e6c367859a8" dependencies = [ - "async-attributes", "async-channel", "async-global-executor", "async-io", @@ -428,17 +181,6 @@ version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" -[[package]] -name = "async-trait" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "atomic-waker" version = "1.0.0" @@ -468,50 +210,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "awc" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691" -dependencies = [ - "actix-codec", - "actix-http", - "actix-rt", - "actix-service", - "base64", - "bytes 0.5.6", - "cfg-if 1.0.0", - "derive_more", - "futures-core", - "log", - "mime", - "percent-encoding", - "rand", - "serde", - "serde_json", - "serde_urlencoded", -] - -[[package]] -name = "backtrace" -version = "0.3.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" -dependencies = [ - "addr2line", - "cfg-if 1.0.0", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "base-x" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" - [[package]] name = "base64" version = "0.13.0" @@ -547,26 +245,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "brotli-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4445dea95f4c2b41cde57cc9fee236ae4dbae88d8fcbdb4750fc1bb5d86aaecd" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "brotli2" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cb036c3eade309815c15ddbacec5b22c4d1f3983a774ab2eac2e3e9ea85568e" -dependencies = [ - "brotli-sys", - "libc", -] - [[package]] name = "bumpalo" version = "3.4.0" @@ -591,15 +269,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" -[[package]] -name = "bytestring" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7c05fa5172da78a62d9949d662d2ac89d4cc7355d7b49adee5163f1fb3f363" -dependencies = [ - "bytes 0.5.6", -] - [[package]] name = "bytestring" version = "1.0.0" @@ -642,7 +311,7 @@ dependencies = [ "libc", "num-integer", "num-traits", - "time 0.1.44", + "time", "winapi 0.3.9", ] @@ -676,17 +345,6 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" -[[package]] -name = "cookie" -version = "0.14.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" -dependencies = [ - "percent-encoding", - "time 0.2.23", - "version_check", -] - [[package]] name = "copyless" version = "0.1.5" @@ -699,15 +357,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" -[[package]] -name = "crc32fast" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "crossbeam" version = "0.8.0" @@ -798,39 +447,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" - [[package]] name = "either" version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "encoding_rs" -version = "0.8.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "enum-as-inner" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c5f0096a91d210159eceb2ff5e1c4da18388a170e1e3ce948aac9c8fdbbf595" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "env_logger" version = "0.8.2" @@ -859,24 +481,6 @@ dependencies = [ "instant", ] -[[package]] -name = "flate2" -version = "1.0.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7411863d55df97a419aa64cb4d2f167103ea9d767e2c54a1868b7ac3f6b47129" -dependencies = [ - "cfg-if 1.0.0", - "crc32fast", - "libc", - "miniz_oxide", -] - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "form_urlencoded" version = "1.0.0" @@ -903,20 +507,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c70be434c505aee38639abccb918163b63158a4b4bb791b45b7023044bdc3c9c" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.9" @@ -924,7 +514,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f01c61843314e95f96cc9245702248733a3a3d744e43e2e755e3c7af8348a0a9" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -977,12 +566,6 @@ dependencies = [ "syn", ] -[[package]] -name = "futures-sink" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6adabac1290109cfa089f79192fb6244ad2c3f1cc2281f3e1dd987592b71feb" - [[package]] name = "futures-task" version = "0.3.9" @@ -998,11 +581,9 @@ version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "036a2107cdeb57f6d7322f1b6c363dad67cd63ca3b7d1b925bdf75bd5d96cda9" dependencies = [ - "futures-channel", "futures-core", "futures-io", "futures-macro", - "futures-sink", "futures-task", "memchr", "pin-project-lite 0.2.1", @@ -1012,15 +593,6 @@ dependencies = [ "slab", ] -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - [[package]] name = "generic-array" version = "0.14.4" @@ -1042,12 +614,6 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1", ] -[[package]] -name = "gimli" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" - [[package]] name = "gloo-timers" version = "0.2.1" @@ -1061,41 +627,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "h2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" -dependencies = [ - "bytes 0.5.6", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio 0.2.24", - "tokio-util", - "tracing", - "tracing-futures", -] - -[[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - -[[package]] -name = "heck" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.17" @@ -1105,34 +636,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hostname" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867" -dependencies = [ - "libc", - "match_cfg", - "winapi 0.3.9", -] - -[[package]] -name = "http" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" -dependencies = [ - "bytes 1.0.0", - "fnv", - "itoa", -] - -[[package]] -name = "httparse" -version = "1.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" - [[package]] name = "humantime" version = "2.0.1" @@ -1150,16 +653,6 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "indexmap" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" -dependencies = [ - "autocfg 1.0.1", - "hashbrown", -] - [[package]] name = "instant" version = "0.1.9" @@ -1178,24 +671,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ipconfig" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e2f18aece9709094573a9f24f483c4f65caa4298e2f7ae1b71cc65d853fad7" -dependencies = [ - "socket2", - "widestring", - "winapi 0.3.9", - "winreg", -] - -[[package]] -name = "itoa" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" - [[package]] name = "js-sys" version = "0.3.46" @@ -1224,12 +699,6 @@ dependencies = [ "log", ] -[[package]] -name = "language-tags" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" - [[package]] name = "lazy_static" version = "1.4.0" @@ -1251,12 +720,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" -[[package]] -name = "linked-hash-map" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" - [[package]] name = "lock_api" version = "0.4.2" @@ -1275,21 +738,6 @@ dependencies = [ "cfg-if 0.1.10", ] -[[package]] -name = "lru-cache" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" -dependencies = [ - "linked-hash-map", -] - -[[package]] -name = "match_cfg" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" - [[package]] name = "matches" version = "0.1.8" @@ -1311,22 +759,6 @@ dependencies = [ "autocfg 1.0.1", ] -[[package]] -name = "mime" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "miniz_oxide" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" -dependencies = [ - "adler", - "autocfg 1.0.1", -] - [[package]] name = "mio" version = "0.6.23" @@ -1492,12 +924,6 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" - [[package]] name = "once_cell" version = "1.5.2" @@ -1558,46 +984,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" -[[package]] -name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal 0.4.27", -] - -[[package]] -name = "pin-project" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a83804639aad6ba65345661744708855f9fbcb71176ea8d28d05aeb11d975e7" -dependencies = [ - "pin-project-internal 1.0.3", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7bcc46b8f73443d15bc1c5fecbb315718491fa9187fa483f0e359323cde8b3a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "pin-project-lite" version = "0.1.11" @@ -1656,12 +1042,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "quick-error" -version = "1.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" - [[package]] name = "quote" version = "1.0.8" @@ -1736,16 +1116,6 @@ version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" -[[package]] -name = "resolv-conf" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00" -dependencies = [ - "hostname", - "quick-error", -] - [[package]] name = "rsa" version = "0.3.0" @@ -1768,90 +1138,17 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustc-demangle" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" - -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver", -] - -[[package]] -name = "ryu" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" - [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "serde" version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.118" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fceb2595057b6891a4ee808f70054bd2d12f0e97f1cbb78689b59f676df325a" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_urlencoded" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" -dependencies = [ - "form_urlencoded", - "itoa", - "ryu", - "serde", -] [[package]] name = "sha-1" @@ -1866,12 +1163,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "sha1" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" - [[package]] name = "sha2" version = "0.9.2" @@ -1951,7 +1242,7 @@ dependencies = [ "async-compat 0.1.5", "async-std", "bytes 1.0.0", - "bytestring 1.0.0", + "bytestring", "conquer-once", "crossbeam", "futures-core", @@ -1968,9 +1259,7 @@ dependencies = [ name = "sqlx-example-quickstart" version = "0.0.0" dependencies = [ - "actix-web", "anyhow", - "async-std", "env_logger", "log", "sqlx", @@ -1985,7 +1274,7 @@ dependencies = [ "base64", "bitflags", "bytes 1.0.0", - "bytestring 1.0.0", + "bytestring", "either", "futures-executor", "futures-io", @@ -2001,64 +1290,6 @@ dependencies = [ "url", ] -[[package]] -name = "standback" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66a8cff4fa24853fdf6b51f75c6d7f8206d7c75cab4e467bcd7f25c2b1febe0" -dependencies = [ - "version_check", -] - -[[package]] -name = "stdweb" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" -dependencies = [ - "discard", - "rustc_version", - "stdweb-derive", - "stdweb-internal-macros", - "stdweb-internal-runtime", - "wasm-bindgen", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "serde_derive", - "syn", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" -dependencies = [ - "base-x", - "proc-macro2", - "quote", - "serde", - "serde_derive", - "serde_json", - "sha1", - "syn", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" - [[package]] name = "subtle" version = "2.4.0" @@ -2146,44 +1377,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "time" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcdaeea317915d59b2b4cd3b5efcd156c309108664277793f5351700c02ce98b" -dependencies = [ - "const_fn", - "libc", - "standback", - "stdweb", - "time-macros", - "version_check", - "winapi 0.3.9", -] - -[[package]] -name = "time-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" -dependencies = [ - "proc-macro-hack", - "time-macros-impl", -] - -[[package]] -name = "time-macros-impl" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" -dependencies = [ - "proc-macro-hack", - "proc-macro2", - "quote", - "standback", - "syn", -] - [[package]] name = "tinyvec" version = "1.1.0" @@ -2210,7 +1403,6 @@ dependencies = [ "iovec", "lazy_static", "libc", - "memchr", "mio 0.6.23", "mio-uds", "pin-project-lite 0.1.11", @@ -2244,91 +1436,6 @@ dependencies = [ "syn", ] -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes 0.5.6", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.1.11", - "tokio 0.2.24", -] - -[[package]] -name = "tracing" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" -dependencies = [ - "cfg-if 1.0.0", - "log", - "pin-project-lite 0.2.1", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tracing-futures" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" -dependencies = [ - "pin-project 0.4.27", - "tracing", -] - -[[package]] -name = "trust-dns-proto" -version = "0.19.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53861fcb288a166aae4c508ae558ed18b53838db728d4d310aad08270a7d4c2b" -dependencies = [ - "async-trait", - "backtrace", - "enum-as-inner", - "futures", - "idna", - "lazy_static", - "log", - "rand", - "smallvec", - "thiserror", - "tokio 0.2.24", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.19.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6759e8efc40465547b0dfce9500d733c65f969a4cbbfbe3ccf68daaa46ef179e" -dependencies = [ - "backtrace", - "cfg-if 0.1.10", - "futures", - "ipconfig", - "lazy_static", - "log", - "lru-cache", - "resolv-conf", - "smallvec", - "thiserror", - "tokio 0.2.24", - "trust-dns-proto", -] - [[package]] name = "typenum" version = "1.12.0" @@ -2353,12 +1460,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" - [[package]] name = "unicode-xid" version = "0.2.1" @@ -2492,12 +1593,6 @@ dependencies = [ "cc", ] -[[package]] -name = "widestring" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c" - [[package]] name = "winapi" version = "0.2.8" @@ -2541,15 +1636,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "winreg" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2986deb581c4fe11b621998a5e53361efe6b48a151178d0cd9eeffa4dc6acc9" -dependencies = [ - "winapi 0.3.9", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" diff --git a/examples/quickstart/Cargo.toml b/examples/quickstart/Cargo.toml index d3c5022d..0d282eea 100644 --- a/examples/quickstart/Cargo.toml +++ b/examples/quickstart/Cargo.toml @@ -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"] } diff --git a/examples/quickstart/src/main.rs b/examples/quickstart/src/main.rs index 3ffa03b6..dc5a6fcb 100644 --- a/examples/quickstart/src/main.rs +++ b/examples/quickstart/src/main.rs @@ -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 = ::connect("mysql://root:password@localhost").await?; +// // 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(()) // } @@ -13,7 +21,10 @@ use sqlx::prelude::*; fn main() -> anyhow::Result<()> { env_logger::try_init()?; - let _conn = ::connect("mysql://root:password@localhost")?; + let mut conn = >::connect("mysql://root:password@localhost")?; + + conn.ping()?; + conn.close()?; Ok(()) } diff --git a/sqlx-core/src/acquire.rs b/sqlx-core/src/acquire.rs new file mode 100644 index 00000000..7e3ccdcf --- /dev/null +++ b/sqlx-core/src/acquire.rs @@ -0,0 +1,46 @@ +#[cfg(feature = "async")] +use futures_util::future::BoxFuture; + +use crate::{Database, DefaultRuntime, Runtime}; + +pub trait Acquire { + type Database: Database; + + /// Get a connection from the pool, make a new connection, or wait for one to become + /// available. + /// + /// Takes exclusive use of the connection until it is released. + /// + #[cfg(feature = "async")] + fn acquire( + self, + ) -> BoxFuture<'static, crate::Result<>::Connection>> + where + >::Connection: Sized; + + /// Get a connection from the pool, if available. + /// + /// Returns `None` immediately if there are no connections available. + /// + fn try_acquire(self) -> Option<>::Connection> + where + >::Connection: Sized; + + #[cfg(feature = "async")] + fn begin( + self, + ) -> BoxFuture<'static, crate::Result<>::Connection>> + where + >::Connection: Sized; + + #[cfg(feature = "async")] + fn try_begin( + self, + ) -> BoxFuture<'static, crate::Result>::Connection>>> + where + >::Connection: Sized; +} + +// TODO: impl Acquire for &Pool { ... } +// TODO: impl Acquire for &mut C { ... } +// TODO: impl Acquire for &mut &A { ... } diff --git a/sqlx-core/src/blocking.rs b/sqlx-core/src/blocking.rs index 26237780..99f6c57b 100644 --- a/sqlx-core/src/blocking.rs +++ b/sqlx-core/src/blocking.rs @@ -1,15 +1,24 @@ //! Types and traits used to implement a database driver with **blocking** I/O. //! +mod acquire; +mod close; +mod connect; mod connection; mod options; mod runtime; +pub use acquire::Acquire; +pub use close::Close; +pub use connect::Connect; pub use connection::Connection; pub use options::ConnectOptions; pub use runtime::{Blocking, Runtime}; pub mod prelude { + pub use super::Acquire as _; + pub use super::Close as _; + pub use super::Connect as _; pub use super::ConnectOptions as _; pub use super::Connection as _; pub use super::Runtime as _; diff --git a/sqlx-core/src/blocking/acquire.rs b/sqlx-core/src/blocking/acquire.rs new file mode 100644 index 00000000..69e31743 --- /dev/null +++ b/sqlx-core/src/blocking/acquire.rs @@ -0,0 +1,28 @@ +use super::{Blocking, Runtime}; +use crate::Database; + +pub trait Acquire: crate::Acquire { + /// Get a connection from the pool, make a new connection, or wait for one to become + /// available. + /// + /// Takes exclusive use of the connection until it is released. + /// + /// For detailed information, refer to the asynchronous version of + /// this: [`acquire()`][crate::Acquire::acquire]. + /// + fn acquire(self) -> crate::Result<>::Connection> + where + >::Connection: Sized; + + fn begin(self) -> crate::Result<>::Connection> + where + >::Connection: Sized; + + fn try_begin(self) -> crate::Result>::Connection>> + where + >::Connection: Sized; +} + +// TODO: impl Acquire for &Pool { ... } +// TODO: impl Acquire for &mut C { ... } +// TODO: impl Acquire for &mut &A { ... } diff --git a/sqlx-core/src/blocking/close.rs b/sqlx-core/src/blocking/close.rs new file mode 100644 index 00000000..b0da47c3 --- /dev/null +++ b/sqlx-core/src/blocking/close.rs @@ -0,0 +1,12 @@ +use std::io; + +use super::{Blocking, Runtime}; + +pub trait Close: crate::Close { + fn close(self) -> crate::Result<()> + where + ::TcpStream: io::Read + io::Write; +} + +// TODO: impl Close for Pool { ... } +// TODO: impl Close for C { ... } diff --git a/sqlx-core/src/blocking/connect.rs b/sqlx-core/src/blocking/connect.rs new file mode 100644 index 00000000..40dbd847 --- /dev/null +++ b/sqlx-core/src/blocking/connect.rs @@ -0,0 +1,13 @@ +use std::io; + +use super::{Blocking, Runtime}; + +pub trait Connect: crate::Connect { + fn connect(url: &str) -> crate::Result + where + Self: Sized, + ::TcpStream: io::Read + io::Write; +} + +// TODO: impl Connect for Pool { ... } +// TODO: impl Connect for PgConnection { ... } diff --git a/sqlx-core/src/blocking/connection.rs b/sqlx-core/src/blocking/connection.rs index a4b0b080..5d0ade51 100644 --- a/sqlx-core/src/blocking/connection.rs +++ b/sqlx-core/src/blocking/connection.rs @@ -1,38 +1,19 @@ use std::io; -use super::{ConnectOptions, Runtime}; -use crate::DefaultRuntime; +use super::{Blocking, Close, Connect, ConnectOptions, Runtime}; /// A unique connection (session) with a specific database. /// /// For detailed information, refer to the asynchronous version of /// this: [`Connection`][crate::Connection]. /// -pub trait Connection: crate::Connection +pub trait Connection: + crate::Connection + Close + Connect where Rt: Runtime, ::TcpStream: io::Read + io::Write, Self::Options: ConnectOptions, { - /// Establish a new database connection. - /// - /// For detailed information, refer to the asynchronous version of - /// this: [`connect()`][crate::Connection::connect]. - /// - fn connect(url: &str) -> crate::Result - where - Self: Sized, - { - url.parse::<>::Options>()?.connect() - } - - /// Explicitly close this database connection. - /// - /// For detailed information, refer to the asynchronous version of - /// this: [`close()`][crate::Connection::close]. - /// - fn close(self) -> crate::Result<()>; - /// Checks if a connection to the database is still valid. /// /// For detailed information, refer to the asynchronous version of diff --git a/sqlx-core/src/blocking/options.rs b/sqlx-core/src/blocking/options.rs index 691000be..d0fdd1be 100644 --- a/sqlx-core/src/blocking/options.rs +++ b/sqlx-core/src/blocking/options.rs @@ -1,7 +1,6 @@ use std::io; -use super::{Connection, Runtime}; -use crate::DefaultRuntime; +use super::{Blocking, Connection, Runtime}; /// Options which can be used to configure how a SQL connection is opened. /// @@ -9,9 +8,8 @@ use crate::DefaultRuntime; /// this: [`ConnectOptions`][crate::ConnectOptions]. /// #[allow(clippy::module_name_repetitions)] -pub trait ConnectOptions: crate::ConnectOptions +pub trait ConnectOptions: crate::ConnectOptions where - Rt: Runtime, ::TcpStream: io::Read + io::Write, Self::Connection: crate::Connection + Connection, { diff --git a/sqlx-core/src/close.rs b/sqlx-core/src/close.rs new file mode 100644 index 00000000..1ce9033c --- /dev/null +++ b/sqlx-core/src/close.rs @@ -0,0 +1,12 @@ +use crate::{DefaultRuntime, Runtime}; + +pub trait Close { + #[cfg(feature = "async")] + fn close(self) -> futures_util::future::BoxFuture<'static, crate::Result<()>> + where + Rt: crate::AsyncRuntime, + ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin; +} + +// TODO: impl Close for Pool { ... } +// TODO: impl Close for C { ... } diff --git a/sqlx-core/src/connect.rs b/sqlx-core/src/connect.rs new file mode 100644 index 00000000..26730d9e --- /dev/null +++ b/sqlx-core/src/connect.rs @@ -0,0 +1,15 @@ +use crate::{ConnectOptions, DefaultRuntime, Runtime}; + +pub trait Connect { + type Options: ConnectOptions; + + #[cfg(feature = "async")] + fn connect(url: &str) -> futures_util::future::BoxFuture<'_, crate::Result> + where + Self: Sized, + Rt: crate::AsyncRuntime, + ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin; +} + +// TODO: impl Connect for Pool { ... } +// TODO: impl Connect for PgConnection { ... } diff --git a/sqlx-core/src/connection.rs b/sqlx-core/src/connection.rs index f51e1b67..74417689 100644 --- a/sqlx-core/src/connection.rs +++ b/sqlx-core/src/connection.rs @@ -1,7 +1,7 @@ #[cfg(feature = "async")] use futures_util::future::BoxFuture; -use crate::{ConnectOptions, Database, DefaultRuntime, Runtime}; +use crate::{Close, Connect, Database, DefaultRuntime, Runtime}; /// A unique connection (session) with a specific database. /// @@ -11,64 +11,11 @@ use crate::{ConnectOptions, Database, DefaultRuntime, Runtime}; /// SQL statements will be executed and results returned within the context /// of this single SQL connection. /// -pub trait Connection: 'static + Send -where - Rt: Runtime, +pub trait Connection: + 'static + Send + Connect + Close { type Database: Database; - type Options: ConnectOptions; - - /// Establish a new database connection. - /// - /// A value of [`Options`](#associatedtype.Options) is parsed from the provided connection string. This parsing - /// is database-specific. - /// - /// ```rust,ignore - /// use sqlx::postgres::PgConnection; - /// - /// let mut conn = ::connect( - /// "postgres://postgres:password@localhost/database", - /// ).await?; - /// ``` - /// - /// You may alternatively build the connection options imperatively. - /// - /// ```rust,ignore - /// use sqlx::mysql::MySqlConnectOptions; - /// use sqlx::ConnectOptions; - /// - /// let mut conn = ::new() - /// .host("localhost") - /// .username("root") - /// .password("password") - /// .connect().await?; - /// ``` - /// - #[cfg(feature = "async")] - #[must_use] - fn connect(url: &str) -> BoxFuture<'_, crate::Result> - where - Self: Sized, - Rt: crate::AsyncRuntime, - ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin, - { - let options = url.parse::(); - Box::pin(async move { options?.connect().await }) - } - - /// Explicitly close this database connection. - /// - /// This method is **not required** for safe and consistent operation. However, it is - /// recommended to call it instead of letting a connection `drop` as the database backend - /// will be faster at cleaning up resources. - /// - #[cfg(feature = "async")] - fn close(self) -> BoxFuture<'static, crate::Result<()>> - where - Rt: crate::AsyncRuntime, - ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin; - /// Checks if a connection to the database is still valid. /// /// The method of operation greatly depends on the database driver. In MySQL, there is an diff --git a/sqlx-core/src/lib.rs b/sqlx-core/src/lib.rs index c062e6aa..d3359bad 100644 --- a/sqlx-core/src/lib.rs +++ b/sqlx-core/src/lib.rs @@ -26,10 +26,14 @@ extern crate _async_std as async_std; #[cfg(feature = "tokio")] extern crate _tokio as tokio; +mod acquire; +mod close; +mod connect; mod connection; mod database; mod error; mod options; +mod pool; mod runtime; #[doc(hidden)] @@ -38,10 +42,14 @@ pub mod io; #[cfg(feature = "blocking")] pub mod blocking; +pub use acquire::Acquire; +pub use close::Close; +pub use connect::Connect; pub use connection::Connection; pub use database::{Database, HasOutput}; pub use error::{DatabaseError, Error, Result}; pub use options::ConnectOptions; +pub use pool::Pool; #[cfg(feature = "actix")] pub use runtime::Actix; #[cfg(feature = "async")] @@ -79,7 +87,7 @@ pub type DefaultRuntime = blocking::Blocking; // the unit type is implemented for Runtime, this is only to allow the // lib to compile, the lib is mostly useless in this state #[cfg(not(any( - feature = "async_std", + feature = "async-std", feature = "actix", feature = "tokio", feature = "blocking" @@ -88,6 +96,9 @@ pub type DefaultRuntime = (); #[cfg(any(feature = "async-std", feature = "tokio", feature = "actix"))] pub mod prelude { + pub use super::Acquire as _; + pub use super::Close as _; + pub use super::Connect as _; pub use super::ConnectOptions as _; pub use super::Connection as _; pub use super::Database as _; @@ -101,7 +112,7 @@ pub mod prelude { pub use blocking::prelude; #[cfg(not(any( - feature = "async_std", + feature = "async-std", feature = "actix", feature = "tokio", feature = "blocking" diff --git a/sqlx-core/src/options.rs b/sqlx-core/src/options.rs index 414bc5ce..6a5af42a 100644 --- a/sqlx-core/src/options.rs +++ b/sqlx-core/src/options.rs @@ -12,7 +12,7 @@ where { type Connection: Connection + ?Sized; - /// Establish a connection to the database. + /// Establish a new connection to the database. #[cfg(feature = "async")] fn connect(&self) -> futures_util::future::BoxFuture<'_, crate::Result> where diff --git a/sqlx-core/src/pool.rs b/sqlx-core/src/pool.rs new file mode 100644 index 00000000..6dfaeb25 --- /dev/null +++ b/sqlx-core/src/pool.rs @@ -0,0 +1,13 @@ +use std::marker::PhantomData; + +use crate::{Database, DefaultRuntime, Runtime}; + +/// A connection pool to enable the efficient reuse of a managed pool of SQL connections. +pub struct Pool { + runtime: PhantomData, + database: PhantomData, +} + +// TODO: impl Acquire for &Pool +// TODO: impl Connect for Pool +// TODO: impl Close for Pool diff --git a/sqlx-mysql/src/connection.rs b/sqlx-mysql/src/connection.rs index 58b80ef5..990a2619 100644 --- a/sqlx-mysql/src/connection.rs +++ b/sqlx-mysql/src/connection.rs @@ -1,7 +1,7 @@ use std::fmt::{self, Debug, Formatter}; use sqlx_core::io::BufStream; -use sqlx_core::{Connection, DefaultRuntime, Runtime}; +use sqlx_core::{Close, Connect, Connection, DefaultRuntime, Runtime}; use crate::protocol::Capabilities; use crate::{MySql, MySqlConnectOptions}; @@ -12,10 +12,7 @@ mod ping; mod stream; #[allow(clippy::module_name_repetitions)] -pub struct MySqlConnection -where - Rt: Runtime, -{ +pub struct MySqlConnection { stream: BufStream, connection_id: u32, @@ -28,10 +25,7 @@ where sequence_id: u8, } -impl MySqlConnection -where - Rt: Runtime, -{ +impl MySqlConnection { pub(crate) fn new(stream: Rt::TcpStream) -> Self { Self { stream: BufStream::with_capacity(stream, 4096, 1024), @@ -54,32 +48,15 @@ where } } -impl Debug for MySqlConnection -where - Rt: Runtime, -{ +impl Debug for MySqlConnection { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("MySqlConnection").finish() } } -impl Connection for MySqlConnection -where - Rt: Runtime, -{ +impl Connection for MySqlConnection { type Database = MySql; - type Options = MySqlConnectOptions; - - #[cfg(feature = "async")] - fn close(self) -> futures_util::future::BoxFuture<'static, sqlx_core::Result<()>> - where - Rt: sqlx_core::AsyncRuntime, - ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin, - { - Box::pin(self.close_async()) - } - #[cfg(feature = "async")] fn ping(&mut self) -> futures_util::future::BoxFuture<'_, sqlx_core::Result<()>> where @@ -90,17 +67,68 @@ where } } +impl Connect for MySqlConnection { + type Options = MySqlConnectOptions; + + #[cfg(feature = "async")] + fn connect(url: &str) -> futures_util::future::BoxFuture<'_, sqlx_core::Result> + where + Self: Sized, + Rt: sqlx_core::AsyncRuntime, + ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin, + { + use sqlx_core::ConnectOptions; + + let options = url.parse::(); + Box::pin(async move { options?.connect().await }) + } +} + +impl Close for MySqlConnection { + #[cfg(feature = "async")] + fn close(self) -> futures_util::future::BoxFuture<'static, sqlx_core::Result<()>> + where + Rt: sqlx_core::AsyncRuntime, + ::TcpStream: futures_io::AsyncRead + futures_io::AsyncWrite + Unpin, + { + Box::pin(self.close_async()) + } +} + #[cfg(feature = "blocking")] impl sqlx_core::blocking::Connection for MySqlConnection where Rt: sqlx_core::blocking::Runtime, ::TcpStream: std::io::Read + std::io::Write, { - fn close(self) -> sqlx_core::Result<()> { - >::close(self) - } - fn ping(&mut self) -> sqlx_core::Result<()> { >::ping(self) } } + +#[cfg(feature = "blocking")] +impl sqlx_core::blocking::Connect for MySqlConnection +where + Rt: sqlx_core::blocking::Runtime, +{ + fn connect(url: &str) -> sqlx_core::Result + where + Self: Sized, + ::TcpStream: std::io::Read + std::io::Write, + { + Self::connect(&url.parse::>()?) + } +} + +#[cfg(feature = "blocking")] +impl sqlx_core::blocking::Close for MySqlConnection +where + Rt: sqlx_core::blocking::Runtime, +{ + fn close(self) -> sqlx_core::Result<()> + where + ::TcpStream: std::io::Read + std::io::Write, + { + self.close() + } +}