This commit is contained in:
Steven Fackler 2018-12-08 17:53:30 -08:00
parent b4ce9c38e5
commit 6ff59acdd2
8 changed files with 68 additions and 32 deletions

View File

@ -60,7 +60,8 @@ impl SqlState {{
&self.0 &self.0
}} }}
" "
).unwrap(); )
.unwrap();
} }
fn make_consts(codes: &LinkedHashMap<String, Vec<String>>, file: &mut BufWriter<File>) { fn make_consts(codes: &LinkedHashMap<String, Vec<String>>, file: &mut BufWriter<File>) {
@ -74,7 +75,8 @@ fn make_consts(codes: &LinkedHashMap<String, Vec<String>>, file: &mut BufWriter<
"#, "#,
name = name, name = name,
code = code, code = code,
).unwrap(); )
.unwrap();
} }
} }
@ -87,7 +89,8 @@ fn make_map(codes: &LinkedHashMap<String, Vec<String>>, file: &mut BufWriter<Fil
" "
#[cfg_attr(rustfmt, rustfmt_skip)] #[cfg_attr(rustfmt, rustfmt_skip)]
static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = " static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = "
).unwrap(); )
.unwrap();
let mut builder = phf_codegen::Map::new(); let mut builder = phf_codegen::Map::new();
for (code, names) in codes { for (code, names) in codes {
builder.entry(&**code, &format!("SqlState::{}", &names[0])); builder.entry(&**code, &format!("SqlState::{}", &names[0]));

View File

@ -132,7 +132,8 @@ pub struct Other {{
pub schema: String, pub schema: String,
}} }}
" "
).unwrap(); )
.unwrap();
} }
fn make_enum(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) { fn make_enum(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
@ -141,7 +142,8 @@ fn make_enum(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
" "
#[derive(PartialEq, Eq, Clone, Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub enum Inner {{" pub enum Inner {{"
).unwrap(); )
.unwrap();
for type_ in types.values() { for type_ in types.values() {
write!( write!(
@ -149,7 +151,8 @@ pub enum Inner {{"
" "
{},", {},",
type_.variant type_.variant
).unwrap(); )
.unwrap();
} }
write!( write!(
@ -159,7 +162,8 @@ pub enum Inner {{"
}} }}
" "
).unwrap(); )
.unwrap();
} }
fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) { fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
@ -169,7 +173,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn from_oid(oid: Oid) -> Option<Inner> {{ pub fn from_oid(oid: Oid) -> Option<Inner> {{
match oid {{ match oid {{
", ",
).unwrap(); )
.unwrap();
for (oid, type_) in types { for (oid, type_) in types {
write!( write!(
@ -177,7 +182,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
" {} => Some(Inner::{}), " {} => Some(Inner::{}),
", ",
oid, type_.variant oid, type_.variant
).unwrap(); )
.unwrap();
} }
write!( write!(
@ -189,7 +195,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn oid(&self) -> Oid {{ pub fn oid(&self) -> Oid {{
match *self {{ match *self {{
", ",
).unwrap(); )
.unwrap();
for (oid, type_) in types { for (oid, type_) in types {
write!( write!(
@ -197,7 +204,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
" Inner::{} => {}, " Inner::{} => {},
", ",
type_.variant, oid type_.variant, oid
).unwrap(); )
.unwrap();
} }
write!( write!(
@ -209,7 +217,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn kind(&self) -> &Kind {{ pub fn kind(&self) -> &Kind {{
match *self {{ match *self {{
", ",
).unwrap(); )
.unwrap();
for type_ in types.values() { for type_ in types.values() {
let kind = match type_.kind { let kind = match type_.kind {
@ -227,7 +236,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
}} }}
", ",
type_.variant, kind type_.variant, kind
).unwrap(); )
.unwrap();
} }
write!( write!(
@ -239,7 +249,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn name(&self) -> &str {{ pub fn name(&self) -> &str {{
match *self {{ match *self {{
"#, "#,
).unwrap(); )
.unwrap();
for type_ in types.values() { for type_ in types.values() {
write!( write!(
@ -247,7 +258,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
r#" Inner::{} => "{}", r#" Inner::{} => "{}",
"#, "#,
type_.variant, type_.name type_.variant, type_.name
).unwrap(); )
.unwrap();
} }
write!( write!(
@ -257,7 +269,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
}} }}
}} }}
" "
).unwrap(); )
.unwrap();
} }
fn make_consts(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) { fn make_consts(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
@ -272,7 +285,8 @@ fn make_consts(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
docs = type_.doc, docs = type_.doc,
ident = type_.ident, ident = type_.ident,
variant = type_.variant variant = type_.variant
).unwrap(); )
.unwrap();
} }
write!(w, "}}").unwrap(); write!(w, "}}").unwrap();

View File

@ -167,7 +167,10 @@ pub fn float8_from_sql(mut buf: &[u8]) -> Result<f64, StdBox<dyn Error + Sync +
/// Serializes an `HSTORE` value. /// Serializes an `HSTORE` value.
#[inline] #[inline]
pub fn hstore_to_sql<'a, I>(values: I, buf: &mut Vec<u8>) -> Result<(), StdBox<dyn Error + Sync + Send>> pub fn hstore_to_sql<'a, I>(
values: I,
buf: &mut Vec<u8>,
) -> Result<(), StdBox<dyn Error + Sync + Send>>
where where
I: IntoIterator<Item = (&'a str, Option<&'a str>)>, I: IntoIterator<Item = (&'a str, Option<&'a str>)>,
{ {
@ -228,7 +231,9 @@ impl<'a> FallibleIterator for HstoreEntries<'a> {
type Error = StdBox<dyn Error + Sync + Send>; type Error = StdBox<dyn Error + Sync + Send>;
#[inline] #[inline]
fn next(&mut self) -> Result<Option<(&'a str, Option<&'a str>)>, StdBox<dyn Error + Sync + Send>> { fn next(
&mut self,
) -> Result<Option<(&'a str, Option<&'a str>)>, StdBox<dyn Error + Sync + Send>> {
if self.remaining == 0 { if self.remaining == 0 {
if !self.buf.is_empty() { if !self.buf.is_empty() {
return Err("invalid buffer size".into()); return Err("invalid buffer size".into());
@ -288,7 +293,9 @@ where
/// Deserializes a `VARBIT` or `BIT` value. /// Deserializes a `VARBIT` or `BIT` value.
#[inline] #[inline]
pub fn varbit_from_sql<'a>(mut buf: &'a [u8]) -> Result<Varbit<'a>, StdBox<dyn Error + Sync + Send>> { pub fn varbit_from_sql<'a>(
mut buf: &'a [u8],
) -> Result<Varbit<'a>, StdBox<dyn Error + Sync + Send>> {
let len = buf.read_i32::<BigEndian>()?; let len = buf.read_i32::<BigEndian>()?;
if len < 0 { if len < 0 {
return Err("invalid varbit length".into()); return Err("invalid varbit length".into());
@ -1053,7 +1060,8 @@ mod test {
None => Ok(IsNull::Yes), None => Ok(IsNull::Yes),
}, },
&mut buf, &mut buf,
).unwrap(); )
.unwrap();
let array = array_from_sql(&buf).unwrap(); let array = array_from_sql(&buf).unwrap();
assert_eq!(array.has_nulls(), true); assert_eq!(array.has_nulls(), true);
@ -1089,7 +1097,8 @@ mod test {
None => Ok(IsNull::Yes), None => Ok(IsNull::Yes),
}, },
&mut buf, &mut buf,
).unwrap(); )
.unwrap();
let array = array_from_sql(&buf).unwrap(); let array = array_from_sql(&buf).unwrap();
assert_eq!(array.has_nulls(), false); assert_eq!(array.has_nulls(), false);

View File

@ -38,7 +38,8 @@ fn require() {
let connector = native_tls::TlsConnector::builder() let connector = native_tls::TlsConnector::builder()
.add_root_certificate( .add_root_certificate(
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(), Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
).build() )
.build()
.unwrap(); .unwrap();
smoke_test( smoke_test(
tokio_postgres::Builder::new() tokio_postgres::Builder::new()
@ -53,7 +54,8 @@ fn prefer() {
let connector = native_tls::TlsConnector::builder() let connector = native_tls::TlsConnector::builder()
.add_root_certificate( .add_root_certificate(
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(), Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
).build() )
.build()
.unwrap(); .unwrap();
smoke_test( smoke_test(
tokio_postgres::Builder::new() tokio_postgres::Builder::new()
@ -68,7 +70,8 @@ fn scram_user() {
let connector = native_tls::TlsConnector::builder() let connector = native_tls::TlsConnector::builder()
.add_root_certificate( .add_root_certificate(
Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(), Certificate::from_pem(include_bytes!("../../test/server.crt")).unwrap(),
).build() )
.build()
.unwrap(); .unwrap();
smoke_test( smoke_test(
tokio_postgres::Builder::new() tokio_postgres::Builder::new()

View File

@ -161,7 +161,12 @@ impl Client {
QueryStream::new(self.clone(), pending, portal.clone()) QueryStream::new(self.clone(), pending, portal.clone())
} }
pub fn copy_in<S>(&self, statement: &Statement, params: &[&dyn ToSql], stream: S) -> CopyInFuture<S> pub fn copy_in<S>(
&self,
statement: &Statement,
params: &[&dyn ToSql],
stream: S,
) -> CopyInFuture<S>
where where
S: Stream, S: Stream,
S::Item: IntoBuf, S::Item: IntoBuf,
@ -236,7 +241,11 @@ impl Client {
} }
} }
fn excecute_message(&self, statement: &Statement, params: &[&dyn ToSql]) -> Result<Vec<u8>, Error> { fn excecute_message(
&self,
statement: &Statement,
params: &[&dyn ToSql],
) -> Result<Vec<u8>, Error> {
let mut buf = self.bind_message(statement, "", params)?; let mut buf = self.bind_message(statement, "", params)?;
frontend::execute("", 0, &mut buf).map_err(Error::parse)?; frontend::execute("", 0, &mut buf).map_err(Error::parse)?;
frontend::sync(&mut buf); frontend::sync(&mut buf);

View File

@ -1,6 +1,4 @@
use chrono::{ use chrono::{DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
DateTime, Duration, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc,
};
use postgres_protocol::types; use postgres_protocol::types;
use std::error::Error; use std::error::Error;

View File

@ -1,5 +1,5 @@
use geo::{Coordinate, LineString, Point, Rect};
use fallible_iterator::FallibleIterator; use fallible_iterator::FallibleIterator;
use geo::{Coordinate, LineString, Point, Rect};
use postgres_protocol::types; use postgres_protocol::types;
use std::error::Error; use std::error::Error;

View File

@ -1,6 +1,6 @@
use uuid::Uuid;
use postgres_protocol::types; use postgres_protocol::types;
use std::error::Error; use std::error::Error;
use uuid::Uuid;
use types::{FromSql, IsNull, ToSql, Type}; use types::{FromSql, IsNull, ToSql, Type};