Skip to content

Instantly share code, notes, and snippets.

View oof2win2's full-sized avatar
🐛

oof2win2 oof2win2

🐛
  • Czech Republic
  • 09:27 (UTC +02:00)
View GitHub Profile
@oof2win2
oof2win2 / workers-rpc-typings.ts
Last active April 14, 2024 12:01
Typings for a "class-based" API approach with workers
class Users {
constructor(private env: Env) {}
async getUser(userId: string) {
// ...
}
// ...
}
type PickMatching<T, V> = {
@oof2win2
oof2win2 / drizzle.ts
Created April 7, 2024 19:50
comparison of drizzle vs kysely
import { drizzle } from "drizzle-orm/d1";
import { AutoRouter, type IRequest, error } from "itty-router";
import { eq } from "drizzle-orm";
import { relations } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
export const posts = sqliteTable("posts", {
id: integer("id").primaryKey({ autoIncrement: true }),
title: text("title"),
@oof2win2
oof2win2 / migrator.ts
Last active April 26, 2024 21:44
Reimplementing Prisma dev migrations for Cloudflare D1
// migrator.ts
// keep in base dir of your project (i.e. next to prisma, src, etc)
import { readdirSync, appendFileSync } from "node:fs";
import { $ } from "bun";
const dbBinding = "fdgl-maindb"; // change this, make it reflect the binding you have in your wrangler.toml
const sqlSchema =
await $`bun prisma migrate diff --from-local-d1 --to-schema-datamodel ./prisma/schema.prisma --script`.text();