Last active
August 10, 2024 13:16
-
-
Save Eveeifyeve/815a4280df2973874300c4ad3b2e9136 to your computer and use it in GitHub Desktop.
drizzle x bun-sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { text, integer } from "drizzle-orm/sqlite-core"; | |
import { sqliteTable } from "drizzle-orm/sqlite-core"; | |
import { drizzle } from "drizzle-orm/bun-sqlite"; | |
import { Database } from "bun:sqlite"; | |
export const user = sqliteTable('user', { | |
id: integer('userId').primaryKey(), | |
username: text('username').notNull(), | |
}) | |
const databaseTables = [`user (id INTEGER PRIMARY KEY, name TEXT)`]; // Drizzle doesn't support creating tables :( | |
const sqlite = new Database("drizzle/db.sqlite"); | |
for (const tableCreationStatement of databaseTables) { | |
await sqlite.exec(`CREATE TABLE IF NOT EXISTS ${tableCreationStatement}`); | |
} | |
const db = drizzle(sqlite); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This just give you the basic template in typescript.