Julian
06/08/2021, 9:53 PMdata and count in one function call?
TypeORM has a function for this called .findManyAndCount() and I was wondering if Prisma had something similar.
I found .count() but this is results in two calls: one for the data, and one for the count.
This can get quite complex with relations and joins, adding a lot of code and overhead.
Would be great if there is a way to combine them 🙂Ryan
06/09/2021, 5:08 AMJulian
06/09/2021, 6:07 AMRyan
06/09/2021, 6:08 AMJulian
06/09/2021, 6:09 AMJulian
06/09/2021, 6:17 AMpassword to the API, but this does not exist in the data model. Instead, I convert it to a hashedPassword . If I don't delete the password field afterwards, Prisma gives an error.
const data: any = {
...userIn,
};
delete data.password;
data.hashedPassword = await this._authService.hashPassword(
userIn.password
);
const user = this._prismaService.user.create({ data: data });
Compared to TypeORM I could just insert the userIn object directly, which has the password field, and it would automatically drop it as it is not relevant for the database:
user = await queryRunner.manager.create(User, { ...userIn })
Am I doing it the correct way for Prisma or is there a better way?Ryan
06/09/2021, 6:20 AMJulian
06/09/2021, 6:21 AMJulian
06/09/2021, 6:31 AMRyan
06/09/2021, 6:32 AMJulian
06/09/2021, 6:33 AM