Skip to content

Instantly share code, notes, and snippets.

@millsp
Created February 18, 2022 11:22
Show Gist options
  • Save millsp/8de5ae79792def17c8f160970d062cef to your computer and use it in GitHub Desktop.
Save millsp/8de5ae79792def17c8f160970d062cef to your computer and use it in GitHub Desktop.
import { PrismaClient } from ".prisma/client";
/**
model Comment {
id String @id @default(auto()) @map("_id") @db.ObjectId
country String?
content CommentContent?
contents CommentContent[]
}
type CommentContent {
time DateTime @default(now())
text String
upvotes CommentContentUpvotes[]
}
type CommentContentUpvotes {
vote Boolean
userId String
}
*/
(async () => {
const prisma = new PrismaClient();
/**
* create
*/
// +1
await prisma.comment.create({
data: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.create({
data: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// -1
// - contents should allow arrays
await prisma.comment.create({
data: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.create({
data: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.create({
data: {
contents: {
set: null
}
}
})
// -1
// - contents not allow null
await prisma.comment.create({
data: {
contents: null
}
})
// +1
await prisma.comment.create({
data: {
contents: []
}
})
/**
* createMany
*/
// +1
await prisma.comment.createMany({
data: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.createMany({
data: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// -1
// - set should allow arrays
await prisma.comment.createMany({
data: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.createMany({
data: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.createMany({
data: {
contents: {
set: null
}
}
})
// -1
// - contents should not allow null
await prisma.comment.createMany({
data: {
contents: null
}
})
// +1
await prisma.comment.createMany({
data: {
contents: []
}
})
/**
* update
*/
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: {
set: null
}
}
})
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: null
}
})
// +1
await prisma.comment.update({
where: {
id: '10'
},
data: {
contents: []
}
})
/**
* updateMany
*/
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: {
set: null
}
}
})
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: null
}
})
// +1
await prisma.comment.updateMany({
where: {
id: '10'
},
data: {
contents: []
}
})
/**
* upsert - create
*/
// +1
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// -1
// - set should allow arrays
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: {
set: null
}
}
})
// -1
// - contents should not allow null
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: null
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10',
},
update: {},
create: {
contents: []
}
})
/**
* upsert - update
*/
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: {
set: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: {
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: {
set: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: [{
text: "Hello World",
upvotes: {
vote: true,
userId: '10'
}
}]
}
})
// -1
// - set should not allow null
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: {
set: null
}
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: null
}
})
// +1
await prisma.comment.upsert({
where: {
id: '10'
},
create: {},
update: {
contents: []
}
})
/**
* delete
*/
// +1
await prisma.comment.delete({
where: {
id: '10'
}
})
/**
* deleteMany
*/
// +1
await prisma.comment.deleteMany({
where: {
country: 'France',
}
})
/**
* find
*/
// +1
await prisma.comment.findFirst({
where: {
id: '10'
},
select: {
contents: {
select: {
text: true,
}
}
}
})
/**
* findMany
*/
// +1
await prisma.comment.findMany({
where: {
country: 'France',
// content: 42
},
select: {
contents: {
select: {
text: true,
}
}
}
})
prisma.$disconnect();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment