Skip to main content

On This Page

Deploy TanStack Start with SQLite to Your Own Server

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

Deploy TanStack Start with SQLite to Your Own Server

This guide walks you through deploying a TanStack Start application with a SQLite database to your own server. TanStack Start simplifies React development with file-based routing and server functions, streamlining the full-stack experience.

Why This Matters

While ideal web app architectures often involve scalable, distributed databases, many projects begin with simpler needs and benefit from options like SQLite. The complexity and cost of managing a full database cluster (e.g. PostgreSQL, MySQL) can be significant—often exceeding $100/month for basic operations—and can detract from core development efforts. SQLite provides a zero-configuration, file-based database solution that’s perfect for rapid prototyping and smaller-scale applications.

Key Insights

  • Haloy simplifies deployment: Haloy automates Docker container deployment, HTTPS configuration, and server orchestration.
  • SQLite’s file-based nature: SQLite stores data in a single file, simplifying backups and portability.
  • Drizzle ORM: Drizzle provides type-safe database interactions, reducing runtime errors; it’s a popular choice for TypeScript projects needing an ORM.

Working Example

// src/db/schema.ts
import { sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const todos = sqliteTable("todos", {
  id: integer("id", { mode: "number" }).primaryKey({
    autoIncrement: true,
  }),
  title: text("title").notNull(),
  createdAt: integer("created_at", { mode: "timestamp" }).default(
    sql`(unixepoch())`
  ),
});
// src/routes/index.tsx
import { createServerFn } from "@tanstack/react-start";
import { db } from "../db";
import { todos } from "../db/schema";

const addTodo = createServerFn({ method: "POST" })
.handler(async ({ data }) => {
  await db.insert(todos).values({ title: data.title });
});

Practical Applications

  • Personal Projects: Utilize this stack for quickly building and deploying personal to-do lists, note-taking apps, or simple web tools.
  • Pitfall: Avoid using SQLite for high-concurrency applications without careful consideration of its limitations, as it is not designed for heavy write loads.

References:

Continue reading

Next article

Automated Pterodactyl & Wings Installation with Bash Scripting

Related Content