@strapi/database 4.14.4 → 4.14.6
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/README.md +3 -0
- package/dist/connection.d.ts +3 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/dialects/dialect.d.ts +27 -0
- package/dist/dialects/dialect.d.ts.map +1 -0
- package/dist/dialects/index.d.ts +5 -0
- package/dist/dialects/index.d.ts.map +1 -0
- package/dist/dialects/mysql/constants.d.ts +3 -0
- package/dist/dialects/mysql/constants.d.ts.map +1 -0
- package/dist/dialects/mysql/database-inspector.d.ts +12 -0
- package/dist/dialects/mysql/database-inspector.d.ts.map +1 -0
- package/dist/dialects/mysql/index.d.ts +20 -0
- package/dist/dialects/mysql/index.d.ts.map +1 -0
- package/dist/dialects/mysql/schema-inspector.d.ts +13 -0
- package/dist/dialects/mysql/schema-inspector.d.ts.map +1 -0
- package/dist/dialects/postgresql/index.d.ts +14 -0
- package/dist/dialects/postgresql/index.d.ts.map +1 -0
- package/dist/dialects/postgresql/schema-inspector.d.ts +14 -0
- package/dist/dialects/postgresql/schema-inspector.d.ts.map +1 -0
- package/dist/dialects/sqlite/index.d.ts +19 -0
- package/dist/dialects/sqlite/index.d.ts.map +1 -0
- package/dist/dialects/sqlite/schema-inspector.d.ts +13 -0
- package/dist/dialects/sqlite/schema-inspector.d.ts.map +1 -0
- package/dist/entity-manager/entity-repository.d.ts +4 -0
- package/dist/entity-manager/entity-repository.d.ts.map +1 -0
- package/dist/entity-manager/index.d.ts +5 -0
- package/dist/entity-manager/index.d.ts.map +1 -0
- package/dist/entity-manager/morph-relations.d.ts +13 -0
- package/dist/entity-manager/morph-relations.d.ts.map +1 -0
- package/dist/entity-manager/regular-relations.d.ts +83 -0
- package/dist/entity-manager/regular-relations.d.ts.map +1 -0
- package/dist/entity-manager/relations/cloning/regular-relations.d.ts +17 -0
- package/dist/entity-manager/relations/cloning/regular-relations.d.ts.map +1 -0
- package/dist/entity-manager/relations-orderer.d.ts +73 -0
- package/dist/entity-manager/relations-orderer.d.ts.map +1 -0
- package/dist/entity-manager/types.d.ts +97 -0
- package/dist/entity-manager/types.d.ts.map +1 -0
- package/dist/errors/database.d.ts +5 -0
- package/dist/errors/database.d.ts.map +1 -0
- package/dist/errors/index.d.ts +8 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/invalid-date.d.ts +5 -0
- package/dist/errors/invalid-date.d.ts.map +1 -0
- package/dist/errors/invalid-datetime.d.ts +5 -0
- package/dist/errors/invalid-datetime.d.ts.map +1 -0
- package/dist/errors/invalid-relation.d.ts +5 -0
- package/dist/errors/invalid-relation.d.ts.map +1 -0
- package/dist/errors/invalid-time.d.ts +5 -0
- package/dist/errors/invalid-time.d.ts.map +1 -0
- package/dist/errors/not-null.d.ts +7 -0
- package/dist/errors/not-null.d.ts.map +1 -0
- package/dist/fields/biginteger.d.ts +4 -0
- package/dist/fields/biginteger.d.ts.map +1 -0
- package/dist/fields/boolean.d.ts +6 -0
- package/dist/fields/boolean.d.ts.map +1 -0
- package/dist/fields/date.d.ts +6 -0
- package/dist/fields/date.d.ts.map +1 -0
- package/dist/fields/datetime.d.ts +6 -0
- package/dist/fields/datetime.d.ts.map +1 -0
- package/dist/fields/field.d.ts +7 -0
- package/dist/fields/field.d.ts.map +1 -0
- package/dist/fields/index.d.ts +4 -0
- package/dist/fields/index.d.ts.map +1 -0
- package/dist/fields/json.d.ts +6 -0
- package/dist/fields/json.d.ts.map +1 -0
- package/dist/fields/number.d.ts +6 -0
- package/dist/fields/number.d.ts.map +1 -0
- package/dist/fields/shared/parsers.d.ts +4 -0
- package/dist/fields/shared/parsers.d.ts.map +1 -0
- package/dist/fields/string.d.ts +6 -0
- package/dist/fields/string.d.ts.map +1 -0
- package/dist/fields/time.d.ts +6 -0
- package/dist/fields/time.d.ts.map +1 -0
- package/dist/fields/timestamp.d.ts +6 -0
- package/dist/fields/timestamp.d.ts.map +1 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6211 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6179 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lifecycles/index.d.ts +17 -0
- package/dist/lifecycles/index.d.ts.map +1 -0
- package/dist/lifecycles/subscribers/index.d.ts +5 -0
- package/dist/lifecycles/subscribers/index.d.ts.map +1 -0
- package/dist/lifecycles/subscribers/models-lifecycles.d.ts +6 -0
- package/dist/lifecycles/subscribers/models-lifecycles.d.ts.map +1 -0
- package/dist/lifecycles/subscribers/timestamps.d.ts +3 -0
- package/dist/lifecycles/subscribers/timestamps.d.ts.map +1 -0
- package/dist/lifecycles/types.d.ts +25 -0
- package/dist/lifecycles/types.d.ts.map +1 -0
- package/dist/metadata/index.d.ts +10 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/metadata.d.ts +22 -0
- package/dist/metadata/metadata.d.ts.map +1 -0
- package/dist/metadata/relations.d.ts +16 -0
- package/dist/metadata/relations.d.ts.map +1 -0
- package/dist/migrations/index.d.ts +12 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/storage.d.ts +15 -0
- package/dist/migrations/storage.d.ts.map +1 -0
- package/dist/query/helpers/index.d.ts +8 -0
- package/dist/query/helpers/index.d.ts.map +1 -0
- package/dist/query/helpers/join.d.ts +30 -0
- package/dist/query/helpers/join.d.ts.map +1 -0
- package/dist/query/helpers/order-by.d.ts +14 -0
- package/dist/query/helpers/order-by.d.ts.map +1 -0
- package/dist/query/helpers/populate/apply.d.ts +11 -0
- package/dist/query/helpers/populate/apply.d.ts.map +1 -0
- package/dist/query/helpers/populate/index.d.ts +4 -0
- package/dist/query/helpers/populate/index.d.ts.map +1 -0
- package/dist/query/helpers/populate/process.d.ts +24 -0
- package/dist/query/helpers/populate/process.d.ts.map +1 -0
- package/dist/query/helpers/search.d.ts +4 -0
- package/dist/query/helpers/search.d.ts.map +1 -0
- package/dist/query/helpers/streams/index.d.ts +2 -0
- package/dist/query/helpers/streams/index.d.ts.map +1 -0
- package/dist/query/helpers/streams/readable.d.ts +39 -0
- package/dist/query/helpers/streams/readable.d.ts.map +1 -0
- package/dist/query/helpers/transform.d.ts +8 -0
- package/dist/query/helpers/transform.d.ts.map +1 -0
- package/dist/query/helpers/where.d.ts +19 -0
- package/dist/query/helpers/where.d.ts.map +1 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/query-builder.d.ts +79 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/types.d.ts +8 -0
- package/dist/query/types.d.ts.map +1 -0
- package/dist/schema/builder.d.ts +33 -0
- package/dist/schema/builder.d.ts.map +1 -0
- package/dist/schema/diff.d.ts +7 -0
- package/dist/schema/diff.d.ts.map +1 -0
- package/dist/schema/index.d.ts +20 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/schema.d.ts +4 -0
- package/dist/schema/schema.d.ts.map +1 -0
- package/dist/schema/storage.d.ts +10 -0
- package/dist/schema/storage.d.ts.map +1 -0
- package/dist/schema/types.d.ts +103 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/transaction-context.d.ts +22 -0
- package/dist/transaction-context.d.ts.map +1 -0
- package/dist/types/index.d.ts +169 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/content-types.d.ts +13 -0
- package/dist/utils/content-types.d.ts.map +1 -0
- package/dist/utils/knex.d.ts +12 -0
- package/dist/utils/knex.d.ts.map +1 -0
- package/dist/utils/types.d.ts +10 -0
- package/dist/utils/types.d.ts.map +1 -0
- package/dist/validations/index.d.ts +6 -0
- package/dist/validations/index.d.ts.map +1 -0
- package/dist/validations/relations/bidirectional.d.ts +12 -0
- package/dist/validations/relations/bidirectional.d.ts.map +1 -0
- package/dist/validations/relations/index.d.ts +7 -0
- package/dist/validations/relations/index.d.ts.map +1 -0
- package/package.json +20 -8
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -4
- package/jest.config.js +0 -6
- package/lib/__tests__/index.test.js +0 -93
- package/lib/__tests__/lifecycles.test.js +0 -55
- package/lib/connection.js +0 -64
- package/lib/dialects/dialect.js +0 -63
- package/lib/dialects/index.js +0 -53
- package/lib/dialects/mysql/constants.js +0 -6
- package/lib/dialects/mysql/database-inspector.js +0 -37
- package/lib/dialects/mysql/index.js +0 -92
- package/lib/dialects/mysql/schema-inspector.js +0 -234
- package/lib/dialects/postgresql/index.js +0 -65
- package/lib/dialects/postgresql/schema-inspector.js +0 -283
- package/lib/dialects/sqlite/index.js +0 -87
- package/lib/dialects/sqlite/schema-inspector.js +0 -151
- package/lib/entity-manager/__tests__/relations-orderer.test.js +0 -186
- package/lib/entity-manager/__tests__/sort-connect-array.test.js +0 -79
- package/lib/entity-manager/entity-repository.js +0 -164
- package/lib/entity-manager/index.js +0 -1385
- package/lib/entity-manager/morph-relations.js +0 -63
- package/lib/entity-manager/regular-relations.js +0 -506
- package/lib/entity-manager/relations/cloning/regular-relations.js +0 -76
- package/lib/entity-manager/relations-orderer.js +0 -225
- package/lib/errors/database.js +0 -12
- package/lib/errors/index.js +0 -17
- package/lib/errors/invalid-date.js +0 -14
- package/lib/errors/invalid-datetime.js +0 -14
- package/lib/errors/invalid-relation.js +0 -14
- package/lib/errors/invalid-time.js +0 -14
- package/lib/errors/not-null.js +0 -15
- package/lib/fields/biginteger.js +0 -17
- package/lib/fields/boolean.js +0 -39
- package/lib/fields/date.js +0 -16
- package/lib/fields/datetime.js +0 -19
- package/lib/fields/field.js +0 -17
- package/lib/fields/index.d.ts +0 -9
- package/lib/fields/index.js +0 -50
- package/lib/fields/json.js +0 -21
- package/lib/fields/number.js +0 -23
- package/lib/fields/shared/parsers.js +0 -71
- package/lib/fields/string.js +0 -17
- package/lib/fields/time.js +0 -17
- package/lib/fields/timestamp.js +0 -19
- package/lib/index.d.ts +0 -198
- package/lib/index.js +0 -129
- package/lib/lifecycles/index.d.ts +0 -51
- package/lib/lifecycles/index.js +0 -90
- package/lib/lifecycles/subscribers/index.d.ts +0 -11
- package/lib/lifecycles/subscribers/models-lifecycles.js +0 -19
- package/lib/lifecycles/subscribers/timestamps.js +0 -65
- package/lib/metadata/index.js +0 -244
- package/lib/metadata/relations.js +0 -578
- package/lib/migrations/index.d.ts +0 -9
- package/lib/migrations/index.js +0 -75
- package/lib/migrations/storage.js +0 -44
- package/lib/query/helpers/index.js +0 -11
- package/lib/query/helpers/join.js +0 -96
- package/lib/query/helpers/order-by.js +0 -70
- package/lib/query/helpers/populate/apply.js +0 -664
- package/lib/query/helpers/populate/index.js +0 -9
- package/lib/query/helpers/populate/process.js +0 -102
- package/lib/query/helpers/search.js +0 -84
- package/lib/query/helpers/streams/index.js +0 -5
- package/lib/query/helpers/streams/readable.js +0 -174
- package/lib/query/helpers/transform.js +0 -84
- package/lib/query/helpers/where.js +0 -365
- package/lib/query/index.js +0 -7
- package/lib/query/query-builder.js +0 -514
- package/lib/schema/__tests__/schema-diff.test.js +0 -231
- package/lib/schema/builder.js +0 -386
- package/lib/schema/diff.js +0 -399
- package/lib/schema/index.d.ts +0 -49
- package/lib/schema/index.js +0 -94
- package/lib/schema/schema.js +0 -202
- package/lib/schema/storage.js +0 -76
- package/lib/transaction-context.js +0 -68
- package/lib/types/index.d.ts +0 -6
- package/lib/types/index.js +0 -35
- package/lib/utils/content-types.js +0 -40
- package/lib/utils/knex.js +0 -22
- package/lib/validations/index.js +0 -20
- package/lib/validations/relations/bidirectional.js +0 -89
- package/lib/validations/relations/index.js +0 -14
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const createPivotJoin = (ctx, { alias, refAlias, joinTable, targetMeta }) => {
|
|
4
|
-
const { qb } = ctx;
|
|
5
|
-
const joinAlias = qb.getAlias();
|
|
6
|
-
qb.join({
|
|
7
|
-
alias: joinAlias,
|
|
8
|
-
referencedTable: joinTable.name,
|
|
9
|
-
referencedColumn: joinTable.joinColumn.name,
|
|
10
|
-
rootColumn: joinTable.joinColumn.referencedColumn,
|
|
11
|
-
rootTable: alias,
|
|
12
|
-
on: joinTable.on,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const subAlias = refAlias || qb.getAlias();
|
|
16
|
-
qb.join({
|
|
17
|
-
alias: subAlias,
|
|
18
|
-
referencedTable: targetMeta.tableName,
|
|
19
|
-
referencedColumn: joinTable.inverseJoinColumn.referencedColumn,
|
|
20
|
-
rootColumn: joinTable.inverseJoinColumn.name,
|
|
21
|
-
rootTable: joinAlias,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
return subAlias;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const createJoin = (ctx, { alias, refAlias, attributeName, attribute }) => {
|
|
28
|
-
const { db, qb } = ctx;
|
|
29
|
-
|
|
30
|
-
if (attribute.type !== 'relation') {
|
|
31
|
-
throw new Error(`Cannot join on non relational field ${attributeName}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const targetMeta = db.metadata.get(attribute.target);
|
|
35
|
-
|
|
36
|
-
const { joinColumn } = attribute;
|
|
37
|
-
|
|
38
|
-
if (joinColumn) {
|
|
39
|
-
const subAlias = refAlias || qb.getAlias();
|
|
40
|
-
qb.join({
|
|
41
|
-
alias: subAlias,
|
|
42
|
-
referencedTable: targetMeta.tableName,
|
|
43
|
-
referencedColumn: joinColumn.referencedColumn,
|
|
44
|
-
rootColumn: joinColumn.name,
|
|
45
|
-
rootTable: alias,
|
|
46
|
-
});
|
|
47
|
-
return subAlias;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { joinTable } = attribute;
|
|
51
|
-
if (joinTable) {
|
|
52
|
-
return createPivotJoin(ctx, { alias, refAlias, joinTable, targetMeta });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return alias;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// TODO: toColumnName for orderBy & on
|
|
59
|
-
const applyJoin = (qb, join) => {
|
|
60
|
-
const {
|
|
61
|
-
method = 'leftJoin',
|
|
62
|
-
alias,
|
|
63
|
-
referencedTable,
|
|
64
|
-
referencedColumn,
|
|
65
|
-
rootColumn,
|
|
66
|
-
rootTable = qb.alias,
|
|
67
|
-
on,
|
|
68
|
-
orderBy,
|
|
69
|
-
} = join;
|
|
70
|
-
|
|
71
|
-
qb[method](`${referencedTable} as ${alias}`, (inner) => {
|
|
72
|
-
inner.on(`${rootTable}.${rootColumn}`, `${alias}.${referencedColumn}`);
|
|
73
|
-
|
|
74
|
-
if (on) {
|
|
75
|
-
for (const key of Object.keys(on)) {
|
|
76
|
-
inner.onVal(`${alias}.${key}`, on[key]);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (orderBy) {
|
|
82
|
-
Object.keys(orderBy).forEach((column) => {
|
|
83
|
-
const direction = orderBy[column];
|
|
84
|
-
qb.orderBy(`${alias}.${column}`, direction);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const applyJoins = (qb, joins) => joins.forEach((join) => applyJoin(qb, join));
|
|
90
|
-
|
|
91
|
-
module.exports = {
|
|
92
|
-
createJoin,
|
|
93
|
-
createPivotJoin,
|
|
94
|
-
applyJoins,
|
|
95
|
-
applyJoin,
|
|
96
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash/fp');
|
|
4
|
-
|
|
5
|
-
const types = require('../../types');
|
|
6
|
-
const { createJoin } = require('./join');
|
|
7
|
-
const { toColumnName } = require('./transform');
|
|
8
|
-
|
|
9
|
-
const processOrderBy = (orderBy, ctx) => {
|
|
10
|
-
const { db, uid, qb, alias } = ctx;
|
|
11
|
-
const meta = db.metadata.get(uid);
|
|
12
|
-
const { attributes } = meta;
|
|
13
|
-
|
|
14
|
-
if (typeof orderBy === 'string') {
|
|
15
|
-
const attribute = attributes[orderBy];
|
|
16
|
-
|
|
17
|
-
if (!attribute) {
|
|
18
|
-
throw new Error(`Attribute ${orderBy} not found on model ${uid}`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const columnName = toColumnName(meta, orderBy);
|
|
22
|
-
|
|
23
|
-
return [{ column: qb.aliasColumn(columnName, alias) }];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (Array.isArray(orderBy)) {
|
|
27
|
-
return orderBy.flatMap((value) => processOrderBy(value, ctx));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (_.isPlainObject(orderBy)) {
|
|
31
|
-
return Object.entries(orderBy).flatMap(([key, direction]) => {
|
|
32
|
-
const value = orderBy[key];
|
|
33
|
-
const attribute = attributes[key];
|
|
34
|
-
|
|
35
|
-
if (!attribute) {
|
|
36
|
-
throw new Error(`Attribute ${key} not found on model ${uid}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (types.isScalar(attribute.type)) {
|
|
40
|
-
const columnName = toColumnName(meta, key);
|
|
41
|
-
|
|
42
|
-
return { column: qb.aliasColumn(columnName, alias), order: direction };
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (attribute.type === 'relation') {
|
|
46
|
-
const subAlias = createJoin(ctx, {
|
|
47
|
-
alias: alias || qb.alias,
|
|
48
|
-
uid,
|
|
49
|
-
attributeName: key,
|
|
50
|
-
attribute,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return processOrderBy(value, {
|
|
54
|
-
db,
|
|
55
|
-
qb,
|
|
56
|
-
alias: subAlias,
|
|
57
|
-
uid: attribute.target,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
throw new Error(`You cannot order on ${attribute.type} types`);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
throw new Error('Invalid orderBy syntax');
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
module.exports = {
|
|
69
|
-
processOrderBy,
|
|
70
|
-
};
|