how to do database transactions with strapi

Solutions on MaxInterview for how to do database transactions with strapi by the best coders in the world

showing results for - "how to do database transactions with strapi"
Luigi
30 Apr 2017
1      await strapi.connections.default.transaction(async (transacting) => {
2
3        mediaFile = await strapi.services['media-file'].getOrCreate(
4          { md5 },
5          mediaFileData,
6          { transacting }
7        );
8
9        const clip = await strapi.services.clip.findOne({ id }, null, {
10          transacting,
11        });
12
13        await strapi.services.clip.update(
14          { id },
15          {
16            mediaFiles: _.uniq([...clip.mediaFiles, mediaFile.id]),
17          },
18          { transacting }
19        );
20      });