Database & Drizzle
Neutron uses Drizzle ORM for database access. It's a lightweight, TypeScript-first ORM that provides the power of raw SQL with the safety of types.
Schema Definition
Define your schema in src/db/schema.ts.
import { pgTable, serial, text, timestamp } from "drizzle-orm/pg-core";
export const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull().unique(),
createdAt: timestamp("created_at").defaultNow(),
});
Querying in Loaders
Loaders have direct access to the database via the context.
export async function loader({ context }) {
const allUsers = await context.db.select().from(users);
return { allUsers };
}
Why Drizzle?
- Performance: No heavy "runtime" or "generate" step. It's just a thin layer over SQL.
- Type Safety: Your queries are fully typed based on your schema.
- Composability: Easily build complex queries using standard SQL patterns.
- Compatibility: Supports both PostgreSQL (Prod) and SQLite (Dev) seamlessly.