diff --git a/examples/angular-vite-pwa/src/app/app.service.ts b/examples/angular-vite-pwa/src/app/app.service.ts index ecdf833ff..4a8320502 100644 --- a/examples/angular-vite-pwa/src/app/app.service.ts +++ b/examples/angular-vite-pwa/src/app/app.service.ts @@ -2,14 +2,14 @@ import { Injectable, inject, type OnDestroy, signal } from "@angular/core"; import { type InferRow, Mnemonic, type Query, type Row } from "@evolu/common"; import { EVOLU } from "./app.config"; import { formatTypeError } from "./error-formatter"; -import type { TodoId } from "./schema"; +import { createQuery, type TodoId } from "./schema"; @Injectable({ providedIn: "root" }) export class AppService implements OnDestroy { private readonly evolu = inject(EVOLU); private readonly unsubscribes: Array<() => void> = []; - private readonly todosQuery = this.evolu.createQuery((db) => + private readonly todosQuery = createQuery((db) => db .selectFrom("todo") .select(["id", "title", "isCompleted"]) diff --git a/examples/angular-vite-pwa/src/app/schema.ts b/examples/angular-vite-pwa/src/app/schema.ts index cbdd38bba..d626c41be 100644 --- a/examples/angular-vite-pwa/src/app/schema.ts +++ b/examples/angular-vite-pwa/src/app/schema.ts @@ -4,6 +4,7 @@ import { NonEmptyString100, nullOr, SqliteBoolean, + createQueryBuilder, } from "@evolu/common"; // Define the typed IDs @@ -19,3 +20,6 @@ const TodoSchema = { export const Schema = { todo: TodoSchema, } satisfies EvoluSchema; + +// Create a query builder (once per schema). +export const createQuery = createQueryBuilder(Schema); diff --git a/examples/react-electron/components/EvoluMinimalExample.tsx b/examples/react-electron/components/EvoluMinimalExample.tsx index 231bdc1d3..c60d2cd96 100644 --- a/examples/react-electron/components/EvoluMinimalExample.tsx +++ b/examples/react-electron/components/EvoluMinimalExample.tsx @@ -74,8 +74,11 @@ export const EvoluMinimalExample: FC = () => { ); }; +// Create a query builder (once per schema). +const createQuery = Evolu.createQueryBuilder(Schema); + // Evolu uses Kysely for type-safe SQL (https://kysely.dev/). -const todosQuery = evolu.createQuery((db) => +const todosQuery = createQuery((db) => db // Type-safe SQL: try autocomplete for table and column names. .selectFrom("todo") diff --git a/examples/react-expo/app/index.tsx b/examples/react-expo/app/index.tsx index 2cda2fe9a..0813afd7f 100644 --- a/examples/react-expo/app/index.tsx +++ b/examples/react-expo/app/index.tsx @@ -107,8 +107,11 @@ const EvoluDemo = ({ }): React.ReactNode => { const useEvolu = createUseEvolu(evolu); + // Create a query builder (once per schema). + const createQuery = Evolu.createQueryBuilder(Schema); + // Evolu uses Kysely for type-safe SQL (https://kysely.dev/). - const todosQuery = evolu.createQuery((db) => + const todosQuery = createQuery((db) => db // Type-safe SQL: try autocomplete for table and column names. .selectFrom("todo") diff --git a/examples/react-nextjs/components/EvoluMinimalExample.tsx b/examples/react-nextjs/components/EvoluMinimalExample.tsx index d72c1a21c..c640e996a 100644 --- a/examples/react-nextjs/components/EvoluMinimalExample.tsx +++ b/examples/react-nextjs/components/EvoluMinimalExample.tsx @@ -76,8 +76,11 @@ export const EvoluMinimalExample: FC = () => { ); }; +// Create a query builder (once per schema). +const createQuery = Evolu.createQueryBuilder(Schema); + // Evolu uses Kysely for type-safe SQL (https://kysely.dev/). -const todosQuery = evolu.createQuery((db) => +const todosQuery = createQuery((db) => db // Type-safe SQL: try autocomplete for table and column names. .selectFrom("todo") diff --git a/examples/react-vite-pwa/src/components/EvoluMinimalExample.tsx b/examples/react-vite-pwa/src/components/EvoluMinimalExample.tsx index 5a83571c2..fb45633bb 100644 --- a/examples/react-vite-pwa/src/components/EvoluMinimalExample.tsx +++ b/examples/react-vite-pwa/src/components/EvoluMinimalExample.tsx @@ -86,8 +86,11 @@ export const EvoluMinimalExample: FC = () => { ); }; +// Create a query builder (once per schema). +const createQuery = Evolu.createQueryBuilder(Schema); + // Evolu uses Kysely for type-safe SQL (https://kysely.dev/). -const todosQuery = evolu.createQuery((db) => +const todosQuery = createQuery((db) => db // Type-safe SQL: try autocomplete for table and column names. .selectFrom("todo") diff --git a/examples/svelte-vite-pwa/src/App.svelte b/examples/svelte-vite-pwa/src/App.svelte index 5f2b909a3..7ee58b094 100644 --- a/examples/svelte-vite-pwa/src/App.svelte +++ b/examples/svelte-vite-pwa/src/App.svelte @@ -42,8 +42,11 @@ console.error(error); }); + // Create a query builder (once per schema). + const createQuery = Evolu.createQueryBuilder(Schema); + // Evolu uses Kysely for type-safe SQL (https://kysely.dev/). - const todosQuery = evolu.createQuery((db) => + const todosQuery = createQuery((db) => db // Type-safe SQL: try autocomplete for table and column names. .selectFrom("todo") diff --git a/examples/vue-vite-pwa/src/App.vue b/examples/vue-vite-pwa/src/App.vue index 2d9ec9738..9a90404bf 100644 --- a/examples/vue-vite-pwa/src/App.vue +++ b/examples/vue-vite-pwa/src/App.vue @@ -7,6 +7,7 @@ import { sqliteTrue, createEvolu, createFormatTypeError, + createQueryBuilder, id, kysely, maxLength, @@ -60,7 +61,10 @@ const evolu = createEvolu(evoluWebDeps)(DatabaseSchema, { provideEvolu(evolu); -const todosWithCategories = evolu.createQuery((db) => +// Create a query builder (once per schema). +const createQuery = createQueryBuilder(DatabaseSchema); + +const todosWithCategories = createQuery((db) => db .selectFrom("todo") .select(["id", "title", "isCompleted", "categoryId", "priority"]) @@ -70,7 +74,7 @@ const todosWithCategories = evolu.createQuery((db) => .orderBy("createdAt"), ); -const todoCategories = evolu.createQuery((db) => +const todoCategories = createQuery((db) => db .selectFrom("todoCategory") .select(["id", "name"]) diff --git a/package.json b/package.json index e4eff972b..16460c658 100755 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "lint": "biome check", "lint-monorepo": "bunx sherif@latest", "format": "biome format --write .", - "verify": "bun run format && bun run build && bun run test && bun run test:coverage && bun run lint && bun run lint-monorepo && bunx vitest run scripts/typedoc-plugin-evolu.test.mts", + "verify": "bun run format && bun run build && bun run test && bun run test:coverage && bun run lint && bun run lint-monorepo && bun run build:docs && bunx vitest run scripts/typedoc-plugin-evolu.test.mts", "clean": "turbo clean && rimraf node_modules bun.lock .turbo out", "version": "changeset version", "release": "bun run build && changeset publish",