This repository was archived by the owner on Oct 22, 2025. It is now read-only.
  
  
  - 
                Notifications
    You must be signed in to change notification settings 
- Fork 44
feat(examples): add sqlite example #1176
          
     Open
      
      
            jog1t
  wants to merge
  1
  commit into
  08-14-feat_examples_add_drizzle_example
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
08-14-feat_examples_add_sqlite_example
  
      
      
   
  
    
  
  
  
 
  
      
    base: 08-14-feat_examples_add_drizzle_example
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # SQLite Integration for RivetKit | ||
|  | ||
| Example project demonstrating SQLite 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/sqlite | ||
| pnpm install | ||
| ``` | ||
|  | ||
| ### Development | ||
| ```sh | ||
| pnpm run dev | ||
| ``` | ||
| Open your browser to https://studio.rivet.gg/ to see your RivetKit server. | ||
|  | ||
| ## License | ||
|  | ||
| Apache 2.0 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "name": "example-sqlite", | ||
| "version": "0.9.9", | ||
| "private": true, | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "tsx --watch src/server.ts", | ||
| "check-types": "tsc --noEmit" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^22.13.9", | ||
| "tsx": "^3.12.7", | ||
| "typescript": "^5.5.2" | ||
| }, | ||
| "dependencies": { | ||
| "@rivetkit/db": "workspace:*", | ||
| "@rivetkit/actor": "workspace:*" | ||
| }, | ||
| "stableVersion": "0.8.0" | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||
| import { actor, setup } from "@rivetkit/actor"; | ||||||||||||||||||
| import { db } from "@rivetkit/db"; | ||||||||||||||||||
|  | ||||||||||||||||||
| export const chat = actor({ | ||||||||||||||||||
| onAuth: () => {}, | ||||||||||||||||||
| db: db({ | ||||||||||||||||||
| onMigrate: async (c) => { | ||||||||||||||||||
| await c | ||||||||||||||||||
| .prepare(`CREATE TABLE IF NOT EXISTS messages ( | ||||||||||||||||||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||||||||||||||||||
| sender TEXT NOT NULL, | ||||||||||||||||||
| text TEXT NOT NULL, | ||||||||||||||||||
| timestamp INTEGER NOT NULL | ||||||||||||||||||
| )`) | ||||||||||||||||||
| .run(); | ||||||||||||||||||
| }, | ||||||||||||||||||
| }), | ||||||||||||||||||
| actions: { | ||||||||||||||||||
| // Callable functions from clients: https://rivet.gg/docs/actors/actions | ||||||||||||||||||
| sendMessage: async (c, sender: string, text: string) => { | ||||||||||||||||||
| const message = { sender, text, timestamp: Date.now() }; | ||||||||||||||||||
| // State changes are automatically persisted | ||||||||||||||||||
| await c.db | ||||||||||||||||||
| .prepare( | ||||||||||||||||||
| `INSERT INTO messages (sender, text, timestamp) VALUES (?, ?, ?)`, | ||||||||||||||||||
| [sender, text, message.timestamp], | ||||||||||||||||||
| ) | ||||||||||||||||||
| .run(); | ||||||||||||||||||
| // Send events to all connected clients: https://rivet.gg/docs/actors/events | ||||||||||||||||||
| c.broadcast("newMessage", message); | ||||||||||||||||||
| return message; | ||||||||||||||||||
| }, | ||||||||||||||||||
|  | ||||||||||||||||||
| getHistory: (c) => | ||||||||||||||||||
| c.db | ||||||||||||||||||
| .prepare(`SELECT * FROM messages ORDER BY timestamp DESC LIMIT 100`) | ||||||||||||||||||
| .all(), | ||||||||||||||||||
| 
      Comment on lines
    
      +34
     to 
      +37
    
   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. Potential data exposure issue: The getHistory action returns all columns from the messages table without any filtering or sanitization. If the database schema is later extended to include sensitive fields (like IP addresses, user IDs, or other metadata), this query would expose all that data to any client that calls this action. The query should explicitly specify which columns to return rather than using SELECT *. 
        Suggested change
       
 Spotted by Diamond | ||||||||||||||||||
| }, | ||||||||||||||||||
| }); | ||||||||||||||||||
|  | ||||||||||||||||||
| export const registry = setup({ | ||||||||||||||||||
| use: { chat }, | ||||||||||||||||||
| }); | ||||||||||||||||||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { registry } from "./registry"; | ||
|  | ||
| registry.runServer(); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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/**/*"] | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "$schema": "https://turbo.build/schema.json", | ||
| "extends": ["//"] | ||
| } | 
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.