Dev__
08/13/2021, 2:38 PMArgument of type '() => Promise<Integration[]>' is not assignable to parameter of type 'PrismaPromise<any>[]'
const [updatedIntegration] = await this.prisma.$transaction(async () => {
const method = ...
const updatedIntegration = await this.prisma.integration.update({
data: {
name,
username,
password: hashedPassword,
descriptionCharacterLimit,
integrationMethodId: method.id
},
where: {
id: integration.id
}
});
// some more queries...
return [updatedIntegration];
});
Victor Iris
08/13/2021, 2:40 PMDev__
08/13/2021, 2:43 PMconst updatedIntegration = await this.prisma.$transaction(async () => {
const method = ...
const updatedIntegration = this.prisma.integration.update({
data: {
name,
username,
password: hashedPassword,
descriptionCharacterLimit,
integrationMethodId: method.id
},
where: {
id: integration.id
}
});
// some more queries...
return updatedIntegration;
});
like this?Victor Iris
08/13/2021, 2:46 PMlet items = []
for (const integration of integrations) {
const newPromise = this.prisma.integration.update({
data: {
name,
username,
password: hashedPassword,
descriptionCharacterLimit,
integrationMethodId: method.id
},
where: {
id: integration.id
}
});
items.push(newPromise)
}
const itemsResults = await this.prisma.$transaction(items)Dev__
08/13/2021, 2:52 PMconst trans = await this.prisma.$transaction(async () => {
return this.prisma.integration.update({
data: {
name,
username,
password: hashedPassword,
descriptionCharacterLimit,
integrationMethodId: method.id
},
where: {
id: integration.id
}
});
});
still: Argument of type '() => Promise<Integration>' is not assignable to parameter of type 'PrismaPromise<any>[]'.
Victor Iris
08/13/2021, 3:14 PMDev__
08/13/2021, 3:16 PMpreviewFeatures = ["orderByRelation", "referentialActions", "interactiveTransactions"]
Victor Iris
08/13/2021, 3:25 PMDev__
08/13/2021, 3:26 PMtry {
await prisma.$transaction(async () => {
await prisma.delete()
await prisma.create(); // lets say this throws a prisma unique contraint error
return prisma.update()
});
} catch (err) {
....
}
does this rollback the delete
and create
as well? or do I need to return delete
and create
as a promise inside the interactive transation @Victor IrisRyan
08/16/2021, 8:01 AMDev__
08/16/2021, 8:03 AMAshrith Reddy
10/25/2021, 1:00 PMasync function main() {
const [user] = await prisma.$transaction(async () => {
// Should the prisma object here need to the argument from this transaction or it can be the global prisma object initialized during application start?
const user = await prisma.user.create({ data: { name: 'name' }})
return [user]
})
prettyPrint(user)
}
Ryan
10/25/2021, 1:03 PMAshrith Reddy
10/25/2021, 1:04 PMRyan
10/25/2021, 2:43 PMAshrith Reddy
10/25/2021, 3:45 PMconst clearUser = async () => {
return prisma.$transaction(async (p) => {
const user = p.user.update({ where: { id: 1 }, data: { deleted: true }})
const findUser = await p.user.fineOne({ where: { id: 1 }})
return findUser.deleted
})
}
const user = await clearUser() // should return true, but in actual it is returning false.
Ryan
10/25/2021, 5:16 PMawait
before the p.user.update call.Ashrith Reddy
10/25/2021, 5:19 PM