> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nihalxkumar.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Other Databases

> Supported database backends for Zingat and how to configure them

# Other Databases

Zingat primarily targets PostgreSQL and SQLite, but the SQLx layer also supports other SQL backends. This page lists the commonly used alternatives and how to point Zingat at them.

<Tip>
  Choose PostgreSQL for production; prefer SQLite for lightweight, single-node deployments and tests.
</Tip>

## Environment variable

Zingat reads the connection string from the `DATABASE_URL` environment variable.

```bash theme={null}
# DEBUG: Point Zingat to a different database by changing DATABASE_URL
export DATABASE_URL="<driver>://<user>:<password>@<host>:<port>/<database>"
```

## PostgreSQL)

```bash theme={null}
# DEBUG: Standard Postgres connection string
export DATABASE_URL="postgres://user:password@localhost:5432/zingat"
```

* **Why use it**: Mature, robust, great concurrency, rich SQL features
* **Notes**: Ensure `sqlx` Postgres feature is enabled at build-time

## SQLite (lightweight)

```bash theme={null}
# DEBUG: File-backed SQLite database; suitable for single-node setups
export DATABASE_URL="sqlite://./zingat.db"
```

* **Why use it**: Zero-config, fast for small deployments and CI
* **Notes**: Concurrency is limited; prefer PostgreSQL for multi-user traffic

## MySQL / MariaDB

```bash theme={null}
# DEBUG: MySQL or MariaDB connection string
export DATABASE_URL="mysql://user:password@localhost:3306/zingat"
```

* **Why use it**: Existing infra or operational preference
* **Notes**: Ensure `sqlx` MySQL feature is enabled; verify SQL dialect differences

## Microsoft SQL Server

```bash theme={null}
# DEBUG: MSSQL connection string
export DATABASE_URL="mssql://user:password@localhost:1433;encrypt=true;TrustServerCertificate=true;database=zingat"
```

* **Why use it**: Enterprise environments standardized on SQL Server
* **Notes**: Some SQL features differ; test migrations and queries

## CockroachDB (Postgres wire-compatible)

```bash theme={null}
# DEBUG: CockroachDB uses Postgres wire protocol
export DATABASE_URL="postgres://user:password@localhost:26257/zingat?sslmode=disable"
```

* **Why use it**: Horizontal scalability with Postgres compatibility
* **Notes**: Validate transactional semantics and any `SERIAL`/`BIGSERIAL` usage

## Verify connectivity

Use `xh` to sanity-check the API after switching databases.

```bash theme={null}
# DEBUG: Health-check and simple API call with xh (project rule)
xh GET http://localhost:8000/health
xh POST http://localhost:8000/api/paste content='db test' expires_in:=60
```

## Migrations

Run migrations after changing `DATABASE_URL`:

```bash theme={null}
# DEBUG: Re-run SQLx migrations against the selected backend
cargo install sqlx-cli # if not installed
sqlx database create || true
sqlx migrate run
```

<Note>
  If you switch database engines, re-run migrations from a clean database to avoid dialect drift.
</Note>
