udsn 0.2.0

a [more] robust connection string URI parser/generator
Documentation
  • Coverage
  • 0%
    0 out of 28 items documented0 out of 18 items with examples
  • Size
  • Source code size: 30.64 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.04 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • tony-o/rust-udsn
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • tony-o

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.