Rev
Rev
PPrisma
Created by Rev on 8/3/2024 in #help-and-questions
Count with distinct
repost*
3 replies
PPrisma
Created by acidjazz on 8/4/2024 in #help-and-questions
prisma client generates model with no create
I dont know the reason, must have a restricted word in prisma for "Session"
11 replies
PPrisma
Created by acidjazz on 8/4/2024 in #help-and-questions
prisma client generates model with no create
did you already make the prisma generate?
11 replies
PPrisma
Created by Rev on 8/1/2024 in #help-and-questions
How to run SQL query after each the migration
The problem is: migration generated is ran in an shadow database and it's not permitted to run DML queries in shadow database
4 replies
PPrisma
Created by Rev on 8/1/2024 in #help-and-questions
There are easy way to use transaction in prisma?
your example case is usefull but i need to make N calls in transaction and most part is not followed by each other, i call function X and then make and http request for another service and then i call function Y and i can't do
await this.prisma.$transaction([
functionX()
functionY()
])
await this.prisma.$transaction([
functionX()
functionY()
])
because between them i need to make request for http external service after functionX
5 replies
PPrisma
Created by Rev on 8/1/2024 in #help-and-questions
There are easy way to use transaction in prisma?
It was just an example, in my project i have repository pattern to abstract the queries because i have many queries that have more than 500 lines to filter, select, order by etc and if i dont use repository pattern my service class would have 30k of lines I thought that was possible to create a function that generated one transaction and pass through the transaction instance like:
startTransaction()

try {
saveCompany()
editCompany()
getCompanyUpdated()

commitTransaction()
} catch {
rollbackTransaction()
}
startTransaction()

try {
saveCompany()
editCompany()
getCompanyUpdated()

commitTransaction()
} catch {
rollbackTransaction()
}
5 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
Nice
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
Try to transform the forEach into for await and divide the call functions like: for await(const unit of pricedUnits) { const createdLease = await createLease(unit, leaseStart, leadeEnd); leases.push(createdLease); } and post the result of queries of full run of seed
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
But to resolve the problem i think that is necessary more information like: Which users are in database? Which is returned by query in each iteration? The user that is returned in each iteration came with the leases? ( Try to select the leases to validate )
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
Consider get all the users as you do for employees and random it to get one
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
It really looks like correctly, the query filter users that doesn't have leases, the findFirst every time returns the first if the where doesn't match anything. "The subquery SELECT "t1"."customerId" FROM "public"."Lease" AS "t1" WHERE (1=1 AND "t1"."customerId" IS NOT NULL) returns all customerId from the Lease table where customerId is not null. The NOT IN clause in the WHERE of the main query filters users whose id is not in the list of customerId returned by the subquery. If there are no records in the Lease table (or if all customerId in the Lease table are null), the subquery will return an empty set. If the subquery returns an empty set, the NOT IN clause will evaluate as true for all records in the users table (all users will be considered as not having leases)."
17 replies
PPrisma
Created by Uncle on 7/21/2024 in #help-and-questions
Help with findFirst and none relations
In the prisma service add this code on constructor: this.$on('query', e => { console.log('Query: ' + e.query); console.log('Params: ' + e.params); console.log('Duration: ' + e.duration + 'ms'); }); And then paste the queries that are running in the database here to help to understanding the problem And paste the database structure from schema and the part of seed code
17 replies