Skip to content

ORMs

Writing SQL is really fast and it’s great for small projects. As your projects grow, you might want to take advantage of an ORM or query builder instead. Here are a few examples of how to do that with popular tools.

Drizzle

Here’s how to use the awesome Drizzle ORM module with Val Town and SQLite. It’s great because it allows you to write very expressive SQL. We even use Drizzle to build Val Town!

ExampleRun in Val Town ↗
import { sqlite } from "https://esm.town/v/std/sqlite";
import { sql } from "npm:drizzle-orm";
import { drizzle } from "npm:drizzle-orm/libsql";
import { integer, sqliteTable, text } from "npm:drizzle-orm/sqlite-core";
const db = drizzle(sqlite as any);
const kv = sqliteTable("kv", {
key: text("key").primaryKey(),
value: text("value").notNull(),
});
const sqliteDrizzleExample = await db.select().from(kv).all();
console.log(sqliteDrizzleExample);

Prisma

🚫 Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment.

Sequelize

🚫 Sequelize isn’t supported in Val Town because it relies on specific database drivers and is not extensible.