Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
fail-fast: false
matrix:
node-version: [22.x]
zero: [current, latest]
zero: [current]
pg-version: [16, 17, 18]
test-suite: [integration, no-config-integration]

Expand Down
37 changes: 3 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ The CLI automatically detects whether `.js` file extensions are needed in import
You can also control optional outputs from the generator:

- **--skip-types**: Skip generating table `Row[]` type exports.
- **--skip-builder**: Skip generating the query `builder` export.
- **--skip-builder**: Skip generating the query `createBuilder` export.
- **--skip-crud**: Skip generating the CRUD mutator `createCRUDBuilder` export.
- **--skip-declare**: Skip generating the module augmentation for default types in Zero.
- **--enable-legacy-mutators**: Enable legacy CRUD mutators (sets `enableLegacyMutators` to `true` in the generated schema).
- **--enable-legacy-queries**: Enable legacy CRUD queries (sets `enableLegacyQueries` to `true` in the generated schema).
Expand All @@ -102,39 +103,7 @@ For more information on disabling legacy mutators and queries, see the [Zero doc
type resolution to work. If they are not included, there will be an error similar to
`Failed to find type definitions`.

### Define Zero schema file

Use the generated Zero schema:

```tsx
import {useEffect, useState} from 'react';
import {useZero} from '@rocicorp/zero/react';
import {syncedQuery} from '@rocicorp/zero';
import {builder} from '../zero-schema.gen.ts';

const postsQuery = syncedQuery('allPosts', z.tuple([]), () =>
builder.posts.related('author').limit(10),
);

function PostList() {
const z = useZero();

const [posts] = useQuery(postsQuery());

return (
<div>
{posts.map(post => (
<div key={post.id} className="post">
{/* Access the JSON content from Drizzle */}
<p>{post.content.textValue}</p>
<p>By: {post.author?.name}</p>
<p>Email: {post.author?.email}</p>
</div>
))}
</div>
);
}
```
Please reference the Zero docs for how to use your new Zero schema: [https://zero.rocicorp.dev/docs/reading-data](https://zero.rocicorp.dev/docs/reading-data).

### Customize with `drizzle-zero.config.ts`

Expand Down
2 changes: 1 addition & 1 deletion db/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ export const startZero = async (options: {getQueriesUrl: string}) => {
const basePgUrlWithInternalPort = `${basePgUrl}@postgres-db:5432`;

// Start Zero container
zeroContainer = await new GenericContainer(`rocicorp/zero:latest`)
zeroContainer = await new GenericContainer(`rocicorp/zero:0.25.0-canary.17`)
.withExposedPorts({
container: 4848,
host: ZERO_PORT,
Expand Down
22 changes: 6 additions & 16 deletions integration/get-queries-server.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
import {serve} from '@hono/node-server';
import {withValidation} from '@rocicorp/zero';
import {handleGetQueriesRequest} from '@rocicorp/zero/server';
import {mustGetQuery} from '@rocicorp/zero';
import {handleQueryRequest} from '@rocicorp/zero/server';
import {Hono} from 'hono';
import type {Server} from 'http';
import * as queries from './synced-queries';
import {queries} from './synced-queries';
import {schema} from './zero-schema.gen';

const validated = Object.fromEntries(
Object.values(queries).map(q => [q.queryName, withValidation(q)]),
);

const app = new Hono();

app.post('/get-queries', async c => {
try {
const jsonBody = await c.req.json();

const response = await handleGetQueriesRequest(
const response = await handleQueryRequest(
(name, args) => {
const q = validated[name];
if (!q) {
throw new Error(`Unknown query: ${name}`);
}

console.log('name', name, 'args', args);

return {query: q(undefined, ...args)};
const q = mustGetQuery(queries, name);
return q.fn({args, ctx: undefined});
},
schema,
jsonBody,
Expand Down
4 changes: 2 additions & 2 deletions integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"type": "module",
"scripts": {
"build": "tsc",
"drizzle-zero:generate": "drizzle-zero generate -f",
"pretest": "pnpm drizzle-zero:generate",
"generate": "drizzle-zero generate -f --skip-declare",
"pretest": "pnpm generate",
"test": "pnpm build && vitest run"
},
"dependencies": {
Expand Down
Loading