A minimal SvelteKit + Bun template with raw Bun SQL, optimized for deployment on Coolify.
# Install dependencies
bun install
# Start development server
bun run dev
# Type check
bun run check
# Build for production
bun run build
This template uses Bun's native SQL interface with SQLite:
import { sql } from '$lib/server/db';
// Query (await returns array of objects)
const users = await sql`SELECT * FROM users` as User[];
// Insert/Update
await sql`INSERT INTO users (name) VALUES (${name})`;
Database file location is configured via DATABASE_PATH environment variable (required).
Migrations are embedded in src/lib/server/db/migrate.ts:
const migrations: { name: string; sql: string }[] = [
{
name: '001_create_users',
sql: `CREATE TABLE IF NOT EXISTS users (...)`
}
];
Run migrations programmatically:
import { migrate } from '$lib/server/db/migrate';
await migrate(); // Idempotent - tracks applied migrations in _migrations table
Visit /test to verify the database and migrations are working.
In Coolify dashboard:
Enter your repository URL:
https://github.com/your-username/your-repo.git
Set branch to main.
Under Build Pack, select Dockerfile. The included Dockerfile handles:
Add a persistent volume for SQLite under Storages:
/data/myapp)/usr/src/app/dataThis preserves your database across deployments.
Click Deploy. The app runs on port 3002 by default.
Copy .env.example to .env:
DATABASE_PATH=./data/app.sqlite
src/
lib/
server/
db/
index.ts # Bun SQL connection
migrate.ts # Migration runner (embedded SQL)
index.ts # Shared lib exports
routes/
+layout.svelte # Root layout
+page.svelte # Home page
layout.css # Tailwind imports
test/ # Database test route
app.html # HTML template
app.d.ts # App types
static/ # Static assets
data/ # SQLite volume mount point