mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-01-06 04:32:37 +00:00
✨ feat: Prisma instead of drizzle
This commit is contained in:
@@ -3,7 +3,7 @@ const dotenv = dotenvLoad();
|
|||||||
|
|
||||||
import { Elysia } from "elysia";
|
import { Elysia } from "elysia";
|
||||||
import { swagger } from "@elysiajs/swagger";
|
import { swagger } from "@elysiajs/swagger";
|
||||||
import { db } from "@minikura/db";
|
import { prisma } from "@minikura/db";
|
||||||
|
|
||||||
const app = new Elysia()
|
const app = new Elysia()
|
||||||
.use(swagger())
|
.use(swagger())
|
||||||
@@ -13,7 +13,7 @@ const app = new Elysia()
|
|||||||
.get("/hello", "Do you miss me?")
|
.get("/hello", "Do you miss me?")
|
||||||
.listen(3000, async () => {
|
.listen(3000, async () => {
|
||||||
console.log("Server is running on port 3000");
|
console.log("Server is running on port 3000");
|
||||||
const result = await db.query.server.findMany();
|
const result = await prisma.server.findMany();
|
||||||
console.log(result);
|
console.log(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,9 @@
|
|||||||
"lint:fix": "biome lint --apply .",
|
"lint:fix": "biome lint --apply .",
|
||||||
"format": "biome format .",
|
"format": "biome format .",
|
||||||
"format:fix": "biome format --write .",
|
"format:fix": "biome format --write .",
|
||||||
"studio": "drizzle-kit studio",
|
"db:generate": "bun --filter @minikura/db generate",
|
||||||
"push": "drizzle-kit push"
|
"db:studio": "bun --filter @minikura/db studio",
|
||||||
|
"db:push": "bun --filter @minikura/db push"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "^1.9.1",
|
"@biomejs/biome": "^1.9.1",
|
||||||
|
|||||||
@@ -3,16 +3,21 @@
|
|||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": "./src/index.ts",
|
"exports": "./src/index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"generate": "prisma generate",
|
||||||
|
"studio": "bun with-env prisma studio",
|
||||||
|
"push": "bun with-env prisma db push",
|
||||||
|
"with-env": "dotenv -e ../../.env --"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "latest",
|
"@types/bun": "latest"
|
||||||
"drizzle-kit": "^0.24.2"
|
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^5.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^16.4.5",
|
"@prisma/client": "5.20.0",
|
||||||
"drizzle-orm": "^0.33.0",
|
"dotenv-cli": "^7.4.2",
|
||||||
"postgres": "^3.4.4"
|
"prisma": "^5.20.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
38
packages/db/prisma/schema.prisma
Normal file
38
packages/db/prisma/schema.prisma
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// This is your Prisma schema file,
|
||||||
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
||||||
|
|
||||||
|
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
|
||||||
|
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
|
||||||
|
|
||||||
|
generator client {
|
||||||
|
provider = "prisma-client-js"
|
||||||
|
}
|
||||||
|
|
||||||
|
datasource db {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("DATABASE_URL")
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ServerType {
|
||||||
|
STATEFUL
|
||||||
|
STATELESS
|
||||||
|
REVERSE_PROXY
|
||||||
|
}
|
||||||
|
|
||||||
|
model Server {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
name String @unique
|
||||||
|
address String
|
||||||
|
port Int
|
||||||
|
type ServerType
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
}
|
||||||
|
|
||||||
|
model User {
|
||||||
|
id String @id @default(cuid())
|
||||||
|
username String @unique
|
||||||
|
password String
|
||||||
|
createdAt DateTime @default(now())
|
||||||
|
updatedAt DateTime @updatedAt
|
||||||
|
}
|
||||||
@@ -1,15 +1,5 @@
|
|||||||
import "dotenv/config";
|
import { PrismaClient } from "@prisma/client";
|
||||||
import { drizzle } from "drizzle-orm/postgres-js";
|
|
||||||
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
|
||||||
import postgres from "postgres";
|
|
||||||
import * as schema from "./schema";
|
|
||||||
|
|
||||||
console.log(process.env.DATABASE_URL);
|
export * from "@prisma/client";
|
||||||
|
|
||||||
// for migrations
|
export const prisma = new PrismaClient();
|
||||||
const migrationClient = postgres(process.env.DATABASE_URL || "", { max: 1 });
|
|
||||||
// migrate(drizzle(migrationClient), ...)
|
|
||||||
|
|
||||||
// for query purposes
|
|
||||||
const queryClient = postgres(process.env.DATABASE_URL || "");
|
|
||||||
export const db = drizzle(queryClient, { schema });
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import {
|
|
||||||
serial,
|
|
||||||
text,
|
|
||||||
timestamp,
|
|
||||||
pgTable,
|
|
||||||
pgSchema,
|
|
||||||
} from "drizzle-orm/pg-core";
|
|
||||||
|
|
||||||
export const server = pgTable("server", {
|
|
||||||
id: serial("id"),
|
|
||||||
createdAt: timestamp("created_at"),
|
|
||||||
updatedAt: timestamp("updated_at"),
|
|
||||||
});
|
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
},
|
},
|
||||||
"dev": {
|
"dev": {
|
||||||
"persistent": true,
|
"persistent": true,
|
||||||
"cache": false
|
"cache": false,
|
||||||
|
"env": ["DATABASE_URL"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ui": "tui",
|
"ui": "tui",
|
||||||
|
|||||||
Reference in New Issue
Block a user