ORMs
Writing SQL is really fast, which is 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!
Note that the Drizzle query client works great, but migrations don't work yet:
this example assumes you have that kv table already set up, possibly because
you've followed the usage documentation.
import { sqlite } from "https://esm.town/v/std/sqlite/main.ts";
import { sql } from "npm:drizzle-orm";
import { drizzle } from "npm:drizzle-orm/libsql/web";
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.
Missing your favorite ORM?
Feel free to edit this docs page on a branch, and email us if you'd like a hand.
Last updated