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
}}
"
).unwrap();
)
.unwrap();
}
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,
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)]
static SQLSTATE_MAP: phf::Map<&'static str, SqlState> = "
).unwrap();
)
.unwrap();
let mut builder = phf_codegen::Map::new();
for (code, names) in codes {
builder.entry(&**code, &format!("SqlState::{}", &names[0]));

View File

@ -132,7 +132,8 @@ pub struct Other {{
pub schema: String,
}}
"
).unwrap();
)
.unwrap();
}
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)]
pub enum Inner {{"
).unwrap();
)
.unwrap();
for type_ in types.values() {
write!(
@ -149,7 +151,8 @@ pub enum Inner {{"
"
{},",
type_.variant
).unwrap();
)
.unwrap();
}
write!(
@ -159,7 +162,8 @@ pub enum Inner {{"
}}
"
).unwrap();
)
.unwrap();
}
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> {{
match oid {{
",
).unwrap();
)
.unwrap();
for (oid, type_) in types {
write!(
@ -177,7 +182,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
" {} => Some(Inner::{}),
",
oid, type_.variant
).unwrap();
)
.unwrap();
}
write!(
@ -189,7 +195,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn oid(&self) -> Oid {{
match *self {{
",
).unwrap();
)
.unwrap();
for (oid, type_) in types {
write!(
@ -197,7 +204,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
" Inner::{} => {},
",
type_.variant, oid
).unwrap();
)
.unwrap();
}
write!(
@ -209,7 +217,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn kind(&self) -> &Kind {{
match *self {{
",
).unwrap();
)
.unwrap();
for type_ in types.values() {
let kind = match type_.kind {
@ -227,7 +236,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
}}
",
type_.variant, kind
).unwrap();
)
.unwrap();
}
write!(
@ -239,7 +249,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
pub fn name(&self) -> &str {{
match *self {{
"#,
).unwrap();
)
.unwrap();
for type_ in types.values() {
write!(
@ -247,7 +258,8 @@ fn make_impl(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
r#" Inner::{} => "{}",
"#,
type_.variant, type_.name
).unwrap();
)
.unwrap();
}
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>) {
@ -272,7 +285,8 @@ fn make_consts(w: &mut BufWriter<File>, types: &BTreeMap<u32, Type>) {
docs = type_.doc,
ident = type_.ident,
variant = type_.variant
).unwrap();
)
.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.
#[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
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>;
#[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.buf.is_empty() {
return Err("invalid buffer size".into());
@ -288,7 +293,9 @@ where
/// Deserializes a `VARBIT` or `BIT` value.
#[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>()?;
if len < 0 {
return Err("invalid varbit length".into());
@ -1053,7 +1060,8 @@ mod test {
None => Ok(IsNull::Yes),
},
&mut buf,
).unwrap();
)
.unwrap();
let array = array_from_sql(&buf).unwrap();
assert_eq!(array.has_nulls(), true);
@ -1089,7 +1097,8 @@ mod test {
None => Ok(IsNull::Yes),
},
&mut buf,
).unwrap();
)
.unwrap();
let array = array_from_sql(&buf).unwrap();
assert_eq!(array.has_nulls(), false);

View File

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

View File

@ -161,7 +161,12 @@ impl Client {
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
S: Stream,
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)?;
frontend::execute("", 0, &mut buf).map_err(Error::parse)?;
frontend::sync(&mut buf);

View File

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

View File

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

View File

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