strapi.connections.default.transaction code example
Example: how to do database transactions with strapi
await strapi.connections.default.transaction(async (transacting) => {
mediaFile = await strapi.services['media-file'].getOrCreate(
{ md5 },
mediaFileData,
{ transacting }
);
const clip = await strapi.services.clip.findOne({ id }, null, {
transacting,
});
await strapi.services.clip.update(
{ id },
{
mediaFiles: _.uniq([...clip.mediaFiles, mediaFile.id]),
},
{ transacting }
);
});