> Every UQL docs page, as Markdown: https://uql-orm.dev/llms.txt
> The same docs over MCP: https://uql-orm.dev/mcp
> Before writing UQL code, read the skill: https://uql-orm.dev/.well-known/agent-skills/uql-orm/SKILL.md

# Bun Native SQL

> Drive Bun's built-in SQL client with UQL, one pool for Postgres, MySQL, MariaDB and CockroachDB.

Source: https://uql-orm.dev/bun-sql

Under Bun, `uql-orm/bun-sql` drives Bun’s own SQL client, so you install no `pg` or `mysql2`. Entities, queries and [migrations](https://uql-orm.dev/migrations.md) stay the same.

```sh
bun add uql-orm
```

## Connect

`BunSqlQuerierPool` takes Bun’s `SQL.Options` and picks the dialect from them:

```ts
import { BunSqlQuerierPool } from 'uql-orm/bun-sql';

export const pool = new BunSqlQuerierPool({
  url: 'postgres://localhost:5432/app',
});
```

| URL scheme or `adapter` | Dialect UQL emits |
| - | - |
| `postgres://`, `postgresql://` | PostgreSQL |
| `mysql://`, `mysql2://` | MySQL |
| `mariadb://` | MariaDB |
| `cockroachdb://` | CockroachDB |

UQL emits each engine’s own SQL; only parameter binding is adapted for Bun. CockroachDB connects through Bun’s Postgres adapter while UQL keeps emitting [CockroachDB SQL](https://uql-orm.dev/cockroachdb.md).

> **Name the engine**
>
> Bun falls back to Postgres for any scheme it does not recognize, so a MySQL server reached through an unknown scheme would receive Postgres SQL. Use one of the schemes above, or set `adapter`. A SQL Server or SQLite URL throws and names the pool to use instead.

## Connections and raw SQL

Each querier reserves a dedicated connection from Bun’s pool and releases it when the querier is released. Inside a unit of work, run raw SQL with `querier.all` and `querier.run`. Outside one, `pool.sql` is Bun’s own client.

## SQLite

This pool does not drive SQLite. Use [`SqliteQuerierPool`](https://uql-orm.dev/sqlite.md), which uses `bun:sqlite` under Bun with nothing to install, and also streams, loads extensions and prepares statements:

```ts
import { SqliteQuerierPool } from 'uql-orm/sqlite';

const pool = new SqliteQuerierPool(':memory:');
```

## Streaming

Bun’s client has no cursor API, so on Postgres and CockroachDB `findManyStream` pages rows through a SQL cursor (`DECLARE` / `FETCH`). Memory stays flat, and the cursor closes when the loop ends, breaks or throws. A cursor needs a transaction, so a stream outside one opens its own.

On MySQL and MariaDB there is no cursor to reach, so the whole result is fetched first and then yielded row by row. To stream a large table there, use [`mysql2` or `mariadb`](https://uql-orm.dev/mysql.md). See [Streaming](https://uql-orm.dev/querying/streaming.md).
