Connection and Ping
Every interaction with the database starts with Database.open(url), which returns
a Result<Database, DbError>. Use .unwrap() to get the handle (and crash loudly
on failure), or match / ? to handle the error gracefully. On failure the
DbError carries a kind (DbErrorKind::ConnectionFailed, …::QueryFailed, …),
a message, and the driver name.
defer db.close() ensures the connection is released at the end of the scope,
regardless of errors.
Opens SQLite in memory, calls db.ping() to confirm the connection is active,
and prints the recognized driver.
// Feature: Database — open a connection and ping
// Syntax: `Database.open("sqlite://:memory:").unwrap()` returns a handle.
// When to use: smoke test before using the connection; CI healthcheck.
use std::Database
let db = Database.open("sqlite://:memory:").unwrap()
defer db.close()
let ok = db.ping().unwrap()
print("ping: {ok}")
// expected: ping: true
print("driver: {db}")
// expected: driver: Database(sqlite)
Requires the Zolo CLI/host — open in the playground or run locally.
For Postgres or MySQL, just swap the URL:
Database.open("postgres://user:password@host/database")
Database.open("mysql://user:password@host/database")
Challenge
Try passing an invalid URL (e.g. "nope://invalid") and handle it with match,
printing e.kind and e.message. Which DbErrorKind do you get?
See also