Skip to content

tRPC

UQL queries are plain JSON, so they pass through tRPC procedures without any adapter. There is nothing to install beyond your existing tRPC setup: procedures call the querier pool directly.

import { initTRPC } from '@trpc/server';
import { getQuerierPool } from 'uql-orm';
import type { Query, Type } from 'uql-orm/type';
import { User } from './shared/models/index.js';
const t = initTRPC.create();
const pool = getQuerierPool();
function passthrough<T>(): (value: unknown) => T {
return (value) => value as T;
}
function entityRouter<E extends object>(entity: Type<E>) {
return t.router({
findMany: t.procedure
.input(passthrough<Query<E>>())
.query(({ input }) => pool.findMany(entity, input)),
insertOne: t.procedure
.input(passthrough<E>())
.mutation(({ input }) => pool.transaction((querier) => querier.insertOne(entity, input))),
});
}
export const appRouter = t.router({
user: entityRouter(User),
});

On the client, the query object is fully typed end to end:

const users = await trpc.user.findMany.query({
$where: { email: { $endsWith: '@domain.com' } },
$limit: 10,
});