> 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

# Elysia

> Query UQL from your Elysia routes, and optionally mount entity CRUD with the fetch handler.

Source: https://uql-orm.dev/elysia

Your Elysia routes query the pool directly. If you also want CRUD routes for many entities without writing them, mount the [HTTP handler](https://uql-orm.dev/http.md). Elysia is fetch-native, so nothing else is needed.

## Your own routes

```ts
import { Elysia } from 'elysia';
import { Post } from './shared/models/index.js';
import { pool } from './uql.config.js';

new Elysia()
  .get('/posts', () =>
    pool.findMany(Post, { $where: { published: true }, $limit: 20 }),
  )
  .listen(3000); // Bun; on Node, `new Elysia({ adapter: node() })` from @elysiajs/node
```

[The pool](https://uql-orm.dev/http.md#the-pool) shows the `uql.config.ts` it comes from. Run several writes together in [`pool.transaction`](https://uql-orm.dev/querying/transactions.md).

## Auto-generated CRUD

```ts
import { cors } from '@elysiajs/cors';
import { Elysia } from 'elysia';
import { createFetchHandler } from 'uql-orm/http';
import { Post, User } from './shared/models/index.js';
import { pool } from './uql.config.js';

const handler = createFetchHandler({ pool, include: [User, Post] });

new Elysia().use(cors()).mount('/api', handler).listen(3000);
```

`.mount()` strips the prefix, forwards every method and leaves the body unparsed, so this serves the [wire protocol](https://uql-orm.dev/http.md#wire-protocol), [`QUERY`](https://uql-orm.dev/http.md#http-query-rfc-10008) included. An unknown route under `/api` is a `404` from the handler.

Hooks and tenant scoping are the handler’s: see [hooks](https://uql-orm.dev/http.md#authorization-hooks) and [`getContext`](https://uql-orm.dev/http.md#tenant-scoping). Their `context` is the web `Request`.

Eden Treaty cannot see mounted routes, so it keeps covering your own routes only. Use the [browser client](https://uql-orm.dev/browser.md) for the CRUD routes.
