@strapi/database 4.9.0 → 4.10.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/jest.config.js CHANGED
@@ -1,5 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ const baseConfig = require('../../../jest.base-config');
4
+ const pkg = require('./package.json');
5
+
3
6
  module.exports = {
4
- preset: '../../../jest-preset.unit.js',
7
+ ...baseConfig,
8
+ displayName: (pkg.strapi && pkg.strapi.name) || pkg.name,
9
+ roots: [__dirname],
5
10
  };
@@ -96,8 +96,15 @@ const createRepository = (uid, db) => {
96
96
  return db.entityManager.attachRelations(uid, id, data);
97
97
  },
98
98
 
99
- updateRelations(id, data) {
100
- return db.entityManager.updateRelations(uid, id, data);
99
+ async updateRelations(id, data) {
100
+ const trx = await db.transaction();
101
+ try {
102
+ await db.entityManager.updateRelations(uid, id, data, { transaction: trx.get() });
103
+ return trx.commit();
104
+ } catch (e) {
105
+ await trx.rollback();
106
+ throw e;
107
+ }
101
108
  },
102
109
 
103
110
  deleteRelations(id) {
@@ -268,12 +268,9 @@ const createEntityManager = (db) => {
268
268
  throw new Error('Nothing to insert');
269
269
  }
270
270
 
271
- const createdEntries = await this.createQueryBuilder(uid).insert(dataToInsert).execute();
271
+ await this.createQueryBuilder(uid).insert(dataToInsert).execute();
272
272
 
273
- const result = {
274
- count: data.length,
275
- ids: createdEntries.map((entry) => (typeof entry === 'object' ? entry?.id : entry)),
276
- };
273
+ const result = { count: data.length };
277
274
 
278
275
  await db.lifecycles.run('afterCreateMany', uid, { params, result }, states);
279
276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/database",
3
- "version": "4.9.0",
3
+ "version": "4.10.0-beta.0",
4
4
  "description": "Strapi's database layer",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -28,9 +28,7 @@
28
28
  "lib": "./lib"
29
29
  },
30
30
  "scripts": {
31
- "test:unit": "jest",
32
- "test:unit:watch": "jest --watch",
33
- "lint": "eslint ."
31
+ "test:unit": "jest --verbose"
34
32
  },
35
33
  "dependencies": {
36
34
  "date-fns": "2.29.3",
@@ -45,5 +43,5 @@
45
43
  "node": ">=14.19.1 <=18.x.x",
46
44
  "npm": ">=6.0.0"
47
45
  },
48
- "gitHead": "ffe3f4621ccc968ce56fda9a8317ec30d4bad205"
46
+ "gitHead": "1519ef0e56d27b738f24fc88223797651ad47aaf"
49
47
  }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- node_modules/
2
- .eslintrc.js
package/.eslintrc.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: ['custom/back'],
4
- };
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- // Test an API with all the possible filed types and simple filterings (no deep filtering, no relations)
4
- const { createStrapiInstance } = require('../../../../test/helpers/strapi');
5
- const { createTestBuilder } = require('../../../../test/helpers/builder');
6
-
7
- const builder = createTestBuilder();
8
- let strapi;
9
-
10
- const testCT = {
11
- displayName: 'test',
12
- singularName: 'test',
13
- pluralName: 'tests',
14
- kind: 'collectionType',
15
- attributes: {
16
- name: {
17
- type: 'string',
18
- },
19
- },
20
- };
21
-
22
- const fixtures = {
23
- test: [
24
- {
25
- name: 'Hugo LLORIS',
26
- },
27
- {
28
- name: 'Samuel UMTITI',
29
- },
30
- {
31
- name: 'Lucas HERNANDEZ',
32
- },
33
- ],
34
- };
35
-
36
- describe('Deep Filtering API', () => {
37
- beforeAll(async () => {
38
- await builder.addContentType(testCT).build();
39
-
40
- strapi = await createStrapiInstance();
41
- });
42
-
43
- afterAll(async () => {
44
- await strapi.destroy();
45
- await builder.cleanup();
46
- });
47
-
48
- test('Return an array of ids on createMany', async () => {
49
- const res = await strapi.db.query('api::test.test').createMany({ data: fixtures.test });
50
-
51
- expect(res).toMatchObject({ count: expect.any(Number) });
52
- expect(Array.isArray(res.ids)).toBe(true);
53
- expect(res.ids.length > 0).toBe(true);
54
- });
55
- });