Addressing feedback from this Gist.
Pagination. Looks like limited to paginate by id. I wanted to paginate by a date field and felt impossible
In the most recent Preview version, (cursor-)pagination can be done by any unique field or combination of fields. For example:
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User?
@@unique([title, content])
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
posts Post[]
}
Becaue email
is unique on User
and title
and content
combined are unique on Post
, you can paginate as follows:
const users = await prisma.user.findMany({
after: {
email: ""
}
})
const posts = await prisma.post.findMany({
after: {
title_content: {
title: "",
content: ""
}
}
})
If you define a unique DateTime
field, you can also paginate on that one, e.g.:
model Post {
id Int @id @default(autoincrement())
date DateTime @unique
}
Now you can do:
const posts = await prisma.post.findMany({
after: {
date: ""
}
})
Generating types inside the nexus and @prisma/client packages is cool, even mind-blowing at the beginning, but sometimes tools like VSCode don't realize types have changed and they give errors when you are using new fields or entities. I had to restart the TS language server sometimes.
Fair point, this is most likely due to bugs in VS Code but we're working constantly to improve the experience on that end – especially with VS Code.
Too verbose [API for connecting relations].
That's a great point and this is a reoccurring point of feedback we hear from our users! We want to improve the API here as well, I just created an issue with your particular example to make sure we'll address this.
I like the ActiveRecord pattern so typeorm + type-graphql feels very natural. For example adding some business logic to the entities is easy. With prisma I had to do a services dir with classes and static methods.
That's very fair! I'd hope that once Nexus has progressed a bit more, the DX it provides will speak for itself and ensure that anything you loved with TypeORM + TypeGraphQL feels at least as easy with Nexus.
With prisma I couldn't do a omposite primary key
That's resolved in the latest preview releases. You can now do e.g.:
model Post {
title String
content String?
published Boolean @default(false)
author User?
date DateTime @unique
@@id([title, content])
}
Looks like
findOne
can only be used with primary keys, which felt weird.
This also already has been addresses. findOne
works with any single-column or multi-column unique constraints.
Weird
findOne
where clause with a composite unique index. The generated WhereXXX type had no fields on it.
This was most likely a bug. If you have a composite unique index like so in Prisma:
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User?
date DateTime @unique
@@unique([title, content])
}
You can query with findOne
like this:
const posts = await prisma.post.findOne({
where: {
title_content: {
content: '',
title: ''
}
}
})
--experimental
CLI tools hang and never exit. They work, but the process never finishes. I can send screenshots.
This also should have been fixed by now.
Non basic things are not very well documented. E.g. Was not easy to create DateTime fields.
We're currently reworking our entire documentation from scratch and will make it available with the Prisma 2.0 launch. So hopefully this point will also be improved by then!