> 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

# TanStack Start

> Query UQL from TanStack Start server functions, and optionally serve entity CRUD from a catch-all server route.

Source: https://uql-orm.dev/tanstack-start

Server functions run on the server, so they query the pool directly. For CRUD routes across many entities, mount the [HTTP handler](https://uql-orm.dev/http.md) in a catch-all server route as well.

## Server functions

A UQL query is plain JSON, so it can be a server function’s input, typed end to end:

```ts
import { createServerFn } from '@tanstack/react-start';
import type { WireQuery } from 'uql-orm';
import { User } from './shared/models/index.js';
import { pool } from './uql.config.js';

export const listUsers = createServerFn({ method: 'GET' })
  .validator((query: WireQuery<User>) => query) // declares the type, checks nothing
  .handler(({ data }) => pool.findMany(User, data));

const users = await listUsers({
  data: {
    $select: { id: true, name: true },
    $where: { status: 'active' },
    $limit: 10,
  },
});
```

That validator trusts the caller. For untrusted callers, validate a few arguments with a schema and build the query on the server. For tenant isolation, run the handler inside `withContext` and declare a `security` [filter](https://uql-orm.dev/querying/filters.md) ([Multi-tenancy](https://uql-orm.dev/multi-tenancy.md)).

## Auto-generated CRUD

```ts title="src/routes/api/uql/$.ts"
import { createFileRoute } from '@tanstack/react-router';
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],
  basePath: '/api/uql',
});

export const Route = createFileRoute('/api/uql/$')({
  server: {
    handlers: {
      ANY: ({ request }: { request: Request }) => handler(request),
    },
  },
});
```

`ANY` answers every method no other handler names, [`QUERY`](https://uql-orm.dev/http.md#http-query-rfc-10008) included.
