-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4db70b4
commit b47209c
Showing
5 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |