chore: update sandbox with drizzle example#4187
Conversation
|
🚅 Deployed to the rivet-pr-4187 environment in rivet-frontend
|
How to use the Graphite Merge QueueAdd the label merge-queue to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
267633b to
e59fe8d
Compare
Merge activity
|
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## How Has This Been Tested? Please describe the tests that you ran to verify your changes. ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes
Pull Request ReviewThis PR adds Drizzle ORM examples to the sandbox and improves the raw SQLite implementation. The changes are well-structured and demonstrate both raw SQL and Drizzle ORM patterns for working with SQLite in RivetKit actors. ✅ Strengths
🔍 Code Quality IssuesCritical: SQL Injection Vulnerability in toggleTodo (sqlite-raw.ts:30-31)await c.db.execute(
"UPDATE todos SET completed = NOT completed WHERE id = ?",
id,
);While this uses a parameterized query (which is good), the const newCompleted = existing[0].completed ? 0 : 1;
const result = await c.db.update(todos)
.set({ completed: newCompleted })Recommendation: Update the raw SQL version to match this pattern for consistency: // First get the current state
const rows = await c.db.execute("SELECT completed FROM todos WHERE id = ?", id);
if (!rows[0]) return null;
const newCompleted = rows[0].completed ? 0 : 1;
await c.db.execute(
"UPDATE todos SET completed = ? WHERE id = ?",
newCompleted,
id,
);Issue: Missing Error Handling in toggleTodo (sqlite-raw.ts:30-36)The raw SQL Recommendation: Add existence check: toggleTodo: async (c, id: number) => {
const existing = await c.db.execute("SELECT * FROM todos WHERE id = ?", id);
if (!existing[0]) return null;
// ... rest of logic
}Issue: addTodo Missing ID Return (sqlite-raw.ts:18-25)The raw SQL Recommendation: Use const result = await c.db.execute(
"INSERT INTO todos (title, created_at) VALUES (?, ?) RETURNING *",
title,
createdAt,
);
return result[0];🎯 Important: Database Query Routing Logic (rivetkit/src/db/mod.ts:67-93)The new logic distinguishes between parameterized and non-parameterized queries: if (args.length > 0) {
// Use db.query() for parameterized queries
const { rows, columns } = await db.query(query, args);
// ...
}
// Use db.exec() for non-parameterized queriesThis is a smart optimization, but there's a potential issue: Question: What happens if someone calls if (args.length > 0 && args.some(arg => arg !== undefined)) {
// Use parameterized query
}📝 Minor Issues
🔒 Security AssessmentGood:
Note: The ⚡ Performance Considerations
🧪 Test CoverageMissing: No tests are included for the new SQLite actors. Consider adding:
According to CLAUDE.md testing guidelines, tests should be run from the rivetkit-typescript package directory. 📚 DocumentationGood: Frontend snippets show clear examples of both raw and Drizzle usage. Missing:
✨ Recommendations Summary
🎉 Overall AssessmentThis is a solid PR that adds valuable examples to the sandbox. The code demonstrates good understanding of SQL injection prevention and follows RivetKit patterns well. The main issues are consistency between the raw and Drizzle implementations and some missing error handling. With the critical issues addressed, this will be a great resource for users learning to work with SQLite in RivetKit actors. Recommendation: Approve with changes requested for the critical and high-priority issues. |
PR Review: SQLite Drizzle ExampleThis PR adds Drizzle ORM examples to the sandbox, replacing the vanilla SQLite example with a more comprehensive Drizzle-based implementation. Overall, the changes look good with some areas for consideration. ✅ Strengths
🔍 Code Quality Observations1. Raw DB Execute Method Enhancement (
|

Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.
Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes.
Checklist: