I'm using Prisma with a MySQL database. This is my code:
const thisYear = Number("2023")
const newYear = thisYear + 1
const startDate = format(new Date(thisYear, 6, 1), 'yyyy-MM-dd HH:mm:ss')
const endDate = format(new Date(newYear, 5, 30), 'yyyy-MM-dd HH:mm:ss')
console.log("startDate, endDate: ", startDate, endDate)
const bucketTransactions = await prisma.bucket_transaction.groupBy({
by: ['bucket_id'],
_sum: {
amount: true,
},
where: {
date_added: {
gte: startDate,
lte: endDate,
},
amount: {
gt: 0,
},
donation_id: {
gt: 0,
},
},
});
I get this error:
Invalid value for argument `gte`: input contains invalid characters. Expected ISO-8601 DateTime.
This is the value of startDate and endDate in the console log:
startDate, endDate: 2023-07-01 00:00:00 2024-06-30 00:00:00
Do you know what's wrong with my code?
I ran this directly into the SQL terminal and it worked:
select * from bucket_transaction WHERE date_added BETWEEN "2023-07-01 00:00:00" and "2024-06-30 00:00:00" AND amount > 0 AND donation_id > 0;
Why doesn't it work with Prisma?
I'm using Prisma with a MySQL database. This is my code:
const thisYear = Number("2023")
const newYear = thisYear + 1
const startDate = format(new Date(thisYear, 6, 1), 'yyyy-MM-dd HH:mm:ss')
const endDate = format(new Date(newYear, 5, 30), 'yyyy-MM-dd HH:mm:ss')
console.log("startDate, endDate: ", startDate, endDate)
const bucketTransactions = await prisma.bucket_transaction.groupBy({
by: ['bucket_id'],
_sum: {
amount: true,
},
where: {
date_added: {
gte: startDate,
lte: endDate,
},
amount: {
gt: 0,
},
donation_id: {
gt: 0,
},
},
});
I get this error:
Invalid value for argument `gte`: input contains invalid characters. Expected ISO-8601 DateTime.
This is the value of startDate and endDate in the console log:
startDate, endDate: 2023-07-01 00:00:00 2024-06-30 00:00:00
Do you know what's wrong with my code?
I ran this directly into the SQL terminal and it worked:
select * from bucket_transaction WHERE date_added BETWEEN "2023-07-01 00:00:00" and "2024-06-30 00:00:00" AND amount > 0 AND donation_id > 0;
Why doesn't it work with Prisma?
Share Improve this question edited Aug 1, 2023 at 19:04 Shadow 34.3k10 gold badges65 silver badges75 bronze badges asked Aug 1, 2023 at 16:17 Page COWPage COW 7653 gold badges18 silver badges41 bronze badges 1-
Doesn't ISO-8601 require a
T
in the timestamp nowadays? Like'2023-07-01T00:00:00'
. – jarlh Commented Aug 1, 2023 at 17:53
2 Answers
Reset to default 3You can change
const startDate = format(new Date(thisYear, 6, 1), 'yyyy-MM-dd HH:mm:ss')
to
const startDate = new Date(thisYear, 6, 1)
or
const startDate = new Date(thisYear, 6, 1).toISOString()
Prisma work with the date directly or with the .toISOString()
I had to change the startDate and the endDate into a new Date object like this:
where: {
date_added: {
gte: new Date(startDate),
lte: new Date(endDate),
}
},
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745333693a4623003.html
评论列表(0条)