diff --git a/Cargo.toml b/Cargo.toml index 4ba462a71..6fee28f0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,3 @@ -[workspace] -members = [ - ".", - "sqlx-core", - "sqlx-postgres-protocol", - "sqlx-postgres", -] - [package] name = "sqlx" version = "0.0.0" @@ -15,19 +7,13 @@ description = "Asynchronous and expressive database client in pure Rust." edition = "2018" [dependencies] -runtime = "=0.3.0-alpha.6" -sqlx-core = { path = "sqlx-core" } -sqlx-postgres = { path = "sqlx-postgres" } -env_logger = "0.6.2" +byteorder = "1.3.2" bytes = "0.4.12" +env_logger = "0.6.2" futures-preview = "=0.3.0-alpha.17" - -[profile.bench] -lto = true -codegen-units = 1 -incremental = false - -[profile.release] -lto = true -codegen-units = 1 -incremental = false +hex = "0.3.2" +itoa = "0.4.4" +log = "0.4.7" +md-5 = "0.8.0" +memchr = "2.2.1" +runtime = "=0.3.0-alpha.6" diff --git a/sqlx-core/Cargo.toml b/sqlx-core/Cargo.toml deleted file mode 100644 index ea9da5fac..000000000 --- a/sqlx-core/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "sqlx-core" -version = "0.0.0" -authors = ["Ryan Leckey "] -license = "MIT OR Apache-2.0" -description = "Shared types and traits for sqlx." -edition = "2018" - -[dependencies] diff --git a/sqlx-core/src/lib.rs b/sqlx-core/src/lib.rs deleted file mode 100644 index 3abc2069d..000000000 --- a/sqlx-core/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub use connection::ConnectOptions; - -mod connection; diff --git a/sqlx-postgres-protocol/Cargo.toml b/sqlx-postgres-protocol/Cargo.toml deleted file mode 100644 index 7944dcf20..000000000 --- a/sqlx-postgres-protocol/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "sqlx-postgres-protocol" -version = "0.0.0" -authors = ["Ryan Leckey "] -license = "MIT OR Apache-2.0" -description = "Provides standalone encoding and decoding of the PostgreSQL v3 wire protocol." -edition = "2018" - -[dependencies] -byteorder = "1.3.2" -bytes = "0.4.12" -memchr = "2.2.1" -md-5 = "0.8.0" -itoa = "0.4.4" -hex = "0.3.2" -log = "0.4.7" - -[dev-dependencies] -matches = "0.1.8" -criterion = "0.2.11" - -[[bench]] -name = "decode" -harness = false - -[[bench]] -name = "encode" -harness = false diff --git a/sqlx-postgres-protocol/benches/decode.rs b/sqlx-postgres-protocol/benches/decode.rs deleted file mode 100644 index eecaa4cc0..000000000 --- a/sqlx-postgres-protocol/benches/decode.rs +++ /dev/null @@ -1,50 +0,0 @@ -#[macro_use] -extern crate criterion; - -use bytes::Bytes; -use criterion::{black_box, Criterion}; -use sqlx_postgres_protocol::{ - BackendKeyData, DataRow, Decode, ParameterStatus, ReadyForQuery, Response, -}; - -fn criterion_benchmark(c: &mut Criterion) { - const NOTICE_RESPONSE: &[u8] = b"SNOTICE\0VNOTICE\0C42710\0Mextension \"uuid-ossp\" already exists, skipping\0Fextension.c\0L1656\0RCreateExtension\0\0"; - const PARAM_STATUS: &[u8] = b"session_authorization\0postgres\0"; - const BACKEND_KEY_DATA: &[u8] = b"\0\0'\xc6\x89R\xc5+"; - const READY_FOR_QUERY: &[u8] = b"E"; - const DATA_ROW: &[u8] = b"\0\x03\0\0\0\x011\0\0\0\x012\0\0\0\x013"; - - c.bench_function("decode Response", |b| { - b.iter(|| { - let _ = Response::decode(black_box(Bytes::from_static(NOTICE_RESPONSE))).unwrap(); - }) - }); - - c.bench_function("decode BackendKeyData", |b| { - b.iter(|| { - let _ = - BackendKeyData::decode(black_box(Bytes::from_static(BACKEND_KEY_DATA))).unwrap(); - }) - }); - - c.bench_function("decode ParameterStatus", |b| { - b.iter(|| { - let _ = ParameterStatus::decode(black_box(Bytes::from_static(PARAM_STATUS))).unwrap(); - }) - }); - - c.bench_function("decode ReadyForQuery", |b| { - b.iter(|| { - let _ = ReadyForQuery::decode(black_box(Bytes::from_static(READY_FOR_QUERY))).unwrap(); - }) - }); - - c.bench_function("decode DataRow", |b| { - b.iter(|| { - let _ = DataRow::decode(black_box(Bytes::from_static(DATA_ROW))).unwrap(); - }) - }); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/sqlx-postgres-protocol/benches/encode.rs b/sqlx-postgres-protocol/benches/encode.rs deleted file mode 100644 index f87a61efe..000000000 --- a/sqlx-postgres-protocol/benches/encode.rs +++ /dev/null @@ -1,68 +0,0 @@ -#[macro_use] -extern crate criterion; - -use criterion::Criterion; -use sqlx_postgres_protocol::{Encode, PasswordMessage, Query, StartupMessage, Terminate}; - -fn criterion_benchmark(c: &mut Criterion) { - c.bench_function("encode PasswordMessage::cleartext", |b| { - let mut dst = Vec::with_capacity(1024); - b.iter(|| { - dst.clear(); - PasswordMessage::cleartext("8e323AMF9YSE9zftFnuhQcvhz7Vf342W4cWU") - .encode(&mut dst) - .unwrap(); - }) - }); - - c.bench_function("encode Query", |b| { - let mut dst = Vec::with_capacity(1024); - b.iter(|| { - dst.clear(); - Query::new("SELECT 1, 2, 3").encode(&mut dst).unwrap(); - }) - }); - - c.bench_function("encode Terminate", |b| { - let mut dst = Vec::with_capacity(1024); - b.iter(|| { - dst.clear(); - Terminate.encode(&mut dst).unwrap(); - }) - }); - - c.bench_function("encode StartupMessage", |b| { - let mut dst = Vec::with_capacity(1024); - b.iter(|| { - dst.clear(); - StartupMessage::new(&[ - ("user", "postgres"), - ("database", "postgres"), - ("DateStyle", "ISO, MDY"), - ("IntervalStyle", "iso_8601"), - ("TimeZone", "UTC"), - ("extra_float_digits", "3"), - ("client_encoding", "UTF-8"), - ]) - .encode(&mut dst) - .unwrap(); - }) - }); - - c.bench_function("encode Password::md5", |b| { - let mut dst = Vec::with_capacity(1024); - b.iter(|| { - dst.clear(); - PasswordMessage::md5( - "8e323AMF9YSE9zftFnuhQcvhz7Vf342W4cWU", - "postgres", - [10, 41, 20, 150], - ) - .encode(&mut dst) - .unwrap(); - }) - }); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/sqlx-postgres/Cargo.toml b/sqlx-postgres/Cargo.toml deleted file mode 100644 index ea0c298da..000000000 --- a/sqlx-postgres/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "sqlx-postgres" -version = "0.0.0" -authors = ["Ryan Leckey "] -license = "MIT OR Apache-2.0" -description = "PostgreSQL database driver for dbx." -edition = "2018" - -[dependencies] -sqlx-core = { path = "../sqlx-core" } -sqlx-postgres-protocol = { path = "../sqlx-postgres-protocol" } -runtime = "=0.3.0-alpha.6" -futures-preview = "=0.3.0-alpha.17" -byteorder = "1.3.2" -log = "0.4.7" -hex = "0.3.2" -bytes = "0.4.12" -memchr = "2.2.1" -md-5 = "0.8.0" - -[dev-dependencies] -matches = "0.1.8" diff --git a/sqlx-postgres/src/lib.rs b/sqlx-postgres/src/lib.rs deleted file mode 100644 index e93a7a5cd..000000000 --- a/sqlx-postgres/src/lib.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![feature(non_exhaustive, async_await)] -#![allow(clippy::needless_lifetimes)] - -mod connection; -pub use connection::Connection; diff --git a/src/lib.rs b/src/lib.rs index 8060ada06..2064373bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,7 @@ -pub use sqlx_core::ConnectOptions; -pub use sqlx_postgres as pg; +#![feature(non_exhaustive, async_await)] +#![allow(clippy::needless_lifetimes)] + +mod options; +pub use self::options::ConnectOptions; + +pub mod postgres; diff --git a/src/main.rs b/src/main.rs index 69e3cf587..f91dbc4be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![feature(async_await)] use futures::{future, TryStreamExt}; -use sqlx::{pg::Connection, ConnectOptions}; +use sqlx::{postgres::Connection, ConnectOptions}; use std::io; // TODO: ToSql and FromSql (to [de]serialize values from/to Rust and SQL) diff --git a/sqlx-core/src/connection.rs b/src/options.rs similarity index 100% rename from sqlx-core/src/connection.rs rename to src/options.rs diff --git a/sqlx-postgres/src/connection/establish.rs b/src/postgres/connection/establish.rs similarity index 95% rename from sqlx-postgres/src/connection/establish.rs rename to src/postgres/connection/establish.rs index e5b1572e4..77bec8de7 100644 --- a/sqlx-postgres/src/connection/establish.rs +++ b/src/postgres/connection/establish.rs @@ -1,6 +1,8 @@ use super::Connection; -use sqlx_core::ConnectOptions; -use sqlx_postgres_protocol::{Authentication, Message, PasswordMessage, StartupMessage}; +use crate::{ + postgres::protocol::{Authentication, Message, PasswordMessage, StartupMessage}, + ConnectOptions, +}; use std::io; pub async fn establish<'a, 'b: 'a>( diff --git a/sqlx-postgres/src/connection/execute.rs b/src/postgres/connection/execute.rs similarity index 93% rename from sqlx-postgres/src/connection/execute.rs rename to src/postgres/connection/execute.rs index f3b21b07b..d7fc1b5ab 100644 --- a/sqlx-postgres/src/connection/execute.rs +++ b/src/postgres/connection/execute.rs @@ -1,10 +1,10 @@ use super::prepare::Prepare; -use sqlx_postgres_protocol::{self as proto, Execute, Message, Sync}; +use crate::postgres::protocol::{self, Execute, Message, Sync}; use std::io; impl<'a> Prepare<'a> { pub async fn execute(self) -> io::Result { - proto::bind::trailer( + protocol::bind::trailer( &mut self.connection.wbuf, self.bind_state, self.bind_values, diff --git a/sqlx-postgres/src/connection/get.rs b/src/postgres/connection/get.rs similarity index 92% rename from sqlx-postgres/src/connection/get.rs rename to src/postgres/connection/get.rs index f2bb26bbb..d11df6bf1 100644 --- a/sqlx-postgres/src/connection/get.rs +++ b/src/postgres/connection/get.rs @@ -1,10 +1,10 @@ use super::prepare::Prepare; -use sqlx_postgres_protocol::{self as proto, DataRow, Execute, Message, Sync}; +use crate::postgres::protocol::{self, DataRow, Execute, Message, Sync}; use std::io; impl<'a> Prepare<'a> { pub async fn get(self) -> io::Result> { - proto::bind::trailer( + protocol::bind::trailer( &mut self.connection.wbuf, self.bind_state, self.bind_values, diff --git a/sqlx-postgres/src/connection/mod.rs b/src/postgres/connection/mod.rs similarity index 98% rename from sqlx-postgres/src/connection/mod.rs rename to src/postgres/connection/mod.rs index a151cdcad..7dbb04e59 100644 --- a/sqlx-postgres/src/connection/mod.rs +++ b/src/postgres/connection/mod.rs @@ -1,3 +1,5 @@ +use super::protocol::{Encode, Message, Terminate}; +use crate::ConnectOptions; use bytes::{BufMut, BytesMut}; use futures::{ io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}, @@ -6,8 +8,6 @@ use futures::{ Future, }; use runtime::net::TcpStream; -use sqlx_core::ConnectOptions; -use sqlx_postgres_protocol::{Encode, Message, Terminate}; use std::{fmt::Debug, io, pin::Pin}; mod establish; diff --git a/sqlx-postgres/src/connection/prepare.rs b/src/postgres/connection/prepare.rs similarity index 74% rename from sqlx-postgres/src/connection/prepare.rs rename to src/postgres/connection/prepare.rs index 2a98e5703..58e32111b 100644 --- a/sqlx-postgres/src/connection/prepare.rs +++ b/src/postgres/connection/prepare.rs @@ -1,5 +1,5 @@ use super::Connection; -use sqlx_postgres_protocol::{self as proto, Parse}; +use crate::postgres::protocol::{self, Parse}; pub struct Prepare<'a> { pub(super) connection: &'a mut Connection, @@ -13,7 +13,7 @@ pub fn prepare<'a, 'b>(connection: &'a mut Connection, query: &'b str) -> Prepar // TODO: Use named statements connection.send(Parse::new("", query, &[])); - let bind_state = proto::bind::header(&mut connection.wbuf, "", "", &[]); + let bind_state = protocol::bind::header(&mut connection.wbuf, "", "", &[]); Prepare { connection, @@ -25,14 +25,14 @@ pub fn prepare<'a, 'b>(connection: &'a mut Connection, query: &'b str) -> Prepar impl<'a> Prepare<'a> { #[inline] pub fn bind<'b>(mut self, value: &'b [u8]) -> Self { - proto::bind::value(&mut self.connection.wbuf, value); + protocol::bind::value(&mut self.connection.wbuf, value); self.bind_values += 1; self } #[inline] pub fn bind_null<'b>(mut self) -> Self { - proto::bind::value_null(&mut self.connection.wbuf); + protocol::bind::value_null(&mut self.connection.wbuf); self.bind_values += 1; self } diff --git a/sqlx-postgres/src/connection/select.rs b/src/postgres/connection/select.rs similarity index 94% rename from sqlx-postgres/src/connection/select.rs rename to src/postgres/connection/select.rs index 0cf9f6baf..d0c08ae51 100644 --- a/sqlx-postgres/src/connection/select.rs +++ b/src/postgres/connection/select.rs @@ -1,11 +1,11 @@ use super::prepare::Prepare; +use crate::postgres::protocol::{self, DataRow, Execute, Message, Sync}; use futures::{stream, Stream}; -use sqlx_postgres_protocol::{self as proto, DataRow, Execute, Message, Sync}; use std::io; impl<'a> Prepare<'a> { pub fn select(self) -> impl Stream> + 'a + Unpin { - proto::bind::trailer( + protocol::bind::trailer( &mut self.connection.wbuf, self.bind_state, self.bind_values, diff --git a/src/postgres/mod.rs b/src/postgres/mod.rs new file mode 100644 index 000000000..756d3345a --- /dev/null +++ b/src/postgres/mod.rs @@ -0,0 +1,4 @@ +mod connection; +pub use connection::Connection; + +mod protocol; diff --git a/sqlx-postgres-protocol/src/authentication.rs b/src/postgres/protocol/authentication.rs similarity index 98% rename from sqlx-postgres-protocol/src/authentication.rs rename to src/postgres/protocol/authentication.rs index 41cfaec69..cdc51b7d4 100644 --- a/sqlx-postgres-protocol/src/authentication.rs +++ b/src/postgres/protocol/authentication.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/backend_key_data.rs b/src/postgres/protocol/backend_key_data.rs similarity index 94% rename from sqlx-postgres-protocol/src/backend_key_data.rs rename to src/postgres/protocol/backend_key_data.rs index 1462ba521..4a1389a25 100644 --- a/sqlx-postgres-protocol/src/backend_key_data.rs +++ b/src/postgres/protocol/backend_key_data.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use std::{convert::TryInto, io}; @@ -37,8 +37,7 @@ impl Decode for BackendKeyData { #[cfg(test)] mod tests { - use super::BackendKeyData; - use crate::Decode; + use super::{BackendKeyData, Decode}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/bind.rs b/src/postgres/protocol/bind.rs similarity index 100% rename from sqlx-postgres-protocol/src/bind.rs rename to src/postgres/protocol/bind.rs diff --git a/sqlx-postgres-protocol/src/command_complete.rs b/src/postgres/protocol/command_complete.rs similarity index 96% rename from sqlx-postgres-protocol/src/command_complete.rs rename to src/postgres/protocol/command_complete.rs index b750e0cd2..2d2957707 100644 --- a/sqlx-postgres-protocol/src/command_complete.rs +++ b/src/postgres/protocol/command_complete.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use memchr::memrchr; use std::{io, str}; @@ -36,8 +36,7 @@ impl Decode for CommandComplete { #[cfg(test)] mod tests { - use super::CommandComplete; - use crate::Decode; + use super::{CommandComplete, Decode}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/data_row.rs b/src/postgres/protocol/data_row.rs similarity index 97% rename from sqlx-postgres-protocol/src/data_row.rs rename to src/postgres/protocol/data_row.rs index 0648762a9..52169a1d0 100644 --- a/sqlx-postgres-protocol/src/data_row.rs +++ b/src/postgres/protocol/data_row.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use std::{ convert::TryInto, @@ -80,8 +80,7 @@ impl Debug for DataRow { #[cfg(test)] mod tests { - use super::DataRow; - use crate::Decode; + use super::{DataRow, Decode}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/decode.rs b/src/postgres/protocol/decode.rs similarity index 100% rename from sqlx-postgres-protocol/src/decode.rs rename to src/postgres/protocol/decode.rs diff --git a/sqlx-postgres-protocol/src/describe.rs b/src/postgres/protocol/describe.rs similarity index 94% rename from sqlx-postgres-protocol/src/describe.rs rename to src/postgres/protocol/describe.rs index bf6540637..3ee80bb04 100644 --- a/sqlx-postgres-protocol/src/describe.rs +++ b/src/postgres/protocol/describe.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] @@ -40,8 +40,7 @@ impl<'a> Encode for Describe<'a> { #[cfg(test)] mod test { - use super::{Describe, DescribeKind}; - use crate::Encode; + use super::{Describe, DescribeKind, Encode}; use std::io; #[test] diff --git a/sqlx-postgres-protocol/src/encode.rs b/src/postgres/protocol/encode.rs similarity index 100% rename from sqlx-postgres-protocol/src/encode.rs rename to src/postgres/protocol/encode.rs diff --git a/sqlx-postgres-protocol/src/execute.rs b/src/postgres/protocol/execute.rs similarity index 97% rename from sqlx-postgres-protocol/src/execute.rs rename to src/postgres/protocol/execute.rs index 6a256aa5f..d950a2d8d 100644 --- a/sqlx-postgres-protocol/src/execute.rs +++ b/src/postgres/protocol/execute.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] diff --git a/sqlx-postgres-protocol/src/message.rs b/src/postgres/protocol/message.rs similarity index 99% rename from sqlx-postgres-protocol/src/message.rs rename to src/postgres/protocol/message.rs index 23e423249..1dac75f6b 100644 --- a/sqlx-postgres-protocol/src/message.rs +++ b/src/postgres/protocol/message.rs @@ -1,4 +1,4 @@ -use crate::{ +use super::{ Authentication, BackendKeyData, CommandComplete, DataRow, Decode, NotificationResponse, ParameterDescription, ParameterStatus, ReadyForQuery, Response, RowDescription, }; diff --git a/sqlx-postgres-protocol/src/lib.rs b/src/postgres/protocol/mod.rs similarity index 95% rename from sqlx-postgres-protocol/src/lib.rs rename to src/postgres/protocol/mod.rs index 21156e122..1de8ee7f2 100644 --- a/sqlx-postgres-protocol/src/lib.rs +++ b/src/postgres/protocol/mod.rs @@ -1,8 +1,7 @@ -//! https://www.postgresql.org/docs/devel/protocol.html +pub mod bind; mod authentication; mod backend_key_data; -pub mod bind; mod command_complete; mod data_row; mod decode; diff --git a/sqlx-postgres-protocol/src/notification_response.rs b/src/postgres/protocol/notification_response.rs similarity index 95% rename from sqlx-postgres-protocol/src/notification_response.rs rename to src/postgres/protocol/notification_response.rs index 8a08fdb2a..9027ff110 100644 --- a/sqlx-postgres-protocol/src/notification_response.rs +++ b/src/postgres/protocol/notification_response.rs @@ -1,4 +1,4 @@ -use crate::{decode::get_str, Decode}; +use super::{decode::get_str, Decode}; use byteorder::{BigEndian, ByteOrder}; use bytes::Bytes; @@ -70,8 +70,7 @@ impl Decode for NotificationResponse { #[cfg(test)] mod tests { - use super::NotificationResponse; - use crate::Decode; + use super::{Decode, NotificationResponse}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/parameter_description.rs b/src/postgres/protocol/parameter_description.rs similarity index 95% rename from sqlx-postgres-protocol/src/parameter_description.rs rename to src/postgres/protocol/parameter_description.rs index ab94d9848..810bf7ef9 100644 --- a/sqlx-postgres-protocol/src/parameter_description.rs +++ b/src/postgres/protocol/parameter_description.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use byteorder::{BigEndian, ByteOrder}; use bytes::Bytes; @@ -30,8 +30,7 @@ impl Decode for ParameterDescription { #[cfg(test)] mod test { - use super::ParameterDescription; - use crate::Decode; + use super::{Decode, ParameterDescription}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/parameter_status.rs b/src/postgres/protocol/parameter_status.rs similarity index 94% rename from sqlx-postgres-protocol/src/parameter_status.rs rename to src/postgres/protocol/parameter_status.rs index 129d947c5..65c2556ac 100644 --- a/sqlx-postgres-protocol/src/parameter_status.rs +++ b/src/postgres/protocol/parameter_status.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use std::{io, str}; @@ -35,8 +35,7 @@ impl Decode for ParameterStatus { #[cfg(test)] mod tests { - use super::ParameterStatus; - use crate::Decode; + use super::{Decode, ParameterStatus}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/parse.rs b/src/postgres/protocol/parse.rs similarity index 98% rename from sqlx-postgres-protocol/src/parse.rs rename to src/postgres/protocol/parse.rs index 13bb92fa2..360d46f43 100644 --- a/sqlx-postgres-protocol/src/parse.rs +++ b/src/postgres/protocol/parse.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] diff --git a/sqlx-postgres-protocol/src/password_message.rs b/src/postgres/protocol/password_message.rs similarity index 80% rename from sqlx-postgres-protocol/src/password_message.rs rename to src/postgres/protocol/password_message.rs index fbac09ebf..69797257f 100644 --- a/sqlx-postgres-protocol/src/password_message.rs +++ b/src/postgres/protocol/password_message.rs @@ -1,4 +1,4 @@ -use crate::{Decode, Encode}; +use super::Encode; use bytes::Bytes; use md5::{Digest, Md5}; use std::io; @@ -45,17 +45,6 @@ impl PasswordMessage { } } -impl Decode for PasswordMessage { - fn decode(src: Bytes) -> io::Result - where - Self: Sized, - { - // There is only one field, the password, and it's not like we can - // decrypt it if it was encrypted - Ok(PasswordMessage { password: src }) - } -} - impl Encode for PasswordMessage { fn size_hint(&self) -> usize { self.password.len() + 5 @@ -69,5 +58,3 @@ impl Encode for PasswordMessage { Ok(()) } } - -// TODO: Encode and Decode tests diff --git a/sqlx-postgres-protocol/src/query.rs b/src/postgres/protocol/query.rs similarity index 92% rename from sqlx-postgres-protocol/src/query.rs rename to src/postgres/protocol/query.rs index 960a2da53..fc8218cb1 100644 --- a/sqlx-postgres-protocol/src/query.rs +++ b/src/postgres/protocol/query.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] @@ -25,8 +25,7 @@ impl Encode for Query<'_> { #[cfg(test)] mod tests { - use super::Query; - use crate::Encode; + use super::{Encode, Query}; use std::io; const QUERY_SELECT_1: &[u8] = b"Q\0\0\0\rSELECT 1\0"; diff --git a/sqlx-postgres-protocol/src/ready_for_query.rs b/src/postgres/protocol/ready_for_query.rs similarity index 93% rename from sqlx-postgres-protocol/src/ready_for_query.rs rename to src/postgres/protocol/ready_for_query.rs index 0e1760421..2e7598682 100644 --- a/sqlx-postgres-protocol/src/ready_for_query.rs +++ b/src/postgres/protocol/ready_for_query.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use bytes::Bytes; use std::io; @@ -42,8 +42,7 @@ impl Decode for ReadyForQuery { #[cfg(test)] mod tests { - use super::{ReadyForQuery, TransactionStatus}; - use crate::Decode; + use super::{Decode, ReadyForQuery, TransactionStatus}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/response.rs b/src/postgres/protocol/response.rs similarity index 99% rename from sqlx-postgres-protocol/src/response.rs rename to src/postgres/protocol/response.rs index e43635cd6..41dbe0020 100644 --- a/sqlx-postgres-protocol/src/response.rs +++ b/src/postgres/protocol/response.rs @@ -1,4 +1,4 @@ -use crate::{decode::get_str, Decode}; +use super::{decode::get_str, Decode}; use bytes::Bytes; use std::{ fmt, io, @@ -398,8 +398,7 @@ impl Decode for Response { #[cfg(test)] mod tests { - use super::{Response, Severity}; - use crate::Decode; + use super::{Decode, Response, Severity}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/row_description.rs b/src/postgres/protocol/row_description.rs similarity index 98% rename from sqlx-postgres-protocol/src/row_description.rs rename to src/postgres/protocol/row_description.rs index 428855cbc..280307028 100644 --- a/sqlx-postgres-protocol/src/row_description.rs +++ b/src/postgres/protocol/row_description.rs @@ -1,4 +1,4 @@ -use crate::Decode; +use super::Decode; use byteorder::{BigEndian, ByteOrder}; use bytes::Bytes; use memchr::memchr; @@ -145,8 +145,7 @@ impl<'a> ExactSizeIterator for FieldDescriptions<'a> {} #[cfg(test)] mod tests { - use super::RowDescription; - use crate::Decode; + use super::{Decode, RowDescription}; use bytes::Bytes; use std::io; diff --git a/sqlx-postgres-protocol/src/startup_message.rs b/src/postgres/protocol/startup_message.rs similarity index 95% rename from sqlx-postgres-protocol/src/startup_message.rs rename to src/postgres/protocol/startup_message.rs index 70b158170..93e26b639 100644 --- a/sqlx-postgres-protocol/src/startup_message.rs +++ b/src/postgres/protocol/startup_message.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use byteorder::{BigEndian, ByteOrder}; use std::io; @@ -45,8 +45,7 @@ impl<'a> Encode for StartupMessage<'a> { #[cfg(test)] mod tests { - use super::StartupMessage; - use crate::Encode; + use super::{Encode, StartupMessage}; use std::io; const STARTUP_MESSAGE: &[u8] = b"\0\0\0)\0\x03\0\0user\0postgres\0database\0postgres\0\0"; diff --git a/sqlx-postgres-protocol/src/sync.rs b/src/postgres/protocol/sync.rs similarity index 92% rename from sqlx-postgres-protocol/src/sync.rs rename to src/postgres/protocol/sync.rs index 3657970e9..1986c1e28 100644 --- a/sqlx-postgres-protocol/src/sync.rs +++ b/src/postgres/protocol/sync.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] diff --git a/sqlx-postgres-protocol/src/terminate.rs b/src/postgres/protocol/terminate.rs similarity index 89% rename from sqlx-postgres-protocol/src/terminate.rs rename to src/postgres/protocol/terminate.rs index 9d9763d95..c6c87b149 100644 --- a/sqlx-postgres-protocol/src/terminate.rs +++ b/src/postgres/protocol/terminate.rs @@ -1,4 +1,4 @@ -use crate::Encode; +use super::Encode; use std::io; #[derive(Debug)] @@ -15,8 +15,7 @@ impl Encode for Terminate { #[cfg(test)] mod tests { - use super::Terminate; - use crate::Encode; + use super::{Encode, Terminate}; use std::io; const TERMINATE: &[u8] = b"X\0\0\0\x04";