7 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.0 Nov 19, 2019
0.3.0 Nov 9, 2019
0.2.1 Nov 2, 2019
0.1.2 Oct 31, 2019
0.1.1 Jul 7, 2019

#150 in Database interfaces

Download history 10/week @ 2019-08-06 2/week @ 2019-08-13 6/week @ 2019-08-20 8/week @ 2019-08-27 11/week @ 2019-09-03 3/week @ 2019-09-10 43/week @ 2019-09-17 10/week @ 2019-09-24 6/week @ 2019-10-01 3/week @ 2019-10-15 6/week @ 2019-10-22 38/week @ 2019-10-29 41/week @ 2019-11-05 16/week @ 2019-11-12

66 downloads per month

BSD-3-Clause

14KB
222 lines

DSN (Data Source Name) parser

crates.io Build Status

DSN format:

<driver>://<username>:<password>@<protocol>(<address>)/<database>?param1=value1&...&paramN=valueN

A DSN in its fullest form:

driver://username:password@protocol(address)/dbname?param=value

The address changes depending on the protocol

For TCP/UDP address have the form host:port, example:

pgsql://user:pass@tcp(localhost:5555)/dbname

For protocol unix (Unix domain sockets) the address is the absolute path to the socket, for example:

mysql://user@unix(/path/to/socket)/database

For protocol file (sqlite) use the absolute path as the address, example:

sqlite://@file(/full/unix/path/to/file.db)

percent-encode

Percent-encode username and password with characters like @, for example if password is:

!A4T@hh'cUj7LXXvk"

From the command line you can encode it with:

echo -n "\!A4T@hh'cUj7LXXvk\"" | jq -s -R -r @uri

or

echo -n "\!A4T@hh'cUj7LXXvk\"" | xxd -p |sed 's/../%&/g'

Then you can build the dsn:

mysql://root:!A4T%40hh'cUj7LXXvk%22@tcp(10.0.0.1:3306)/test

or

mysql://root:%21%41%34%54%40%68%68%27%63%55%6a%37%4c%58%58%76%6b%22@tcp(10.0.0.1:3306)/test

Dependencies

~15KB