Public
Script
Forked from stevekrouse/sqliteDrizzleExample
August 6, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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";
await sqlite.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
// await sqlite.execute("CREATE TABLE IF NOT EXISTS kv (key TEXT PRIMARY KEY, value TEXT NOT NULL)");
const db = drizzle(sqlite as any);
const kv = sqliteTable("kv", {
key: text("key"),
value: text("value").notNull(),
});
// await db.insert(kv).values({ key: "hello", value: "world" }).run();
await db.insert(kv).values({ key: "hello", value: "world" }).onConflictDoNothing().run();
export let sqliteDrizzleExample = await db.select().from(kv).all();
console.log(sqliteDrizzleExample);
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
August 6, 2024