Deserialize libpq-style connection strings
Just the key/value pair version for now - URLs will come later
This commit is contained in:
parent
10a850a527
commit
46f4a2911c
@ -10,6 +10,9 @@ readme = "../README.md"
|
|||||||
keywords = ["database", "postgres", "postgresql", "sql", "async"]
|
keywords = ["database", "postgres", "postgresql", "sql", "async"]
|
||||||
categories = ["database"]
|
categories = ["database"]
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
test = false
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = [
|
features = [
|
||||||
"with-bit-vec-0.5",
|
"with-bit-vec-0.5",
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::iter;
|
||||||
|
use std::str::{self, FromStr};
|
||||||
use tokio_io::{AsyncRead, AsyncWrite};
|
use tokio_io::{AsyncRead, AsyncWrite};
|
||||||
|
|
||||||
use crate::proto::ConnectFuture;
|
use crate::proto::ConnectFuture;
|
||||||
use crate::{Connect, TlsMode};
|
use crate::{Connect, Error, TlsMode};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
params: HashMap<String, String>,
|
params: HashMap<String, String>,
|
||||||
password: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Builder {
|
impl Default for Builder {
|
||||||
@ -22,18 +24,19 @@ impl Builder {
|
|||||||
params.insert("client_encoding".to_string(), "UTF8".to_string());
|
params.insert("client_encoding".to_string(), "UTF8".to_string());
|
||||||
params.insert("timezone".to_string(), "GMT".to_string());
|
params.insert("timezone".to_string(), "GMT".to_string());
|
||||||
|
|
||||||
Builder {
|
Builder { params }
|
||||||
params,
|
|
||||||
password: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user(&mut self, user: &str) -> &mut Builder {
|
pub fn user(&mut self, user: &str) -> &mut Builder {
|
||||||
self.param("user", user)
|
self.param("user", user)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn database(&mut self, database: &str) -> &mut Builder {
|
pub fn dbname(&mut self, database: &str) -> &mut Builder {
|
||||||
self.param("database", database)
|
self.param("dbname", database)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn password(&mut self, password: &str) -> &mut Builder {
|
||||||
|
self.param("password", password)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn param(&mut self, key: &str, value: &str) -> &mut Builder {
|
pub fn param(&mut self, key: &str, value: &str) -> &mut Builder {
|
||||||
@ -41,21 +44,162 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn password(&mut self, password: &str) -> &mut Builder {
|
|
||||||
self.password = Some(password.to_string());
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn connect<S, T>(&self, stream: S, tls_mode: T) -> Connect<S, T>
|
pub fn connect<S, T>(&self, stream: S, tls_mode: T) -> Connect<S, T>
|
||||||
where
|
where
|
||||||
S: AsyncRead + AsyncWrite,
|
S: AsyncRead + AsyncWrite,
|
||||||
T: TlsMode<S>,
|
T: TlsMode<S>,
|
||||||
{
|
{
|
||||||
Connect(ConnectFuture::new(
|
Connect(ConnectFuture::new(stream, tls_mode, self.params.clone()))
|
||||||
stream,
|
}
|
||||||
tls_mode,
|
}
|
||||||
self.password.clone(),
|
|
||||||
self.params.clone(),
|
impl FromStr for Builder {
|
||||||
))
|
type Err = Error;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Builder, Error> {
|
||||||
|
let mut parser = Parser::new(s);
|
||||||
|
let mut builder = Builder::new();
|
||||||
|
|
||||||
|
while let Some((key, value)) = parser.parameter()? {
|
||||||
|
builder.param(key, &value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(builder)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Parser<'a> {
|
||||||
|
s: &'a str,
|
||||||
|
it: iter::Peekable<str::CharIndices<'a>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Parser<'a> {
|
||||||
|
fn new(s: &'a str) -> Parser<'a> {
|
||||||
|
Parser {
|
||||||
|
s,
|
||||||
|
it: s.char_indices().peekable(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn skip_ws(&mut self) {
|
||||||
|
while let Some(&(_, ' ')) = self.it.peek() {
|
||||||
|
self.it.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn take_while<F>(&mut self, f: F) -> &'a str
|
||||||
|
where
|
||||||
|
F: Fn(char) -> bool,
|
||||||
|
{
|
||||||
|
let start = match self.it.peek() {
|
||||||
|
Some(&(i, _)) => i,
|
||||||
|
None => return "",
|
||||||
|
};
|
||||||
|
|
||||||
|
loop {
|
||||||
|
match self.it.peek() {
|
||||||
|
Some(&(_, c)) if f(c) => {
|
||||||
|
self.it.next();
|
||||||
|
}
|
||||||
|
Some(&(i, _)) => return &self.s[start..i],
|
||||||
|
None => return &self.s[start..],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn eat(&mut self, target: char) -> Result<(), Error> {
|
||||||
|
match self.it.next() {
|
||||||
|
Some((_, c)) if c == target => Ok(()),
|
||||||
|
Some((i, c)) => {
|
||||||
|
let m = format!(
|
||||||
|
"unexpected character at byte {}: expected `{}` but got `{}`",
|
||||||
|
i, target, c
|
||||||
|
);
|
||||||
|
Err(Error::connection_syntax(m.into()))
|
||||||
|
}
|
||||||
|
None => Err(Error::connection_syntax("unexpected EOF".into())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn eat_if(&mut self, target: char) -> bool {
|
||||||
|
match self.it.peek() {
|
||||||
|
Some(&(_, c)) if c == target => {
|
||||||
|
self.it.next();
|
||||||
|
true
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn keyword(&mut self) -> Option<&'a str> {
|
||||||
|
let s = self.take_while(|c| match c {
|
||||||
|
' ' | '=' => false,
|
||||||
|
_ => true,
|
||||||
|
});
|
||||||
|
|
||||||
|
if s.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value(&mut self) -> Result<Cow<'a, str>, Error> {
|
||||||
|
let raw = if self.eat_if('\'') {
|
||||||
|
let s = self.take_while(|c| c != '\'');
|
||||||
|
self.eat('\'')?;
|
||||||
|
s
|
||||||
|
} else {
|
||||||
|
let s = self.take_while(|c| c != ' ');
|
||||||
|
if s.is_empty() {
|
||||||
|
return Err(Error::connection_syntax("unexpected EOF".into()));
|
||||||
|
}
|
||||||
|
s
|
||||||
|
};
|
||||||
|
|
||||||
|
self.unescape_value(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unescape_value(&mut self, raw: &'a str) -> Result<Cow<'a, str>, Error> {
|
||||||
|
if !raw.contains('\\') {
|
||||||
|
return Ok(Cow::Borrowed(raw));
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut s = String::with_capacity(raw.len());
|
||||||
|
|
||||||
|
let mut it = raw.chars();
|
||||||
|
while let Some(c) = it.next() {
|
||||||
|
let to_push = if c == '\\' {
|
||||||
|
match it.next() {
|
||||||
|
Some('\'') => '\'',
|
||||||
|
Some('\\') => '\\',
|
||||||
|
Some(c) => {
|
||||||
|
return Err(Error::connection_syntax(
|
||||||
|
format!("invalid escape `\\{}`", c).into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
None => return Err(Error::connection_syntax("unexpected EOF".into())),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c
|
||||||
|
};
|
||||||
|
s.push(to_push);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Cow::Owned(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parameter(&mut self) -> Result<Option<(&'a str, Cow<'a, str>)>, Error> {
|
||||||
|
self.skip_ws();
|
||||||
|
let keyword = match self.keyword() {
|
||||||
|
Some(keyword) => keyword,
|
||||||
|
None => return Ok(None),
|
||||||
|
};
|
||||||
|
self.skip_ws();
|
||||||
|
self.eat('=')?;
|
||||||
|
self.skip_ws();
|
||||||
|
let value = self.value()?;
|
||||||
|
|
||||||
|
Ok(Some((keyword, value)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -345,6 +345,7 @@ enum Kind {
|
|||||||
MissingPassword,
|
MissingPassword,
|
||||||
UnsupportedAuthentication,
|
UnsupportedAuthentication,
|
||||||
Authentication,
|
Authentication,
|
||||||
|
ConnectionSyntax,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ErrorInner {
|
struct ErrorInner {
|
||||||
@ -381,6 +382,7 @@ impl fmt::Display for Error {
|
|||||||
Kind::MissingPassword => "password not provided",
|
Kind::MissingPassword => "password not provided",
|
||||||
Kind::UnsupportedAuthentication => "unsupported authentication method requested",
|
Kind::UnsupportedAuthentication => "unsupported authentication method requested",
|
||||||
Kind::Authentication => "authentication error",
|
Kind::Authentication => "authentication error",
|
||||||
|
Kind::ConnectionSyntax => "invalid connection string",
|
||||||
};
|
};
|
||||||
fmt.write_str(s)?;
|
fmt.write_str(s)?;
|
||||||
if let Some(ref cause) = self.0.cause {
|
if let Some(ref cause) = self.0.cause {
|
||||||
@ -479,4 +481,8 @@ impl Error {
|
|||||||
pub(crate) fn authentication(e: io::Error) -> Error {
|
pub(crate) fn authentication(e: io::Error) -> Error {
|
||||||
Error::new(Kind::Authentication, Some(Box::new(e)))
|
Error::new(Kind::Authentication, Some(Box::new(e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn connection_syntax(e: Box<dyn error::Error + Sync + Send>) -> Error {
|
||||||
|
Error::new(Kind::ConnectionSyntax, Some(e))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ where
|
|||||||
#[state_machine_future(start, transitions(SendingStartup))]
|
#[state_machine_future(start, transitions(SendingStartup))]
|
||||||
Start {
|
Start {
|
||||||
future: TlsFuture<S, T>,
|
future: TlsFuture<S, T>,
|
||||||
password: Option<String>,
|
|
||||||
params: HashMap<String, String>,
|
params: HashMap<String, String>,
|
||||||
},
|
},
|
||||||
#[state_machine_future(transitions(ReadingAuth))]
|
#[state_machine_future(transitions(ReadingAuth))]
|
||||||
@ -80,6 +79,14 @@ where
|
|||||||
let (stream, channel_binding) = try_ready!(state.future.poll());
|
let (stream, channel_binding) = try_ready!(state.future.poll());
|
||||||
let mut state = state.take();
|
let mut state = state.take();
|
||||||
|
|
||||||
|
// we don't want to send the password as a param
|
||||||
|
let password = state.params.remove("password");
|
||||||
|
|
||||||
|
// libpq uses the parameter "dbname" but the protocol expects "database" (!?!)
|
||||||
|
if let Some(dbname) = state.params.remove("dbname") {
|
||||||
|
state.params.insert("database".to_string(), dbname);
|
||||||
|
}
|
||||||
|
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
frontend::startup_message(state.params.iter().map(|(k, v)| (&**k, &**v)), &mut buf)
|
frontend::startup_message(state.params.iter().map(|(k, v)| (&**k, &**v)), &mut buf)
|
||||||
.map_err(Error::encode)?;
|
.map_err(Error::encode)?;
|
||||||
@ -94,7 +101,7 @@ where
|
|||||||
transition!(SendingStartup {
|
transition!(SendingStartup {
|
||||||
future: stream.send(buf),
|
future: stream.send(buf),
|
||||||
user,
|
user,
|
||||||
password: state.password,
|
password,
|
||||||
channel_binding,
|
channel_binding,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -317,12 +324,7 @@ where
|
|||||||
S: AsyncRead + AsyncWrite,
|
S: AsyncRead + AsyncWrite,
|
||||||
T: TlsMode<S>,
|
T: TlsMode<S>,
|
||||||
{
|
{
|
||||||
pub fn new(
|
pub fn new(stream: S, tls_mode: T, params: HashMap<String, String>) -> ConnectFuture<S, T> {
|
||||||
stream: S,
|
Connect::start(TlsFuture::new(stream, tls_mode), params)
|
||||||
tls_mode: T,
|
|
||||||
password: Option<String>,
|
|
||||||
params: HashMap<String, String>,
|
|
||||||
) -> ConnectFuture<S, T> {
|
|
||||||
Connect::start(TlsFuture::new(stream, tls_mode), password, params)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,19 +16,19 @@ use tokio_postgres::{AsyncMessage, Client, Connection, NoTls};
|
|||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
fn connect(
|
fn connect(
|
||||||
builder: &tokio_postgres::Builder,
|
s: &str,
|
||||||
) -> impl Future<Item = (Client, Connection<TcpStream>), Error = tokio_postgres::Error> {
|
) -> impl Future<Item = (Client, Connection<TcpStream>), Error = tokio_postgres::Error> {
|
||||||
let builder = builder.clone();
|
let builder = s.parse::<tokio_postgres::Builder>().unwrap();
|
||||||
TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
|
TcpStream::connect(&"127.0.0.1:5433".parse().unwrap())
|
||||||
.map_err(|e| panic!("{}", e))
|
.map_err(|e| panic!("{}", e))
|
||||||
.and_then(move |s| builder.connect(s, NoTls))
|
.and_then(move |s| builder.connect(s, NoTls))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn smoke_test(builder: &tokio_postgres::Builder) {
|
fn smoke_test(s: &str) {
|
||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(builder);
|
let handshake = connect(s);
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
@ -51,11 +51,7 @@ fn plain_password_missing() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=pass_user dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("pass_user")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
runtime.block_on(handshake).err().unwrap();
|
runtime.block_on(handshake).err().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,12 +60,7 @@ fn plain_password_wrong() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=pass_user password=foo dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("pass_user")
|
|
||||||
.password("foo")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
match runtime.block_on(handshake) {
|
match runtime.block_on(handshake) {
|
||||||
Ok(_) => panic!("unexpected success"),
|
Ok(_) => panic!("unexpected success"),
|
||||||
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
||||||
@ -79,12 +70,7 @@ fn plain_password_wrong() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn plain_password_ok() {
|
fn plain_password_ok() {
|
||||||
smoke_test(
|
smoke_test("user=pass_user password=password dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("pass_user")
|
|
||||||
.password("password")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -92,11 +78,7 @@ fn md5_password_missing() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=md5_user dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("md5_user")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
runtime.block_on(handshake).err().unwrap();
|
runtime.block_on(handshake).err().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,12 +87,7 @@ fn md5_password_wrong() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=md5_user password=foo dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("md5_user")
|
|
||||||
.password("foo")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
match runtime.block_on(handshake) {
|
match runtime.block_on(handshake) {
|
||||||
Ok(_) => panic!("unexpected success"),
|
Ok(_) => panic!("unexpected success"),
|
||||||
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
||||||
@ -120,12 +97,7 @@ fn md5_password_wrong() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn md5_password_ok() {
|
fn md5_password_ok() {
|
||||||
smoke_test(
|
smoke_test("user=md5_user password=password dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("md5_user")
|
|
||||||
.password("password")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -133,11 +105,7 @@ fn scram_password_missing() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=scram_user dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("scram_user")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
runtime.block_on(handshake).err().unwrap();
|
runtime.block_on(handshake).err().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,12 +114,7 @@ fn scram_password_wrong() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(
|
let handshake = connect("user=scram_user password=foo dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("scram_user")
|
|
||||||
.password("foo")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
match runtime.block_on(handshake) {
|
match runtime.block_on(handshake) {
|
||||||
Ok(_) => panic!("unexpected success"),
|
Ok(_) => panic!("unexpected success"),
|
||||||
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
Err(ref e) if e.code() == Some(&SqlState::INVALID_PASSWORD) => {}
|
||||||
@ -161,12 +124,7 @@ fn scram_password_wrong() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn scram_password_ok() {
|
fn scram_password_ok() {
|
||||||
smoke_test(
|
smoke_test("user=scram_user password=password dbname=postgres");
|
||||||
tokio_postgres::Builder::new()
|
|
||||||
.user("scram_user")
|
|
||||||
.password("password")
|
|
||||||
.database("postgres"),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -174,9 +132,7 @@ fn pipelined_prepare() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -194,9 +150,7 @@ fn insert_select() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -228,9 +182,7 @@ fn query_portal() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -270,9 +222,7 @@ fn cancel_query() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let cancel_data = connection.cancel_data();
|
let cancel_data = connection.cancel_data();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
@ -306,9 +256,7 @@ fn custom_enum() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -342,9 +290,7 @@ fn custom_domain() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -367,9 +313,7 @@ fn custom_array() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -392,9 +336,7 @@ fn custom_composite() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -431,9 +373,7 @@ fn custom_range() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -459,9 +399,7 @@ fn custom_simple() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -478,9 +416,7 @@ fn notifications() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, mut connection) = runtime
|
let (mut client, mut connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let (tx, rx) = mpsc::unbounded();
|
let (tx, rx) = mpsc::unbounded();
|
||||||
let connection = future::poll_fn(move || {
|
let connection = future::poll_fn(move || {
|
||||||
@ -524,9 +460,7 @@ fn transaction_commit() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -559,9 +493,7 @@ fn transaction_abort() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -596,9 +528,7 @@ fn copy_in() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -641,9 +571,7 @@ fn copy_in_error() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -682,9 +610,7 @@ fn copy_out() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
@ -713,9 +639,7 @@ fn transaction_builder_around_moved_client() {
|
|||||||
let _ = env_logger::try_init();
|
let _ = env_logger::try_init();
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let (mut client, connection) = runtime
|
let (mut client, connection) = runtime.block_on(connect("user=postgres")).unwrap();
|
||||||
.block_on(connect(tokio_postgres::Builder::new().user("postgres")))
|
|
||||||
.unwrap();
|
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.handle().spawn(connection).unwrap();
|
runtime.handle().spawn(connection).unwrap();
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ where
|
|||||||
{
|
{
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -190,7 +190,7 @@ fn test_text_params() {
|
|||||||
fn test_borrowed_text() {
|
fn test_borrowed_text() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -207,7 +207,7 @@ fn test_borrowed_text() {
|
|||||||
fn test_bpchar_params() {
|
fn test_bpchar_params() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -240,7 +240,7 @@ fn test_bpchar_params() {
|
|||||||
fn test_citext_params() {
|
fn test_citext_params() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -286,7 +286,7 @@ fn test_bytea_params() {
|
|||||||
fn test_borrowed_bytea() {
|
fn test_borrowed_bytea() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -345,7 +345,7 @@ where
|
|||||||
{
|
{
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -372,7 +372,7 @@ fn test_f64_nan_param() {
|
|||||||
fn test_pg_database_datname() {
|
fn test_pg_database_datname() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -388,7 +388,7 @@ fn test_pg_database_datname() {
|
|||||||
fn test_slice() {
|
fn test_slice() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -419,7 +419,7 @@ fn test_slice() {
|
|||||||
fn test_slice_wrong_type() {
|
fn test_slice_wrong_type() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -445,7 +445,7 @@ fn test_slice_wrong_type() {
|
|||||||
fn test_slice_range() {
|
fn test_slice_range() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -502,7 +502,7 @@ fn domain() {
|
|||||||
|
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -531,7 +531,7 @@ fn domain() {
|
|||||||
fn composite() {
|
fn composite() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
@ -566,7 +566,7 @@ fn composite() {
|
|||||||
fn enum_() {
|
fn enum_() {
|
||||||
let mut runtime = Runtime::new().unwrap();
|
let mut runtime = Runtime::new().unwrap();
|
||||||
|
|
||||||
let handshake = connect(tokio_postgres::Builder::new().user("postgres"));
|
let handshake = connect("user=postgres");
|
||||||
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
let (mut client, connection) = runtime.block_on(handshake).unwrap();
|
||||||
let connection = connection.map_err(|e| panic!("{}", e));
|
let connection = connection.map_err(|e| panic!("{}", e));
|
||||||
runtime.spawn(connection);
|
runtime.spawn(connection);
|
||||||
|
Loading…
Reference in New Issue
Block a user