-
Notifications
You must be signed in to change notification settings - Fork 6
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
33bb42e
commit e411408
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ import { Prisma } from "./Prisma"; | |
import { createTestAgent } from "../helpers/createTestAgent"; | ||
import { promisify } from "util"; | ||
import { exec as execCb } from "child_process"; | ||
import path = require("path"); | ||
import * as path from "path"; | ||
|
||
const execAsync = promisify(execCb); | ||
|
||
|
@@ -213,3 +213,43 @@ t.test("it works with postgres", async (t) => { | |
|
||
await client.$disconnect(); | ||
}); | ||
|
||
t.test("it works with mongodb", async (t) => { | ||
const agent = createTestAgent(); | ||
agent.start([new Prisma()]); | ||
|
||
process.env.DATABASE_URL = | ||
"mongodb://root:[email protected]:27020/prisma?authSource=admin&directConnection=true"; | ||
|
||
// Generate prismajs client | ||
const { stdout, stderr } = await execAsync( | ||
"npx prisma generate", // Generate prisma client, reset db and apply migrations | ||
{ | ||
cwd: path.join(__dirname, "fixtures/prisma/mongodb"), | ||
} | ||
); | ||
|
||
if (stderr) { | ||
t.fail(stderr); | ||
} | ||
|
||
// Clear require cache | ||
for (const key in require.cache) { | ||
delete require.cache[key]; | ||
} | ||
|
||
const { PrismaClient } = require("@prisma/client"); | ||
|
||
const client = new PrismaClient(); | ||
|
||
await client.user.create({ | ||
data: { | ||
name: "Alice", | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
await client.user.deleteMany(); | ||
|
||
await client.$disconnect(); | ||
}); |
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,27 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "mongodb" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model User { | ||
id String @id @default(auto()) @map("_id") @db.ObjectId | ||
email String @unique | ||
name String? | ||
posts Post[] | ||
} | ||
|
||
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 | ||
} |
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