Skip to content

Commit

Permalink
Merge pull request #5 from BriefHQ/testing
Browse files Browse the repository at this point in the history
Fixes for relationships
  • Loading branch information
0xcadams authored Jan 5, 2025
2 parents 7cff491 + 85c98d9 commit c721cb9
Show file tree
Hide file tree
Showing 25 changed files with 593 additions and 3,204 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,26 @@ import { useQuery, useZero } from "@rocicorp/zero/react";

function PostList({ selectedAuthorId }: { selectedAuthorId?: number }) {
const z = useZero();

// Build a query for posts with their authors
let postsQuery = z.query.post
.related('author')
.limit(100);
let postsQuery = z.query.post.related("author").limit(100);

// Filter by author if selectedAuthorId is provided
if (selectedAuthorId) {
postsQuery = postsQuery.where('author_id', '=', selectedAuthorId);
postsQuery = postsQuery.where("author_id", "=", selectedAuthorId);
}

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

return (
<div>
<div>{postsDetail.type === 'complete' ? 'Complete results' : 'Partial results'}</div>
<div>
{posts.map(post => (
{postsDetail.type === "complete"
? "Complete results"
: "Partial results"}
</div>
<div>
{posts.map((post) => (
<div key={post.id} className="post">
<h2>{post.content}</h2>
<p>By: {post.author?.name}</p>
Expand Down
18 changes: 5 additions & 13 deletions integration/drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,17 @@
"name": "message_senderId_user_id_fk",
"tableFrom": "message",
"tableTo": "user",
"columnsFrom": [
"senderId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["senderId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
"message_mediumId_medium_id_fk": {
"name": "message_mediumId_medium_id_fk",
"tableFrom": "message",
"tableTo": "medium",
"columnsFrom": [
"mediumId"
],
"columnsTo": [
"id"
],
"columnsFrom": ["mediumId"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
Expand Down Expand Up @@ -136,4 +128,4 @@
"schemas": {},
"tables": {}
}
}
}
2 changes: 1 addition & 1 deletion integration/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"breakpoints": true
}
]
}
}
2 changes: 1 addition & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"test": "vitest run"
},
"dependencies": {
"@rocicorp/zero": "^0.10.2024122404",
"@rocicorp/zero": "canary",
"drizzle-orm": "^0.38.3",
"drizzle-zero": "workspace:*"
},
Expand Down
Loading

0 comments on commit c721cb9

Please sign in to comment.