GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Database

Define SQL tables in TypeScript and query them from your routes, with typed rows.

src/database.tsSame on every host
import { defineDatabase } from 'vite-hub/database'
import {
  integer,
  sqliteTable,
  text,
} from 'drizzle-orm/sqlite-core'

// Your tables, written with Drizzle
export default defineDatabase({
  schema: {
    notes: sqliteTable('notes', {
      id: integer('id').primaryKey(),
      title: text('title').notNull(),
    }),
  },
})
src/database.ts
Deploy on

Node / Docker: SQLite / libSQL / Postgres

Tables in one file

Write your tables with Drizzle in src/database.ts. ViteHub finds the file and makes migrations.

Query from any route

useDatabase() gives you a Drizzle client and your tables, with typed results.

More than one database

Name a database to keep its data apart, with its own client and connection.

Local first, hosted later

Use a local SQLite file while you develop. Move to Turso or Cloudflare D1 with the same routes.

SQLite or Postgres

Use Postgres with postgres.js or node-postgres. db.$replica reads from read replicas.

Seed, query, and reset

vitehub seed adds starting rows, vitehub database sql runs a query, and drop or reset empties the database.