From 2d4916ec2c4e7d95edc06c69bd9a858690d50b2f Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 4 Jan 2016 10:22:56 -0800 Subject: [PATCH 1/6] Update url dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a0a99c7a..5d9e5344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,4 +42,4 @@ security-framework = { version = "0.1.2", optional = true } bit-vec = { version = "0.4", optional = true } [dev-dependencies] -url = "0.2" +url = "0.5" From bd67e438c4f44a7d40e38a48b0bb08fa7398788b Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 22 Jan 2016 20:00:42 -0800 Subject: [PATCH 2/6] Add a Domain Kind This could break downstream code that expects a domain type to explicitly be a Simple Kind, but I doubt that exists. cc #153 --- src/lib.rs | 17 ++++++++++------ src/types/mod.rs | 2 ++ tests/test.rs | 1 + tests/types/mod.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 83bcccc3..e0f64681 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -462,7 +462,7 @@ impl InnerConnection { #[cfg_attr(rustfmt, rustfmt_skip)] fn setup_typeinfo_query(&mut self) -> result::Result<(), ConnectError> { match self.raw_prepare(TYPEINFO_QUERY, - "SELECT t.typname, t.typelem, r.rngsubtype, n.nspname \ + "SELECT t.typname, t.typelem, r.rngsubtype, t.typbasetype, n.nspname \ FROM pg_catalog.pg_type t \ LEFT OUTER JOIN pg_catalog.pg_range r ON \ r.rngtypid = t.oid \ @@ -478,7 +478,7 @@ impl InnerConnection { } match self.raw_prepare(TYPEINFO_QUERY, - "SELECT t.typname, t.typelem, NULL::OID, n.nspname \ + "SELECT t.typname, t.typelem, NULL::OID, t.typbasetype, n.nspname \ FROM pg_catalog.pg_type t \ INNER JOIN pg_catalog.pg_namespace n \ ON t.typnamespace = n.oid \ @@ -749,7 +749,7 @@ impl InnerConnection { } _ => bad_response!(self), } - let (name, elem_oid, rngsubtype, schema) = match try!(self.read_message()) { + let (name, elem_oid, rngsubtype, basetype, schema) = match try!(self.read_message()) { DataRow { row } => { let ctx = SessionInfo::new(self); let name = try!(String::from_sql(&Type::Name, @@ -762,10 +762,13 @@ impl InnerConnection { Some(ref data) => try!(Option::::from_sql(&Type::Oid, &mut &**data, &ctx)), None => try!(Option::::from_sql_null(&Type::Oid, &ctx)), }; + let basetype = try!(Oid::from_sql(&Type::Oid, + &mut &**row[3].as_ref().unwrap(), + &ctx)); let schema = try!(String::from_sql(&Type::Name, - &mut &**row[3].as_ref().unwrap(), + &mut &**row[4].as_ref().unwrap(), &ctx)); - (name, elem_oid, rngsubtype, schema) + (name, elem_oid, rngsubtype, basetype, schema) } ErrorResponse { fields } => { try!(self.wait_for_ready()); @@ -783,7 +786,9 @@ impl InnerConnection { } try!(self.wait_for_ready()); - let kind = if elem_oid != 0 { + let kind = if basetype != 0 { + Kind::Domain(try!(self.get_type(basetype))) + } else if elem_oid != 0 { Kind::Array(try!(self.get_type(elem_oid))) } else { match rngsubtype { diff --git a/src/types/mod.rs b/src/types/mod.rs index 91b02a29..ed488d59 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -107,6 +107,8 @@ pub enum Kind { Array(Type), /// A range type along with the type of its elements. Range(Type), + /// Domain type along with its underlying type. + Domain(Type), #[doc(hidden)] __PseudoPrivateForExtensibility, } diff --git a/tests/test.rs b/tests/test.rs index 79900443..c70fa0b1 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,3 +1,4 @@ +#[macro_use] extern crate postgres; extern crate url; #[cfg(feature = "openssl")] diff --git a/tests/types/mod.rs b/tests/types/mod.rs index 4ed0a7f7..9b7f7aee 100644 --- a/tests/types/mod.rs +++ b/tests/types/mod.rs @@ -2,10 +2,11 @@ use std::collections::HashMap; use std::f32; use std::f64; use std::fmt; +use std::io::{Read, Write}; -use postgres::{Connection, SslMode}; +use postgres::{Connection, SslMode, Result}; use postgres::error::Error; -use postgres::types::{ToSql, FromSql, Slice, WrongType}; +use postgres::types::{ToSql, FromSql, Slice, WrongType, Type, IsNull, Kind, SessionInfo}; #[cfg(feature = "bit-vec")] mod bit_vec; @@ -233,3 +234,48 @@ fn test_slice_range() { Err(e) => panic!("Unexpected error {:?}", e), }; } + +#[test] +fn domain() { + #[derive(Debug, PartialEq)] + struct SessionId(Vec); + + impl ToSql for SessionId { + fn to_sql(&self, ty: &Type, out: &mut W, ctx: &SessionInfo) -> Result + where W: Write + { + let inner = match *ty.kind() { + Kind::Domain(ref inner) => inner, + _ => unreachable!(), + }; + self.0.to_sql(inner, out, ctx) + } + + fn accepts(ty: &Type) -> bool { + ty.name() == "session_id" && match *ty.kind() { Kind::Domain(_) => true, _ => false } + } + + to_sql_checked!(); + } + + impl FromSql for SessionId { + fn from_sql(ty: &Type, raw: &mut R, ctx: &SessionInfo) -> Result { + Vec::::from_sql(ty, raw, ctx).map(SessionId) + } + + fn accepts(ty: &Type) -> bool { + // This is super weird! + as FromSql>::accepts(ty) + } + } + + let conn = Connection::connect("postgres://postgres@localhost", SslMode::None).unwrap(); + conn.batch_execute("CREATE DOMAIN pg_temp.session_id AS bytea CHECK(octet_length(VALUE) = 16); + CREATE TABLE pg_temp.foo (id pg_temp.session_id);") + .unwrap(); + + let id = SessionId(b"0123456789abcdef".to_vec()); + conn.execute("INSERT INTO pg_temp.foo (id) VALUES ($1)", &[&id]).unwrap(); + let rows = conn.query("SELECT id FROM pg_temp.foo", &[]).unwrap(); + assert_eq!(id, rows.get(0).get(0)); +} From 5f3ea95b795995d129e2625870ec694e5e2c48ad Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 22 Jan 2016 20:34:12 -0800 Subject: [PATCH 3/6] Bump minimum version to 1.5 --- .travis.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3c75575..521d5dc5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: required rust: - nightly - beta -- 1.4.0 +- 1.5.0 addons: postgresql: 9.4 before_script: diff --git a/README.md b/README.md index 364e32fc..a0ffcd8e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ fn main() { ``` ## Requirements -* **Rust** - Rust-Postgres is developed against the 1.4 release of Rust +* **Rust** - Rust-Postgres is developed against the 1.5 release of Rust available on http://www.rust-lang.org. It should also compile against more recent releases. From be18d8ad9089c2bcd7630c3699d930a0d3ab12a4 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 22 Jan 2016 21:22:05 -0800 Subject: [PATCH 4/6] Rustfmt --- src/md5.rs | 6 ++++-- src/types/mod.rs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/md5.rs b/src/md5.rs index 64a67c41..f5a21bc0 100644 --- a/src/md5.rs +++ b/src/md5.rs @@ -21,7 +21,8 @@ struct StepUp { ammount: T, } -impl Iterator for StepUp where T: Add + PartialOrd + Copy +impl Iterator for StepUp + where T: Add + PartialOrd + Copy { type Item = T; @@ -41,7 +42,8 @@ trait RangeExt { fn step_up(self, ammount: T) -> StepUp; } -impl RangeExt for Range where T: Add + PartialOrd + Copy +impl RangeExt for Range + where T: Add + PartialOrd + Copy { fn step_up(self, ammount: T) -> StepUp { StepUp { diff --git a/src/types/mod.rs b/src/types/mod.rs index ed488d59..b89e0210 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -891,7 +891,8 @@ pub trait ToSql: fmt::Debug { fn to_sql_checked(&self, ty: &Type, out: &mut Write, ctx: &SessionInfo) -> Result; } -impl<'a, T> ToSql for &'a T where T: ToSql +impl<'a, T> ToSql for &'a T + where T: ToSql { to_sql_checked!(); From 79d7d3629ce71e49bfb428cc2f48e4498ee4a752 Mon Sep 17 00:00:00 2001 From: kud1ing Date: Fri, 29 Jan 2016 08:52:01 +0100 Subject: [PATCH 5/6] add keywords to improve linkability on crates.io --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5d9e5344..44b07981 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ description = "A native PostgreSQL driver" repository = "https://github.com/sfackler/rust-postgres" documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.0/postgres" readme = "README.md" -keywords = ["database", "sql"] +keywords = ["database", "postgres", "postgresql", "sql"] build = "build.rs" include = ["src/*", "build.rs", "Cargo.toml", "LICENSE", "README.md", "THIRD_PARTY"] From c6773869520fb560750c40b7e1b82c830f8fcd95 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 1 Feb 2016 22:49:29 +0000 Subject: [PATCH 6/6] Release v0.11.1 --- Cargo.toml | 4 ++-- README.md | 2 +- src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44b07981..280ea974 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "postgres" -version = "0.11.0" +version = "0.11.1" authors = ["Steven Fackler "] license = "MIT" description = "A native PostgreSQL driver" repository = "https://github.com/sfackler/rust-postgres" -documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.0/postgres" +documentation = "https://sfackler.github.io/rust-postgres/doc/v0.11.1/postgres" readme = "README.md" keywords = ["database", "postgres", "postgresql", "sql"] build = "build.rs" diff --git a/README.md b/README.md index a0ffcd8e..99c3d063 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Rust-Postgres A native PostgreSQL driver for Rust. -[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.11.0/postgres) +[Documentation](https://sfackler.github.io/rust-postgres/doc/v0.11.1/postgres) [![Build Status](https://travis-ci.org/sfackler/rust-postgres.png?branch=master)](https://travis-ci.org/sfackler/rust-postgres) [![Latest Version](https://img.shields.io/crates/v/postgres.svg)](https://crates.io/crates/postgres) diff --git a/src/lib.rs b/src/lib.rs index e0f64681..a4581b32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ //! } //! } //! ``` -#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.0")] +#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc/v0.11.1")] #![warn(missing_docs)] extern crate bufstream;