udsn 0.2.1

a [more] robust connection string URI parser/generator
Documentation

uDSN

A quick little DSN parser that can give you a nice looking URI connection string on the other side:

use udsn::{DSN, Resource};

let dsn = DSN::new()
    .protocol("postgres"),       // protocol
    .username(Some("username")), // username
    .password(None),             // password
    .resource(Resource::URI("localhost".to_string())), // uri or localpath
    .host("localhost")           // convenience shortcut for .resource(Resource::URI...
    .path("/tmp/db.sqlite")      // convenience shortcut for .resourde(Resource::Path...
    .port(Some(5432)),           // port
    .database(Some("db_name")),  // dbname
    .params(                     // params
        Some(vec![
            ("sslmode",         Some("verify")),
            ("connect_timeout", Some("10"))
        ])
    );

dsn.to_string() == "postgresql://localhost/db?sslmode=verify-full&connect_timeout=10";

/* OR, parse and modify an existing */

let dsn = DSN::parse("postgresql://localhost/db?sslmode=verify-full&connect_timeout=10");

dsn.username = Some("user");
dsn.password = Some("pass");

dsn.to_string() == "postgresql://user:pass@localhost/db?sslmode=verify-full&connect_timeout=10";

/* as a bonus you can also use the percent encoder/decoder */

use udsn::{percent_encode, percent_decode};

percent_encode("/...") == "%2f...";
percent_decode("%2f...") == "/...";

Motivation

The motiviation for writing this module is that other DSN modules had various bugs, dependencies, or other weirdness. The most common being that odd characters would show up when using parameters (or no parameters) and upon looking at the tests, they tested the one use case they needed the module for. Or, they provided no documentation/examples.

So, here we are.