25 releases

0.2.25 Jun 20, 2024
0.2.23 Mar 11, 2024
0.2.22 Sep 30, 2023
0.2.16 Jul 27, 2023
0.2.1 Jun 16, 2022

#781 in Database interfaces

Download history 22/week @ 2024-08-16 45/week @ 2024-08-23 77/week @ 2024-08-30 53/week @ 2024-09-06 43/week @ 2024-09-13 84/week @ 2024-09-20 30/week @ 2024-09-27 21/week @ 2024-10-04 19/week @ 2024-10-11 23/week @ 2024-10-18 15/week @ 2024-10-25 67/week @ 2024-11-01 11/week @ 2024-11-08 23/week @ 2024-11-15 52/week @ 2024-11-22 24/week @ 2024-11-29

123 downloads per month
Used in 8 crates (3 directly)

MIT/Apache

45KB
1K SLoC

mdsn

M-DSN: A Multi-address DSN(Data Source Name) parser.

M-DSN support two kind of DSN format:

  1. <driver>[+<protocol>]://<username>:<password>@<addresses>/<database>?<params>
  2. <driver>[+<protocol>]://<username>:<password>@<fragment>?<params>
  3. <driver>://<username>:<password>@<protocol>(<addresses>)/<database>?<params>

All the items will be parsed into struct Dsn.

Parser

use mdsn::Dsn;

// The two styles are equivalent.
let dsn = Dsn::parse("taos://root:taosdata@host1:6030,host2:6030/db")?;
let dsn: Dsn = "taos://root:taosdata@host1:6030,host2:6030/db".parse()?;

assert_eq!(dsn.driver, "taos");
assert_eq!(dsn.username.unwrap(), "root");
assert_eq!(dsn.password.unwrap(), "taosdata");
assert_eq!(dsn.database.unwrap(), "db");
assert_eq!(dsn.addresses.len(), 2);
assert_eq!(dsn.addresses, vec![
    mdsn::Address::new("host1", 6030),
    mdsn::Address::new("host2", 6030),
]);

DSN Examples

A DSN for TDengine driver taos.

taos://root:taosdata@localhost:6030/db?timezone=Asia/Shanghai&asyncLog=1

With multi-address:

taos://root:taosdata@host1:6030,host2:6030/db?timezone=Asia/Shanghai

A DSN for unix socket:

unix:///path/to/unix.sock?param1=value

A DSN for postgresql with url-encoded socket directory path.

postgresql://%2Fvar%2Flib%2Fpostgresql/db

A DSN for sqlite db file, note that you must use prefix ./ for a relative path file.

sqlite://./file.db

License: MIT OR Apache-2.0

Dependencies

~2.9–5MB
~88K SLoC