Skip to content

Commit

Permalink
feat: backup prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaYamamoto0 committed May 9, 2024
1 parent 4db70b4 commit b47209c
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 4 deletions.
38 changes: 38 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import configs from "./locart.config.js";
process.env["DATABASE_URL"] = configs.database["database_url"];

import { PrismaClient } from "@prisma/client";
const prisma = new PrismaClient();

async function main() {
await prisma.user.create({
data: {
name: "Rich",
email: "hello@prisma.com",
posts: {
create: {
title: "My first post",
body: "Lots of really interesting stuff",
slug: "my-first-post",
},
},
},
});

const allUsers = await prisma.user.findMany({
include: {
posts: true,
},
});
console.dir(allUsers, { depth: null });
}

main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});
3 changes: 1 addition & 2 deletions locart.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export default {
},
database: {
// The URL to connect to MongoDB
database_url:
"mongodb+srv://admim:95941412@cluster0.39vdz0z.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0",
database_url: "mongodb+srv://admim:95941412@cluster-main.ixnnffd.mongodb.net/cluster-main",
},
// storage settings
storage: {
Expand Down
82 changes: 81 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"dependencies": {
"@prisma/client": "^5.13.0",
"cors": "^2.8.5",
"express": "^4.19.2",
"helmet": "^7.1.0",
Expand All @@ -37,7 +38,8 @@
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"nodemon": "^3.1.0",
"prettier": "^3.2.5"
"prettier": "^3.2.5",
"prisma": "^5.13.0"
},
"license": "Apache-2.0",
"author": "HarukaYamamoto0 <harukayamamotodev@gmail.com>",
Expand Down
41 changes: 41 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
datasource db {
provider = "mongodb"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
}

model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
slug String @unique
title String
body String
author User @relation(fields: [authorId], references: [id])
authorId String @db.ObjectId
comments Comment[]
}

model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
email String @unique
name String?
address Address?
posts Post[]
}

model Comment {
id String @id @default(auto()) @map("_id") @db.ObjectId
comment String
post Post @relation(fields: [postId], references: [id])
postId String @db.ObjectId
}

// Address is an embedded document
type Address {
street String
city String
state String
zip String
}

0 comments on commit b47209c

Please sign in to comment.