Clean up for extra::url fixes

This commit is contained in:
Steven Fackler
2013-08-22 22:47:06 -04:00
parent 2b617e61b1
commit e5c5b783f3
2 changed files with 4 additions and 5 deletions

View File

@@ -23,11 +23,11 @@ impl Drop for PostgresConnection {
}
impl PostgresConnection {
pub fn connect(url: &str, username: &str) -> PostgresConnection {
pub fn connect(url: &str) -> PostgresConnection {
let parsed_url: Url = FromStr::from_str(url).unwrap();
let socket_url = fmt!("%s:%s", parsed_url.host,
parsed_url.port.unwrap_or_default(~"5432"));
parsed_url.port.get_ref().as_slice());
let addr: SocketAddr = FromStr::from_str(socket_url).unwrap();
let conn = PostgresConnection {
stream: Cell::new(TcpStream::connect(addr).unwrap()),
@@ -35,7 +35,7 @@ impl PostgresConnection {
};
let mut args = HashMap::new();
args.insert(&"user", username);
args.insert(&"user", parsed_url.user.get_ref().user.as_slice());
conn.write_message(&StartupMessage(args));
match conn.read_message() {

View File

@@ -4,8 +4,7 @@ use postgres::PostgresConnection;
#[test]
fn test_connect() {
let conn = PostgresConnection::connect("postgres://127.0.0.1:54322",
"postgres");
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
let stmt = conn.prepare("CREATE TABLE foo (id BIGINT PRIMARY KEY)");
stmt.query();