mirror of
https://litchi.icu/ngc2207/mine-code-now.git
synced 2025-05-18 17:06:37 +00:00
feat: integrate Prisma for MongoDB with initial schema and seed data
This commit is contained in:
parent
ff57a87de5
commit
7faa8237c7
@ -15,19 +15,21 @@
|
||||
"lucide-react": "^0.460.0",
|
||||
"next": "15.0.3",
|
||||
"next-themes": "^0.4.3",
|
||||
"prisma": "^5.22.0",
|
||||
"react": "19.0.0-rc-66855b96-20241106",
|
||||
"react-dom": "19.0.0-rc-66855b96-20241106",
|
||||
"tailwind-merge": "^2.5.4",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5",
|
||||
"@prisma/client": "^5.22.0",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "15.0.3",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "15.0.3"
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
18
prisma/schema.prisma
Normal file
18
prisma/schema.prisma
Normal file
@ -0,0 +1,18 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
output = "../node_modules/.prisma/client"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mongodb"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Snippet {
|
||||
id String @id @default(auto()) @map("_id") @db.ObjectId
|
||||
title String
|
||||
language String
|
||||
code String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
57
prisma/seed.ts
Normal file
57
prisma/seed.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
async function main() {
|
||||
await prisma.snippet.createMany({
|
||||
data: [
|
||||
{
|
||||
title: "Hello World in JavaScript",
|
||||
language: "JavaScript",
|
||||
code: `console.log("Hello, World!");
|
||||
|
||||
function greet(name) {
|
||||
return "Hello, " + name + "!";
|
||||
}
|
||||
|
||||
console.log(greet("Prisma"));`,
|
||||
},
|
||||
{
|
||||
title: "Hello World in Python",
|
||||
language: "Python",
|
||||
code: `print("Hello, World!")
|
||||
|
||||
def greet(name):
|
||||
return f"Hello, {name}!"
|
||||
|
||||
print(greet("Prisma"))`,
|
||||
},
|
||||
{
|
||||
title: "Hello World in Java",
|
||||
language: "Java",
|
||||
code: `public class HelloWorld {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello, World!");
|
||||
}
|
||||
|
||||
public static String greet(String name) {
|
||||
return "Hello, " + name + "!";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(greet("Prisma"));
|
||||
}
|
||||
}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
console.log("Seeding completed.");
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
15
src/lib/prisma.ts
Normal file
15
src/lib/prisma.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient();
|
||||
};
|
||||
|
||||
declare const globalThis: {
|
||||
prismaGlobal: ReturnType<typeof prismaClientSingleton>;
|
||||
} & typeof global;
|
||||
|
||||
const prisma = globalThis.prismaGlobal ?? prismaClientSingleton();
|
||||
|
||||
export default prisma;
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
|
Loading…
Reference in New Issue
Block a user