Server primitives
Server Primitives are APIs for environment values, databases, queues, workflows, files, sandboxes, and other server features.
Application code calls the ViteHub API. The Vite integration connects that call to the implementation supported by the current development or deployment host.
Choose a primitive for the job
| You need | Start with |
|---|---|
| Configure the app | Env, Auth, or Rate Limit |
| Store data and files | Database, KV, Blob, Workspace, or Source |
| Send or receive messages | Email or Channels |
| Run work later | Queue, Schedule, or Workflow |
| Run isolated automation | Browser, Shell, or Sandbox |
How a primitive works in your app
Most ViteHub primitives follow the same pattern:
Configure ViteHub
Add ViteHub to your configuration. ViteHub uses the Vite Environment API, which requires Vite 8+, Nitro 3+, or Nuxt 5+.
import { defineConfig } from 'vite'
import { vitehub } from 'vite-hub'
export default defineConfig({
plugins: [
vitehub({ preset: 'node', database: true }),
],
})
import viteHubNuxt from 'vite-hub/nuxt'
export default defineNuxtConfig({
modules: [
[viteHubNuxt, { preset: 'node', database: true }],
],
})
import { defineConfig } from 'vite'
import { nitro } from 'nitro/vite'
import { vitehub } from 'vite-hub'
export default defineConfig({
plugins: [
vitehub({ preset: 'node', database: true }),
nitro(),
],
})
Define the database
Create a Database Definition file that ViteHub discovers automatically. Its file name becomes the database name, and the file defines the schema and options.
import { defineDatabase } from 'vite-hub/database'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
export default defineDatabase({
name: 'notes',
schema: {
notes: sqliteTable('notes', {
id: integer('id').primaryKey(),
title: text('title').notNull(),
}),
},
})
import { defineDatabase } from 'vite-hub/database'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
export default defineDatabase({
name: 'notes',
schema: {
notes: sqliteTable('notes', {
id: integer('id').primaryKey(),
title: text('title').notNull(),
}),
},
})
import { defineDatabase } from 'vite-hub/database'
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
export default defineDatabase({
name: 'notes',
schema: {
notes: sqliteTable('notes', {
id: integer('id').primaryKey(),
title: text('title').notNull(),
}),
},
})
Use it from server code
Import the database API in a server route and query the named database. ViteHub connects that call to the provider configured for the current environment.
import { useDatabase } from 'vite-hub/database/drizzle'
export default {
async fetch() {
const { db, schema } = useDatabase('notes')
return Response.json(await db.select().from(schema.notes))
},
}
import { useDatabase } from 'vite-hub/database/drizzle'
export default defineEventHandler(() => {
const { db, schema } = useDatabase('notes')
return db.select().from(schema.notes)
})
import { useDatabase } from 'vite-hub/database/drizzle'
export default defineEventHandler(() => {
const { db, schema } = useDatabase('notes')
return db.select().from(schema.notes)
})
The same path applies to other Server Primitives. Configure ViteHub, add a definition when the feature needs a name or schema, and call its server API. Check the host support matrix before choosing a deployment target.