defrex
08/20/2020, 3:04 PMRyan
08/20/2020, 3:05 PMdefrex
08/20/2020, 3:13 PMorderBy
values into the cursors this works fine. However, to calculate hasNextPage
& hasPreviousPage
I need to query “before” and “after” the current range for an arbitrary sort.
That means something like this (for before, assuming completedAt
is nullable)
{
"where": {
"AND": [
{
"createdAt": {
"lt": "2020-08-20T14:42:27.681Z"
}
},
{
"OR": [
{
"completedAt": {
"gt": "2020-08-20T14:42:27.683Z"
}
},
{
"completedAt": {
"equals": null
}
}
]
}
]
},
"orderBy": [
{
"completedAt": "desc"
},
{
"createdAt": "asc"
}
]
}
However, that same logic applied to a non-nullable field generates this.
{
"where": {
"AND": [
{
"completedAt": {
"lt": "2020-08-20T14:42:27.681Z"
}
},
{
"OR": [
{
"createdAt": {
"gt": "2020-08-20T14:42:27.683Z"
}
},
{
"createdAt": {
"equals": null
}
}
]
}
]
},
"orderBy": [
{
"completedAt": "asc"
},
{
"createdAt": "desc"
}
]
}
Which fails, since createdAt
can’t be null
.defrex
08/20/2020, 3:16 PMdefrex
08/20/2020, 4:14 PMawait prisma.$queryRaw`
select
columns.column_name,
case columns.is_nullable
when 'NO' then
false
when 'YES' then
true
end as nullable
from
information_schema.columns
where
columns.table_name = 'task'
`
Ryan
08/21/2020, 6:04 AMimport * as Prisma from '@prisma/client'
console.log(Prisma.dmmf.datamodel)
This will give you the entire datamodel and whether the fields are required or notdefrex
08/21/2020, 4:49 PM