• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
nbbaier

nbbaier

ChatAppSDKStarter

Remix of laurynas/ChatAppSDKStarter
Public
Like
ChatAppSDKStarter
Home
Code
6
backend
4
frontend
2
shared
3
.vtignore
README.md
deno.json
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
backend
/
database
/
README.md
Code
/
backend
/
database
/
README.md
Search
10/10/2025
README.md

Database

This app uses Val Town SQLite to manage data. Every Val Town account comes with a free SQLite database, hosted on Turso.

Structure

  • schema.ts - Drizzle ORM schema definitions (tables, columns, types)
  • migrations.ts - Database table creation logic
  • queries.ts - Query functions used by MCP tools
  • db.ts - Database connection configuration

Tables

The starter includes a messages table for storing message board data:

export const messages = sqliteTable("messages", { id: integer("id").primaryKey({ autoIncrement: true }), content: text("content").notNull(), timestamp: text("timestamp").notNull().default(new Date().toISOString()), });

Migrations

Migrations run automatically on startup via createTables() in migrations.ts, which is imported in queries.ts.

The migration logic uses CREATE TABLE IF NOT EXISTS, so it's safe to run on every startup. You can comment out the import in queries.ts for a slight (30ms) performance improvement on cold starts, but it's left in by default so forks work out of the box.

Queries

The queries.ts file exports typed functions for database operations:

  • getMessages(limit?) - Fetch messages with optional limit
  • insertMessage(content) - Insert a new message

These functions are imported and used by MCP tools in backend/mcp/server.ts.

Schema Changes

SQLite has limited support for altering existing tables. When you need to modify a table schema:

  1. Create a new table with the updated schema
  2. Copy data from the old table to the new table
  3. Drop the old table
  4. Rename the new table

Alternatively, you can just change the table name (e.g., messages_v2) to start fresh.

For help with database operations, reach out in the Val Town Discord.

Get started with a template:
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.