-
Couldn't load subscription status.
- Fork 44
feat: sqlite #992
feat: sqlite #992
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| DB_FILE_NAME=file:local.db |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| # Hono Integration for RivetKit | ||||||
|
|
||||||
| Example project demonstrating Hono web framework integration with [RivetKit](https://rivetkit.org). | ||||||
|
|
||||||
| [Learn More →](https://github.com/rivet-gg/rivetkit) | ||||||
|
|
||||||
| [Discord](https://rivet.gg/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-gg/rivetkit/issues) | ||||||
|
|
||||||
| ## Getting Started | ||||||
|
|
||||||
| ### Prerequisites | ||||||
|
|
||||||
| - Node.js | ||||||
|
|
||||||
| ### Installation | ||||||
|
|
||||||
| ```sh | ||||||
| git clone https://github.com/rivet-gg/rivetkit | ||||||
| cd rivetkit/examples/hono | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README in the drizzle example directory contains an incorrect installation path. It instructs users to
Suggested change
Spotted by Diamond |
||||||
| npm install | ||||||
| ``` | ||||||
|
|
||||||
| ### Development | ||||||
|
|
||||||
| ```sh | ||||||
| npm run dev | ||||||
| ``` | ||||||
|
|
||||||
| Open your browser to http://localhost:3000 to see the Hono server with RivetKit integration. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README in the drizzle example references a Hono server and instructs users to open http://localhost:3000, but this appears to be copied from a different example. The drizzle/SQLite example likely doesn't have a web interface or uses a different port. Consider updating the README with instructions specific to this database example.
Suggested change
Spotted by Diamond |
||||||
|
|
||||||
| ## License | ||||||
|
|
||||||
| Apache 2.0 | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { defineConfig } from "@rivetkit/db/drizzle"; | ||
|
|
||
| export default defineConfig({ | ||
| out: "./drizzle", | ||
| schema: "./src/db/schema.ts", | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| CREATE TABLE `users_table` ( | ||
| `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
| `name` text NOT NULL, | ||
| `age` integer NOT NULL, | ||
| `email` text NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| CREATE UNIQUE INDEX `users_table_email_unique` ON `users_table` (`email`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| { | ||
| "version": "6", | ||
| "dialect": "sqlite", | ||
| "id": "22f3d49c-97d5-46ca-b0f1-99950c3efec7", | ||
| "prevId": "00000000-0000-0000-0000-000000000000", | ||
| "tables": { | ||
| "users_table": { | ||
| "name": "users_table", | ||
| "columns": { | ||
| "id": { | ||
| "name": "id", | ||
| "type": "integer", | ||
| "primaryKey": true, | ||
| "notNull": true, | ||
| "autoincrement": true | ||
| }, | ||
| "name": { | ||
| "name": "name", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true, | ||
| "autoincrement": false | ||
| }, | ||
| "age": { | ||
| "name": "age", | ||
| "type": "integer", | ||
| "primaryKey": false, | ||
| "notNull": true, | ||
| "autoincrement": false | ||
| }, | ||
| "email": { | ||
| "name": "email", | ||
| "type": "text", | ||
| "primaryKey": false, | ||
| "notNull": true, | ||
| "autoincrement": false | ||
| } | ||
| }, | ||
| "indexes": { | ||
| "users_table_email_unique": { | ||
| "name": "users_table_email_unique", | ||
| "columns": [ | ||
| "email" | ||
| ], | ||
| "isUnique": true | ||
| } | ||
| }, | ||
| "foreignKeys": {}, | ||
| "compositePrimaryKeys": {}, | ||
| "uniqueConstraints": {}, | ||
| "checkConstraints": {} | ||
| } | ||
| }, | ||
| "views": {}, | ||
| "enums": {}, | ||
| "_meta": { | ||
| "schemas": {}, | ||
| "tables": {}, | ||
| "columns": {} | ||
| }, | ||
| "internal": { | ||
| "indexes": {} | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "version": "7", | ||
| "dialect": "sqlite", | ||
| "entries": [ | ||
| { | ||
| "idx": 0, | ||
| "version": "6", | ||
| "when": 1750711614205, | ||
| "tag": "0000_wonderful_iron_patriot", | ||
| "breakpoints": true | ||
| }, | ||
| { | ||
| "idx": 1, | ||
| "version": "6", | ||
| "when": 1750716663518, | ||
| "tag": "0001_rich_susan_delgado", | ||
| "breakpoints": true | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import journal from './meta/_journal.json'; | ||
| import m0000 from './0000_wonderful_iron_patriot.sql'; | ||
|
|
||
| export default { | ||
| journal, | ||
| migrations: { | ||
| m0000, | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export async function load(url, context, nextLoad) { | ||
| if(url.endsWith('.sql')) { | ||
| return { | ||
| shortCircuit: true, | ||
| format: 'module', | ||
| source: `export default 'SQL file loaded from ${url}';` | ||
| } | ||
| } | ||
| return nextLoad(url, context) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| { | ||
| "name": "example-sqlite", | ||
| "version": "0.9.0-rc.1", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "tsx --watch src/server.ts", | ||
| "check-types": "tsc --noEmit" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^22.13.9", | ||
| "rivetkit": "workspace:*", | ||
| "tsx": "^3.12.7", | ||
| "typescript": "^5.5.2" | ||
| }, | ||
| "dependencies": { | ||
| "@rivetkit/db": "workspace:0.9.0-rc.1", | ||
| "drizzle-kit": "^0.31.2", | ||
| "drizzle-orm": "^0.44.2" | ||
| }, | ||
| "example": { | ||
| "platforms": [ | ||
| "*" | ||
| ] | ||
| }, | ||
| "stableVersion": "0.8.0" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import {register} from "node:module"; | ||
| import { pathToFileURL } from 'node:url'; | ||
|
|
||
|
|
||
| register("./hooks.js", pathToFileURL(__filename)) | ||
|
|
||
|
|
||
| // registerHooks({ | ||
| // resolve(specifier, context, nextResolve) { | ||
| // console.log({specifier, context}); | ||
| // }, | ||
| // load(url, context, nextLoad) { | ||
| // console.log({url, context}); | ||
| // }, | ||
| // }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // import { int, sqliteTable, text } from "@rivetkit/db/drizzle"; | ||
|
|
||
| // export const usersTable = sqliteTable("users_table", { | ||
| // id: int().primaryKey({ autoIncrement: true }), | ||
| // name: text().notNull(), | ||
| // age: int().notNull(), | ||
| // email: text().notNull().unique(), | ||
| // email2: text().notNull().unique(), | ||
| // }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // import { worker, setup } from "rivetkit"; | ||
| // import { db } from "@rivetkit/db/drizzle"; | ||
| // import * as schema from "./db/schema"; | ||
| // import migrations from "../drizzle/migrations"; | ||
|
|
||
| // export const counter = worker({ | ||
| // db: db({ schema, migrations }), | ||
| // state: { | ||
| // count: 0, | ||
| // }, | ||
| // onAuth: () => { | ||
| // // Configure auth here | ||
| // }, | ||
| // actions: { | ||
| // increment: (c, x: number) => { | ||
| // // createState or state fix fix fix | ||
| // c.db.c.state.count += x; | ||
| // return c.state.count; | ||
| // }, | ||
| // }, | ||
| // }); | ||
|
|
||
| // export const registry = setup({ | ||
| // workers: { counter }, | ||
| // }); | ||
|
|
||
| // export type Registry = typeof registry; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // import { registry } from "./registry"; | ||
| // import { createMemoryDriver } from "@rivetkit/memory"; | ||
| // import { serve } from "@rivetkit/nodejs"; | ||
|
|
||
| // serve(registry, { | ||
| // driver: createMemoryDriver(), | ||
| // }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "compilerOptions": { | ||
| /* Visit https://aka.ms/tsconfig.json to read more about this file */ | ||
|
|
||
| /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ | ||
| "target": "esnext", | ||
| /* Specify a set of bundled library declaration files that describe the target runtime environment. */ | ||
| "lib": ["esnext"], | ||
| /* Specify what JSX code is generated. */ | ||
| "jsx": "react-jsx", | ||
| "allowArbitraryExtensions": true, | ||
|
|
||
| /* Specify what module code is generated. */ | ||
| "module": "esnext", | ||
| /* Specify how TypeScript looks up a file from a given module specifier. */ | ||
| "moduleResolution": "bundler", | ||
| /* Specify type package names to be included without being referenced in a source file. */ | ||
| "types": ["node"], | ||
| /* Enable importing .json files */ | ||
| "resolveJsonModule": true, | ||
|
|
||
| /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ | ||
| "allowJs": true, | ||
| /* Enable error reporting in type-checked JavaScript files. */ | ||
| "checkJs": false, | ||
|
|
||
| /* Disable emitting files from a compilation. */ | ||
| "noEmit": true, | ||
|
|
||
| /* Ensure that each file can be safely transpiled without relying on other imports. */ | ||
| "isolatedModules": true, | ||
| /* Allow 'import x from y' when a module doesn't have a default export. */ | ||
| "allowSyntheticDefaultImports": true, | ||
| /* Ensure that casing is correct in imports. */ | ||
| "forceConsistentCasingInFileNames": true, | ||
|
|
||
| /* Enable all strict type-checking options. */ | ||
| "strict": true, | ||
|
|
||
| /* Skip type checking all .d.ts files. */ | ||
| "skipLibCheck": true | ||
| }, | ||
| "include": ["src/**/*"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { worker } from "rivetkit"; | ||
|
|
||
| // Short timeout worker | ||
| export const shortTimeoutWorker = worker({ | ||
| onAuth: () => {}, | ||
| state: { value: 0 }, | ||
| options: { | ||
| action: { | ||
| timeout: 50, // 50ms timeout | ||
| }, | ||
| }, | ||
| actions: { | ||
| quickAction: async (c) => { | ||
| return "quick response"; | ||
| }, | ||
| slowAction: async (c) => { | ||
| // This action should timeout | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| return "slow response"; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Long timeout worker | ||
| export const longTimeoutWorker = worker({ | ||
| onAuth: () => {}, | ||
| state: { value: 0 }, | ||
| options: { | ||
| action: { | ||
| timeout: 200, // 200ms timeout | ||
| }, | ||
| }, | ||
| actions: { | ||
| delayedAction: async (c) => { | ||
| // This action should complete within timeout | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| return "delayed response"; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Default timeout worker | ||
| export const defaultTimeoutWorker = worker({ | ||
| onAuth: () => {}, | ||
| state: { value: 0 }, | ||
| actions: { | ||
| normalAction: async (c) => { | ||
| await new Promise((resolve) => setTimeout(resolve, 50)); | ||
| return "normal response"; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| // Sync worker (timeout shouldn't apply) | ||
| export const syncTimeoutWorker = worker({ | ||
| onAuth: () => {}, | ||
| state: { value: 0 }, | ||
| options: { | ||
| action: { | ||
| timeout: 50, // 50ms timeout | ||
| }, | ||
| }, | ||
| actions: { | ||
| syncAction: (c) => { | ||
| return "sync response"; | ||
| }, | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README title and description in the drizzle example incorrectly identifies this as a "Hono Integration" example when it's actually demonstrating SQLite/Drizzle database integration with RivetKit. The title and description should be updated to accurately reflect the content of this example, which appears to be focused on database integration rather than the Hono web framework.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.