-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datetime type with Prisma does not work with getServerSideProps #469
Comments
Have run into this several times now. Still not sure if there’s an easy way to fix. |
So, what would you recommend for Datetime in Prisma / Blitz (for now)? |
As a long-term solution, we’ll probably have to work that out somewhere within Blitz. For your purposes, though I’d recommend either:
Then, when you’re creating your const question = await createQuestion({
data: {
text: event.target[0].value,
publishedAt: new Date().getTime(),
choices: {
create: [
{ text: event.target[1].value },
{ text: event.target[2].value },
{ text: event.target[3].value },
],
},
},
}) |
Thank you, this helps a lot 🙏 Do you know if this recommendation has any implications for ordering or filtering? |
Glad that helped @gielcobben! For filtering, you’d do this: import db from "db"
// e.g. 1591115990258
const date = new Date().getTime()
const questions = await db.question.findMany({ where: { publishedAt: date } }) To order, you’d do this: import db from "db"
const questions = await db.question.findMany({ orderBy: { publishedAt: "asc" } }) |
Investigated this a bit more, and since this is essentially built into Next as a feature, I don’t think it can be “solved” beyond using something like the solution above. |
(See also the GUI for another example of a Blitz app which casts the date to an |
@merelinguist Shouldn't we use |
I recommend using String with ISO date format instead of a number. |
Is there a solution yet? |
@hauptrolle yes! Use the |
Fyi, we have an open issue to add this to blitz core: #750 |
What is the problem?
The tutorial uses
publishedAt DateTime
in the Prisma schema. When I re-writeapp/questions/pages/[id].tsx
to usegetServerSideProps
it's throwing and error:Steps to Reproduce:
app/questions/pages/[id].tsx
with:Versions:
Supporting Documentation
The text was updated successfully, but these errors were encountered: