start backend db

This commit is contained in:
Ishaan Dey
2024-04-16 18:19:34 -04:00
parent a838241ac3
commit 27159a60e6
12 changed files with 4762 additions and 0 deletions

View File

@ -0,0 +1,21 @@
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run `npm run dev` in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run `npm run deploy` to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
import { drizzle } from "drizzle-orm/d1";
export interface Env {
DB: D1Database;
}
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
return new Response("Hello World!");
},
};

View File

@ -0,0 +1,23 @@
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createId } from "@paralleldrive/cuid2";
export const user = sqliteTable("user", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey()
.unique(),
name: text("name").notNull(),
email: text("email").notNull(),
});
export const sandbox = sqliteTable("sandbox", {
id: text("id")
.$defaultFn(() => createId())
.primaryKey()
.unique(),
name: text("name").notNull(),
type: text("text", { enum: ["react", "node"] }).notNull(),
userId: text("user_id")
.notNull()
.references(() => user.id),
});