[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › [local‑first/Schema](https://evolu.dev/docs/api-reference/common/local-first/Schema) › createQueryBuilder

```ts
function createQueryBuilder<S>(_schema: S): CreateQuery<S>;
```

Defined in: [packages/common/src/local-first/Schema.ts:482](https://github.com/evoluhq/evolu/blob/49ea8ca499566aba270f8cb601e7f49aa62320f8/packages/common/src/local-first/Schema.ts#L482)

Creates a query builder from a [EvoluSchema](https://evolu.dev/docs/api-reference/common/local-first/Schema/type-aliases/EvoluSchema).

Supports Kysely relation-style query composition (nested objects/arrays via
JSON subqueries), such as [evoluJsonObjectFrom](https://evolu.dev/docs/api-reference/common/local-first/Query/functions/evoluJsonObjectFrom) and
[evoluJsonArrayFrom](https://evolu.dev/docs/api-reference/common/local-first/Query/functions/evoluJsonArrayFrom). These helpers are Evolu's safer SQLite variants of
the
[Kysely relations recipe](https://kysely.dev/docs/recipes/relations).

### Example

```ts
import {
  createQueryBuilder,
  id,
  NonEmptyTrimmedString100,
  nullOr,
  SqliteBoolean,
} from "@evolu/common";

const TodoId = id("Todo");
type TodoId = typeof TodoId.Output;
const Schema = {
  todo: {
    id: TodoId,
    title: NonEmptyTrimmedString100,
    isCompleted: nullOr(SqliteBoolean),
  },
};

// Create one typed builder per schema and reuse it for every query.
const createQuery = createQueryBuilder(Schema);
const todosQuery = createQuery((db) =>
  db.selectFrom("todo").select(["id", "title", "isCompleted"]),
);

expectTypeOf<typeof todosQuery.Row>().toEqualTypeOf<{
  id: TodoId;
  title: NonEmptyTrimmedString100 | null;
  isCompleted: SqliteBoolean | null;
}>();
expect(todosQuery).toBeTypeOf("string");
```