Skip to content

Instantly share code, notes, and snippets.

@Eveeifyeve
Last active August 10, 2024 13:16
Show Gist options
  • Save Eveeifyeve/815a4280df2973874300c4ad3b2e9136 to your computer and use it in GitHub Desktop.
Save Eveeifyeve/815a4280df2973874300c4ad3b2e9136 to your computer and use it in GitHub Desktop.
drizzle x bun-sql
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);
@Eveeifyeve
Copy link
Author

Eveeifyeve commented Feb 8, 2024

This just give you the basic template in typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment