Utopia DSN
Data source names (connection strings), parsed into scheme, credentials, host, port, path and options.
This library is maintained by the Appwrite team.
Getting started
[]
= { = "https://github.com/appwrite/appwrite" }
A DSN (data source name) puts everything needed to reach a service in one string: scheme://user:password@host:port/path?query. Applications read them from configuration so a database, cache or provider can change without code changes. This guide covers the common tasks.
Read a connection string
Parse the string once, then read each part. A missing part is None (or empty for the path).
use Dsn;
let dsn = parse?;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Use credentials with special characters
Passwords often contain @, / or :, which have a meaning in a DSN. Percent-encode them in the string; the parser decodes them. Credentials are bytes in Rust, because a decoded password can be any bytes.
use Dsn;
let dsn = parse?;
assert_eq!;
let password = Stringfrom_utf8_lossy;
assert_eq!;
Keep secrets out of logs
Printing a DSN for debugging never shows its password, and errors never quote the string they refused.
use Dsn;
let dsn = parse?;
let logged = format!;
assert!;
assert!;
Read options from the query string
Settings that are not part of the address go in the query. Read one with param, or with param_or to fall back to a default.
use Dsn;
let dsn = parse?;
assert_eq!;
assert_eq!;
assert_eq!;
Configure a service from the environment
Read the DSN from an environment variable, with a default for local development, and pick an adapter by its scheme.
use Dsn;
let value = var.unwrap_or_else;
let dsn = parse?;
let adapter = match dsn.scheme ;
assert_eq!;
Reject invalid configuration
A DSN needs a scheme and a host. Anything else fails with an error you can report without exposing the value.
use ;
for value in
Contributing
Development happens in appwrite/appwrite, where this crate lives at crates/utopia/dsn. Run these commands from a checkout of it. The contributing guide covers each step.
Test
Compare with PHP
The utopia PHP extension serves this crate as Utopia\DSN\DSN, which no longer has a PHP implementation.
License
BSD-3-Clause. See LICENSE.