diff --git a/examples/contacts/src/main.rs b/examples/contacts/src/main.rs index 1b79f20c..e7663c43 100644 --- a/examples/contacts/src/main.rs +++ b/examples/contacts/src/main.rs @@ -10,13 +10,13 @@ use fake::{ Dummy, Fake, Faker, }; use futures::{channel::oneshot::channel, future, stream::TryStreamExt}; -use sqlx::{pg::Pg, Pool}; +use sqlx::{Postgres, Pool}; use std::{ io, time::{Duration, Instant}, }; -type PgPool = Pool; +type PostgresPool = Pool; #[derive(Debug, Dummy)] struct Contact { @@ -40,7 +40,7 @@ struct Contact { async fn main() -> Fallible<()> { env_logger::try_init()?; - let pool = PgPool::new("postgres://postgres@127.0.0.1/sqlx__dev", 85); + let pool = PostgresPool::new("postgres://postgres@127.0.0.1/sqlx__dev", 85); ensure_schema(&pool).await?; insert(&pool, 50_000).await?; @@ -49,7 +49,7 @@ async fn main() -> Fallible<()> { Ok(()) } -async fn ensure_schema(pool: &PgPool) -> io::Result<()> { +async fn ensure_schema(pool: &PostgresPool) -> io::Result<()> { sqlx::query( r#" CREATE TABLE IF NOT EXISTS contacts ( @@ -71,7 +71,7 @@ CREATE TABLE IF NOT EXISTS contacts ( Ok(()) } -async fn insert(pool: &PgPool, count: usize) -> io::Result<()> { +async fn insert(pool: &PostgresPool, count: usize) -> io::Result<()> { let start_at = Instant::now(); let mut handles = vec![]; @@ -111,7 +111,7 @@ async fn insert(pool: &PgPool, count: usize) -> io::Result<()> { Ok(()) } -async fn select(pool: &PgPool, iterations: usize) -> io::Result<()> { +async fn select(pool: &PostgresPool, iterations: usize) -> io::Result<()> { let start_at = Instant::now(); let mut rows: usize = 0; diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index 9eb7496e..f66e53fd 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -2,7 +2,7 @@ use failure::Fallible; use futures::{future, TryStreamExt}; -use sqlx::{pg::Pg, Connection}; +use sqlx::{Postgres, Connection}; use structopt::StructOpt; #[derive(StructOpt, Debug)] @@ -26,7 +26,7 @@ async fn main() -> Fallible<()> { let opt = Options::from_args(); - let mut conn = Connection::::establish("postgres://postgres@127.0.0.1/sqlx__dev").await?; + let mut conn = Connection::::establish("postgres://postgres@127.0.0.1/sqlx__dev").await?; ensure_schema(&mut conn).await?; @@ -47,7 +47,7 @@ async fn main() -> Fallible<()> { Ok(()) } -async fn ensure_schema(conn: &mut Connection) -> Fallible<()> { +async fn ensure_schema(conn: &mut Connection) -> Fallible<()> { sqlx::query("BEGIN").execute(conn).await?; // language=sql @@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS tasks ( Ok(()) } -async fn print_all_tasks(conn: &mut Connection) -> Fallible<()> { +async fn print_all_tasks(conn: &mut Connection) -> Fallible<()> { // language=sql sqlx::query( r#" @@ -90,7 +90,7 @@ WHERE done_at IS NULL Ok(()) } -async fn add_task(conn: &mut Connection, text: &str) -> Fallible<()> { +async fn add_task(conn: &mut Connection, text: &str) -> Fallible<()> { // language=sql sqlx::query( r#" @@ -105,7 +105,7 @@ VALUES ( $1 ) Ok(()) } -async fn mark_task_as_done(conn: &mut Connection, id: i64) -> Fallible<()> { +async fn mark_task_as_done(conn: &mut Connection, id: i64) -> Fallible<()> { // language=sql sqlx::query( r#" diff --git a/src/lib.rs b/src/lib.rs index 3989a080..f683be3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,10 @@ pub mod types; pub mod mariadb; #[cfg(feature = "postgres")] -pub mod pg; +pub mod postgres; + +#[cfg(feature = "postgres")] +pub use self::postgres::Postgres; mod connection; mod executor; diff --git a/src/pg/backend.rs b/src/pg/backend.rs deleted file mode 100644 index aca8def7..00000000 --- a/src/pg/backend.rs +++ /dev/null @@ -1,15 +0,0 @@ -use crate::backend::{Backend, BackendAssocRawQuery}; - -pub struct Pg; - -impl<'q> BackendAssocRawQuery<'q, Pg> for Pg { - type RawQuery = super::PgRawQuery<'q>; -} - -impl Backend for Pg { - type RawConnection = super::PgRawConnection; - type Row = super::PgRow; -} - -// Generates tuple FromSqlRow impls for this backend -impl_from_sql_row_tuples_for_backend!(Pg); diff --git a/src/postgres/backend.rs b/src/postgres/backend.rs new file mode 100644 index 00000000..6f2ec3d3 --- /dev/null +++ b/src/postgres/backend.rs @@ -0,0 +1,15 @@ +use crate::backend::{Backend, BackendAssocRawQuery}; + +pub struct Postgres; + +impl<'q> BackendAssocRawQuery<'q, Postgres> for Postgres { + type RawQuery = super::PostgresRawQuery<'q>; +} + +impl Backend for Postgres { + type RawConnection = super::PostgresRawConnection; + type Row = super::PostgresRow; +} + +// Generates tuple FromSqlRow impls for this backend +impl_from_sql_row_tuples_for_backend!(Postgres); diff --git a/src/pg/connection/establish.rs b/src/postgres/connection/establish.rs similarity index 92% rename from src/pg/connection/establish.rs rename to src/postgres/connection/establish.rs index 56ef9490..c72aaa2a 100644 --- a/src/pg/connection/establish.rs +++ b/src/postgres/connection/establish.rs @@ -1,9 +1,9 @@ -use super::PgRawConnection; -use crate::pg::protocol::{Authentication, Message, PasswordMessage, StartupMessage}; +use super::PostgresRawConnection; +use crate::postgres::protocol::{Authentication, Message, PasswordMessage, StartupMessage}; use std::io; use url::Url; -pub async fn establish<'a, 'b: 'a>(conn: &'a mut PgRawConnection, url: &'b Url) -> io::Result<()> { +pub async fn establish<'a, 'b: 'a>(conn: &'a mut PostgresRawConnection, url: &'b Url) -> io::Result<()> { let user = url.username(); let password = url.password().unwrap_or(""); let database = url.path().trim_start_matches('/'); diff --git a/src/pg/connection/execute.rs b/src/postgres/connection/execute.rs similarity index 82% rename from src/pg/connection/execute.rs rename to src/postgres/connection/execute.rs index 9c24c65a..f99f73a1 100644 --- a/src/pg/connection/execute.rs +++ b/src/postgres/connection/execute.rs @@ -1,8 +1,8 @@ -use super::PgRawConnection; -use crate::pg::protocol::Message; +use super::PostgresRawConnection; +use crate::postgres::protocol::Message; use std::io; -pub async fn execute(conn: &mut PgRawConnection) -> io::Result { +pub async fn execute(conn: &mut PostgresRawConnection) -> io::Result { conn.flush().await?; let mut rows = 0; diff --git a/src/pg/connection/fetch.rs b/src/postgres/connection/fetch.rs similarity index 78% rename from src/pg/connection/fetch.rs rename to src/postgres/connection/fetch.rs index 8a4f89c7..24724f97 100644 --- a/src/pg/connection/fetch.rs +++ b/src/postgres/connection/fetch.rs @@ -1,11 +1,11 @@ -use super::{PgRawConnection, PgRow}; -use crate::pg::protocol::Message; +use super::{PostgresRawConnection, PostgresRow}; +use crate::postgres::protocol::Message; use futures_core::stream::Stream; use std::io; pub fn fetch<'a>( - conn: &'a mut PgRawConnection, -) -> impl Stream> + 'a { + conn: &'a mut PostgresRawConnection, +) -> impl Stream> + 'a { async_stream::try_stream! { conn.flush().await?; @@ -18,7 +18,7 @@ pub fn fetch<'a>( | Message::CommandComplete(_) => {} Message::DataRow(body) => { - yield PgRow(body); + yield PostgresRow(body); } Message::ReadyForQuery(_) => { diff --git a/src/pg/connection/fetch_optional.rs b/src/postgres/connection/fetch_optional.rs similarity index 70% rename from src/pg/connection/fetch_optional.rs rename to src/postgres/connection/fetch_optional.rs index 149549bb..ad547eea 100644 --- a/src/pg/connection/fetch_optional.rs +++ b/src/postgres/connection/fetch_optional.rs @@ -1,11 +1,11 @@ -use super::{PgRawConnection, PgRow}; -use crate::pg::protocol::Message; +use super::{PostgresRawConnection, PostgresRow}; +use crate::postgres::protocol::Message; use std::io; -pub async fn fetch_optional<'a>(conn: &'a mut PgRawConnection) -> io::Result> { +pub async fn fetch_optional<'a>(conn: &'a mut PostgresRawConnection) -> io::Result> { conn.flush().await?; - let mut row: Option = None; + let mut row: Option = None; while let Some(message) = conn.receive().await? { match message { @@ -16,7 +16,7 @@ pub async fn fetch_optional<'a>(conn: &'a mut PgRawConnection) -> io::Result {} Message::DataRow(body) => { - row = Some(PgRow(body)); + row = Some(PostgresRow(body)); } Message::ReadyForQuery(_) => { diff --git a/src/pg/connection/mod.rs b/src/postgres/connection/mod.rs similarity index 94% rename from src/pg/connection/mod.rs rename to src/postgres/connection/mod.rs index 4727cdb3..91313de7 100644 --- a/src/pg/connection/mod.rs +++ b/src/postgres/connection/mod.rs @@ -1,6 +1,6 @@ use super::{ protocol::{Encode, Message, Terminate}, - Pg, PgRow, + Postgres, PostgresRow, }; use crate::{connection::RawConnection, query::RawQuery}; use bytes::{BufMut, BytesMut}; @@ -20,7 +20,7 @@ mod execute; mod fetch; mod fetch_optional; -pub struct PgRawConnection { +pub struct PostgresRawConnection { stream: TcpStream, // Do we think that there is data in the read buffer to be decoded @@ -43,7 +43,7 @@ pub struct PgRawConnection { secret_key: u32, } -impl PgRawConnection { +impl PostgresRawConnection { async fn establish(url: &str) -> io::Result { // TODO: Handle errors let url = Url::parse(url).unwrap(); @@ -146,12 +146,12 @@ impl PgRawConnection { } } -impl RawConnection for PgRawConnection { - type Backend = Pg; +impl RawConnection for PostgresRawConnection { + type Backend = Postgres; #[inline] fn establish(url: &str) -> BoxFuture> { - Box::pin(PgRawConnection::establish(url)) + Box::pin(PostgresRawConnection::establish(url)) } #[inline] @@ -168,7 +168,7 @@ impl RawConnection for PgRawConnection { Box::pin(execute::execute(self)) } - fn fetch<'c, 'q, Q: 'q>(&'c mut self, query: Q) -> BoxStream<'c, io::Result> + fn fetch<'c, 'q, Q: 'q>(&'c mut self, query: Q) -> BoxStream<'c, io::Result> where Q: RawQuery<'q, Backend = Self::Backend>, { @@ -180,7 +180,7 @@ impl RawConnection for PgRawConnection { fn fetch_optional<'c, 'q, Q: 'q>( &'c mut self, query: Q, - ) -> BoxFuture<'c, io::Result>> + ) -> BoxFuture<'c, io::Result>> where Q: RawQuery<'q, Backend = Self::Backend>, { diff --git a/src/pg/mod.rs b/src/postgres/mod.rs similarity index 53% rename from src/pg/mod.rs rename to src/postgres/mod.rs index ef815daf..22ba3175 100644 --- a/src/pg/mod.rs +++ b/src/postgres/mod.rs @@ -6,4 +6,4 @@ mod query; mod row; pub mod types; -pub use self::{backend::Pg, connection::PgRawConnection, query::PgRawQuery, row::PgRow}; +pub use self::{backend::Postgres, connection::PostgresRawConnection, query::PostgresRawQuery, row::PostgresRow}; diff --git a/src/pg/protocol/authentication.rs b/src/postgres/protocol/authentication.rs similarity index 100% rename from src/pg/protocol/authentication.rs rename to src/postgres/protocol/authentication.rs diff --git a/src/pg/protocol/backend_key_data.rs b/src/postgres/protocol/backend_key_data.rs similarity index 100% rename from src/pg/protocol/backend_key_data.rs rename to src/postgres/protocol/backend_key_data.rs diff --git a/src/pg/protocol/bind.rs b/src/postgres/protocol/bind.rs similarity index 100% rename from src/pg/protocol/bind.rs rename to src/postgres/protocol/bind.rs diff --git a/src/pg/protocol/cancel_request.rs b/src/postgres/protocol/cancel_request.rs similarity index 100% rename from src/pg/protocol/cancel_request.rs rename to src/postgres/protocol/cancel_request.rs diff --git a/src/pg/protocol/close.rs b/src/postgres/protocol/close.rs similarity index 100% rename from src/pg/protocol/close.rs rename to src/postgres/protocol/close.rs diff --git a/src/pg/protocol/command_complete.rs b/src/postgres/protocol/command_complete.rs similarity index 100% rename from src/pg/protocol/command_complete.rs rename to src/postgres/protocol/command_complete.rs diff --git a/src/pg/protocol/copy_data.rs b/src/postgres/protocol/copy_data.rs similarity index 100% rename from src/pg/protocol/copy_data.rs rename to src/postgres/protocol/copy_data.rs diff --git a/src/pg/protocol/copy_done.rs b/src/postgres/protocol/copy_done.rs similarity index 100% rename from src/pg/protocol/copy_done.rs rename to src/postgres/protocol/copy_done.rs diff --git a/src/pg/protocol/copy_fail.rs b/src/postgres/protocol/copy_fail.rs similarity index 100% rename from src/pg/protocol/copy_fail.rs rename to src/postgres/protocol/copy_fail.rs diff --git a/src/pg/protocol/data_row.rs b/src/postgres/protocol/data_row.rs similarity index 100% rename from src/pg/protocol/data_row.rs rename to src/postgres/protocol/data_row.rs diff --git a/src/pg/protocol/decode.rs b/src/postgres/protocol/decode.rs similarity index 100% rename from src/pg/protocol/decode.rs rename to src/postgres/protocol/decode.rs diff --git a/src/pg/protocol/describe.rs b/src/postgres/protocol/describe.rs similarity index 100% rename from src/pg/protocol/describe.rs rename to src/postgres/protocol/describe.rs diff --git a/src/pg/protocol/encode.rs b/src/postgres/protocol/encode.rs similarity index 100% rename from src/pg/protocol/encode.rs rename to src/postgres/protocol/encode.rs diff --git a/src/pg/protocol/execute.rs b/src/postgres/protocol/execute.rs similarity index 100% rename from src/pg/protocol/execute.rs rename to src/postgres/protocol/execute.rs diff --git a/src/pg/protocol/flush.rs b/src/postgres/protocol/flush.rs similarity index 100% rename from src/pg/protocol/flush.rs rename to src/postgres/protocol/flush.rs diff --git a/src/pg/protocol/message.rs b/src/postgres/protocol/message.rs similarity index 100% rename from src/pg/protocol/message.rs rename to src/postgres/protocol/message.rs diff --git a/src/pg/protocol/mod.rs b/src/postgres/protocol/mod.rs similarity index 100% rename from src/pg/protocol/mod.rs rename to src/postgres/protocol/mod.rs diff --git a/src/pg/protocol/notification_response.rs b/src/postgres/protocol/notification_response.rs similarity index 100% rename from src/pg/protocol/notification_response.rs rename to src/postgres/protocol/notification_response.rs diff --git a/src/pg/protocol/parameter_description.rs b/src/postgres/protocol/parameter_description.rs similarity index 100% rename from src/pg/protocol/parameter_description.rs rename to src/postgres/protocol/parameter_description.rs diff --git a/src/pg/protocol/parameter_status.rs b/src/postgres/protocol/parameter_status.rs similarity index 100% rename from src/pg/protocol/parameter_status.rs rename to src/postgres/protocol/parameter_status.rs diff --git a/src/pg/protocol/parse.rs b/src/postgres/protocol/parse.rs similarity index 100% rename from src/pg/protocol/parse.rs rename to src/postgres/protocol/parse.rs diff --git a/src/pg/protocol/password_message.rs b/src/postgres/protocol/password_message.rs similarity index 100% rename from src/pg/protocol/password_message.rs rename to src/postgres/protocol/password_message.rs diff --git a/src/pg/protocol/query.rs b/src/postgres/protocol/query.rs similarity index 100% rename from src/pg/protocol/query.rs rename to src/postgres/protocol/query.rs diff --git a/src/pg/protocol/ready_for_query.rs b/src/postgres/protocol/ready_for_query.rs similarity index 100% rename from src/pg/protocol/ready_for_query.rs rename to src/postgres/protocol/ready_for_query.rs diff --git a/src/pg/protocol/response.rs b/src/postgres/protocol/response.rs similarity index 100% rename from src/pg/protocol/response.rs rename to src/postgres/protocol/response.rs diff --git a/src/pg/protocol/row_description.rs b/src/postgres/protocol/row_description.rs similarity index 100% rename from src/pg/protocol/row_description.rs rename to src/postgres/protocol/row_description.rs diff --git a/src/pg/protocol/startup_message.rs b/src/postgres/protocol/startup_message.rs similarity index 100% rename from src/pg/protocol/startup_message.rs rename to src/postgres/protocol/startup_message.rs diff --git a/src/pg/protocol/sync.rs b/src/postgres/protocol/sync.rs similarity index 100% rename from src/pg/protocol/sync.rs rename to src/postgres/protocol/sync.rs diff --git a/src/pg/protocol/terminate.rs b/src/postgres/protocol/terminate.rs similarity index 100% rename from src/pg/protocol/terminate.rs rename to src/postgres/protocol/terminate.rs diff --git a/src/pg/query.rs b/src/postgres/query.rs similarity index 89% rename from src/pg/query.rs rename to src/postgres/query.rs index d3e9e12b..f57b80c2 100644 --- a/src/pg/query.rs +++ b/src/postgres/query.rs @@ -1,6 +1,6 @@ use super::{ protocol::{self, BufMut}, - Pg, PgRawConnection, + Postgres, PostgresRawConnection, }; use crate::{ query::RawQuery, @@ -9,7 +9,7 @@ use crate::{ }; use byteorder::{BigEndian, ByteOrder}; -pub struct PgRawQuery<'q> { +pub struct PostgresRawQuery<'q> { limit: i32, query: &'q str, // OIDs of the bind parameters @@ -18,8 +18,8 @@ pub struct PgRawQuery<'q> { buf: Vec, } -impl<'q> RawQuery<'q> for PgRawQuery<'q> { - type Backend = Pg; +impl<'q> RawQuery<'q> for PostgresRawQuery<'q> { + type Backend = Postgres; fn new(query: &'q str) -> Self { Self { @@ -41,7 +41,7 @@ impl<'q> RawQuery<'q> for PgRawQuery<'q> { // TODO: When/if we receive types that do _not_ support BINARY, we need to check here // TODO: There is no need to be explicit unless we are expecting mixed BINARY / TEXT - self.types.push(>::metadata().oid); + self.types.push(>::metadata().oid); let pos = self.buf.len(); self.buf.put_int_32(0); @@ -60,7 +60,7 @@ impl<'q> RawQuery<'q> for PgRawQuery<'q> { self } - fn finish(self, conn: &mut PgRawConnection) { + fn finish(self, conn: &mut PostgresRawConnection) { conn.write(protocol::Parse { portal: "", query: self.query, diff --git a/src/pg/row.rs b/src/postgres/row.rs similarity index 65% rename from src/pg/row.rs rename to src/postgres/row.rs index e2d7027f..9822af1a 100644 --- a/src/pg/row.rs +++ b/src/postgres/row.rs @@ -1,10 +1,10 @@ -use super::{protocol::DataRow, Pg}; +use super::{protocol::DataRow, Postgres}; use crate::row::Row; -pub struct PgRow(pub(crate) Box); +pub struct PostgresRow(pub(crate) Box); -impl Row for PgRow { - type Backend = Pg; +impl Row for PostgresRow { + type Backend = Postgres; #[inline] fn is_empty(&self) -> bool { diff --git a/src/pg/types/boolean.rs b/src/postgres/types/boolean.rs similarity index 62% rename from src/pg/types/boolean.rs rename to src/postgres/types/boolean.rs index 8935250e..f93a0082 100644 --- a/src/pg/types/boolean.rs +++ b/src/postgres/types/boolean.rs @@ -1,21 +1,21 @@ -use super::{Pg, PgTypeMetadata, PgTypeFormat}; +use super::{Postgres, PostgresTypeMetadata, PostgresTypeFormat}; use crate::{ deserialize::FromSql, serialize::{IsNull, ToSql}, types::HasSqlType, }; -impl HasSqlType for Pg { - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, +impl HasSqlType for Postgres { + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 16, array_oid: 1000, } } } -impl ToSql for bool { +impl ToSql for bool { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { buf.push(self as u8); @@ -24,7 +24,7 @@ impl ToSql for bool { } } -impl FromSql for bool { +impl FromSql for bool { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { // TODO: Handle optionals diff --git a/src/pg/types/character.rs b/src/postgres/types/character.rs similarity index 65% rename from src/pg/types/character.rs rename to src/postgres/types/character.rs index 60afbd18..8737dd28 100644 --- a/src/pg/types/character.rs +++ b/src/postgres/types/character.rs @@ -1,4 +1,4 @@ -use super::{Pg, PgTypeMetadata, PgTypeFormat}; +use super::{Postgres, PostgresTypeMetadata, PostgresTypeFormat}; use crate::{ deserialize::FromSql, serialize::{IsNull, ToSql}, @@ -6,25 +6,25 @@ use crate::{ }; use std::str; -impl HasSqlType<&'_ str> for Pg { +impl HasSqlType<&'_ str> for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 25, array_oid: 1009, } } } -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - >::metadata() + fn metadata() -> PostgresTypeMetadata { + >::metadata() } } -impl ToSql for &'_ str { +impl ToSql for &'_ str { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { buf.extend_from_slice(self.as_bytes()); @@ -33,14 +33,14 @@ impl ToSql for &'_ str { } } -impl ToSql for String { +impl ToSql for String { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { self.as_str().to_sql(buf) } } -impl FromSql for String { +impl FromSql for String { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { // TODO: Handle nulls diff --git a/src/pg/types/mod.rs b/src/postgres/types/mod.rs similarity index 90% rename from src/pg/types/mod.rs rename to src/postgres/types/mod.rs index e7a11121..892f4d18 100644 --- a/src/pg/types/mod.rs +++ b/src/postgres/types/mod.rs @@ -27,14 +27,14 @@ //! | `IpAddr` | INET | //! -use super::Pg; +use super::Postgres; use crate::types::TypeMetadata; mod boolean; mod character; mod numeric; -pub enum PgTypeFormat { +pub enum PostgresTypeFormat { Text = 0, Binary = 1, } @@ -44,12 +44,12 @@ pub enum PgTypeFormat { /// /// While the BINARY format is preferred in most cases, there are scenarios /// where only the TEXT format may be available for a type. -pub struct PgTypeMetadata { - pub format: PgTypeFormat, +pub struct PostgresTypeMetadata { + pub format: PostgresTypeFormat, pub oid: u32, pub array_oid: u32, } -impl TypeMetadata for Pg { - type TypeMetadata = PgTypeMetadata; +impl TypeMetadata for Postgres { + type TypeMetadata = PostgresTypeMetadata; } diff --git a/src/pg/types/numeric.rs b/src/postgres/types/numeric.rs similarity index 60% rename from src/pg/types/numeric.rs rename to src/postgres/types/numeric.rs index 7c289b22..2ad87602 100644 --- a/src/pg/types/numeric.rs +++ b/src/postgres/types/numeric.rs @@ -1,4 +1,4 @@ -use super::{Pg, PgTypeMetadata, PgTypeFormat}; +use super::{Postgres, PostgresTypeMetadata, PostgresTypeFormat}; use crate::{ deserialize::FromSql, serialize::{IsNull, ToSql}, @@ -6,18 +6,18 @@ use crate::{ }; use byteorder::{BigEndian, ByteOrder}; -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 21, array_oid: 1005, } } } -impl ToSql for i16 { +impl ToSql for i16 { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { buf.extend_from_slice(&self.to_be_bytes()); @@ -26,25 +26,25 @@ impl ToSql for i16 { } } -impl FromSql for i16 { +impl FromSql for i16 { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { BigEndian::read_i16(buf.unwrap()) } } -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 23, array_oid: 1007, } } } -impl ToSql for i32 { +impl ToSql for i32 { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { buf.extend_from_slice(&self.to_be_bytes()); @@ -53,25 +53,25 @@ impl ToSql for i32 { } } -impl FromSql for i32 { +impl FromSql for i32 { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { BigEndian::read_i32(buf.unwrap()) } } -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 20, array_oid: 1016, } } } -impl ToSql for i64 { +impl ToSql for i64 { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { buf.extend_from_slice(&self.to_be_bytes()); @@ -80,57 +80,57 @@ impl ToSql for i64 { } } -impl FromSql for i64 { +impl FromSql for i64 { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { BigEndian::read_i64(buf.unwrap()) } } -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 700, array_oid: 1021, } } } -impl ToSql for f32 { +impl ToSql for f32 { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { (self.to_bits() as i32).to_sql(buf) } } -impl FromSql for f32 { +impl FromSql for f32 { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { f32::from_bits(i32::from_sql(buf) as u32) } } -impl HasSqlType for Pg { +impl HasSqlType for Postgres { #[inline] - fn metadata() -> PgTypeMetadata { - PgTypeMetadata { - format: PgTypeFormat::Binary, + fn metadata() -> PostgresTypeMetadata { + PostgresTypeMetadata { + format: PostgresTypeFormat::Binary, oid: 701, array_oid: 1022, } } } -impl ToSql for f64 { +impl ToSql for f64 { #[inline] fn to_sql(self, buf: &mut Vec) -> IsNull { (self.to_bits() as i64).to_sql(buf) } } -impl FromSql for f64 { +impl FromSql for f64 { #[inline] fn from_sql(buf: Option<&[u8]>) -> Self { f64::from_bits(i64::from_sql(buf) as u64) diff --git a/src/types.rs b/src/types.rs index 0186b5af..23105b3b 100644 --- a/src/types.rs +++ b/src/types.rs @@ -33,21 +33,21 @@ pub trait HasSqlType: TypeMetadata { // Example of what that derive should generate -// impl HasSqlType for Pg { +// impl HasSqlType for Postgres { // #[inline] -// fn metadata() -> PgTypeMetadata { -// >::metadata() +// fn metadata() -> PostgresTypeMetadata { +// >::metadata() // } // } -// impl ToSql for Bool { +// impl ToSql for Bool { // #[inline] // fn to_sql(self, buf: &mut Vec) -> IsNull { // self.0.to_sql(buf) // } // } -// impl FromSql for bool { +// impl FromSql for bool { // #[inline] // fn from_sql(buf: Option<&[u8]>) -> Self { // Self(bool::from_sql(buf))