Skip to content
Using Rent

Database connections

Your application connects to its database through a connection URL. The first-app walkthrough uses a local SQLite file. For a server database, point Rent at PostgreSQL, MySQL, or MariaDB, whether it runs on your machine or with a hosting provider.

MariaDB uses the MySQL protocol and the same mysql Cargo feature.

When starting a new project, select its database with --database:

rent new social-app --database postgres
cd social-app

rent new writes the matching rent.toml, Cargo feature, connection example, and, except for SQLite, a local Compose service. Set DATABASE_URL in .env to an existing local or hosted server. If you choose the included container instead, start it with docker compose up -d --wait. Then run rent doctor to check the connection. Docker is optional.

A SQLite project is immediately usable and stores rent.db beside the application.

Compile only what you deploy

The generated manifest disables Rent's defaults and enables one database:

[dependencies]
rent = {
  git = "<repository URL supplied with preview access>",
  tag = "v0.7.2",
  default-features = false,
  features = ["postgres"],
}

Available database features are postgres, mysql, and sqlite. Select several only when the same binary must connect to several database families:

features = ["postgres", "sqlite"]

Code generation follows database.backends in rent.toml, so generated models do not mention disabled SQLx row types:

[database]
dialect = "postgres"
url_env = "DATABASE_URL"
backends = ["postgres"]

Changing the list requires both a Cargo feature change and rent generate.

Connection URLs

postgres://app:secret@db.internal:5432/application
mysql://app:secret@db.internal:3306/application
sqlite://application.db?mode=rwc

Keep credentials outside rent.toml. Put DATABASE_URL in the project-root .env for local development. Rent checks an explicit command override, the process environment, and then .env, in that order. The conventional variable name is DATABASE_URL, but url_env can select another name when an existing application requires it.

The generated client selects the correct driver from the URL:

let database_url = std::env::var("DATABASE_URL")?;
let client = generated::client::Client::connect(&database_url).await?;

Use Client::connect_with when you need to tune pool limits or timeouts. Applications no longer need to repeat a dialect enum beside a URL that already identifies the database.

Development containers versus supported databases

Docker Compose is a local development convenience, not a Rent dependency. Both development and production applications connect to a compatible server by URL. Supabase, TimescaleDB and ParadeDB are PostgreSQL distributions and use Rent's PostgreSQL backend.

For pool settings and TLS, see production deployment.