Skip to content

Elysia

Elysia is fetch-native, so it mounts UQL’s HTTP transport core directly. createFetchHandler returns a web-standard (request: Request) => Promise<Response>, and .mount() binds it to a prefix and strips that prefix before the handler sees the request. There is nothing to install beyond uql-orm.

import { Elysia } from 'elysia';
import { createFetchHandler } from 'uql-orm/http';
import './uql.config.js'; // setQuerierPool + entity imports
import { User, Post } from './shared/models/index.js';
const handler = createFetchHandler({ include: [User, Post] });
new Elysia().mount('/api', handler).listen(3000);

This mounts the full wire protocol for each entity (list, get, count, create, upsert, bulk operations, delete) plus the QUERY transport. Because .mount() forwards every method to the handler, the QUERY method works here without extra routing (unlike Next.js route handlers).

.mount() only claims the /api prefix, so your own Elysia routes, plugins, and lifecycle hooks live side by side with the generated CRUD. Keep hand-written routes for read-modify-write logic, multi-entity transactions, aggregations, file uploads, and streaming:

import { cors } from '@elysiajs/cors';
new Elysia()
.use(cors())
.get('/health', () => 'ok')
.post('/checkout', ({ body }) => runCheckout(body)) // custom business logic
.mount('/api', handler) // entity CRUD under /api
.listen(3000);

createFetchHandler accepts the core’s pre, preSave, preFilter, and post hooks. The hook context is the web Request, so read auth and tenant state from its headers:

const handler = createFetchHandler({
include: [User, Post],
async preFilter({ query, context }) {
// context is the web Request; abort by throwing with a numeric status
const user = await authenticate(context.headers.get('authorization'));
if (!user) {
throw Object.assign(new Error('unauthorized'), { status: 401 });
}
query.$where ??= {};
Object.assign(query.$where, { creatorId: user.id });
},
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.