@strapi/database
Advanced tools
Comparing version 4.4.0-alpha.0 to 4.4.0-beta.0
@@ -47,2 +47,6 @@ 'use strict'; | ||
} | ||
canAddIncrements() { | ||
return true; | ||
} | ||
} | ||
@@ -49,0 +53,0 @@ |
@@ -27,2 +27,6 @@ 'use strict'; | ||
useReturning() { | ||
return true; | ||
} | ||
async initialize() { | ||
@@ -72,4 +76,8 @@ await this.db.connection.raw('pragma foreign_keys = on'); | ||
} | ||
canAddIncrements() { | ||
return false; | ||
} | ||
} | ||
module.exports = SqliteDialect; |
@@ -37,3 +37,3 @@ 'use strict'; | ||
for (const attributeName in attributes) { | ||
for (const attributeName of Object.keys(attributes)) { | ||
const attribute = attributes[attributeName]; | ||
@@ -337,3 +337,3 @@ | ||
for (const attributeName in attributes) { | ||
for (const attributeName of Object.keys(attributes)) { | ||
const attribute = attributes[attributeName]; | ||
@@ -492,3 +492,3 @@ | ||
for (const attributeName in attributes) { | ||
for (const attributeName of Object.keys(attributes)) { | ||
const attribute = attributes[attributeName]; | ||
@@ -673,3 +673,3 @@ | ||
for (const attributeName in attributes) { | ||
for (const attributeName of Object.keys(attributes)) { | ||
const attribute = attributes[attributeName]; | ||
@@ -783,3 +783,2 @@ | ||
// TODO: support multiple relations at once with the populate syntax | ||
// TODO: add lifecycle events | ||
@@ -796,12 +795,14 @@ async populate(uid, entity, populate) { | ||
// TODO: support multiple relations at once with the populate syntax | ||
// TODO: add lifecycle events | ||
async load(uid, entity, field, params) { | ||
async load(uid, entity, fields, params) { | ||
const { attributes } = db.metadata.get(uid); | ||
const attribute = attributes[field]; | ||
const fieldsArr = _.castArray(fields); | ||
fieldsArr.forEach((field) => { | ||
const attribute = attributes[field]; | ||
if (!attribute || attribute.type !== 'relation') { | ||
throw new Error('Invalid load. Expected a relational attribute'); | ||
} | ||
if (!attribute || attribute.type !== 'relation') { | ||
throw new Error(`Invalid load. Expected ${field} to be a relational attribute`); | ||
} | ||
}); | ||
@@ -811,5 +812,6 @@ const entry = await this.findOne(uid, { | ||
where: { id: entity.id }, | ||
populate: { | ||
[field]: params || true, | ||
}, | ||
populate: fieldsArr.reduce((acc, field) => { | ||
acc[field] = params || true; | ||
return acc; | ||
}, {}), | ||
}); | ||
@@ -821,3 +823,7 @@ | ||
return entry[field]; | ||
if (Array.isArray(fields)) { | ||
return _.pick(fields, entry); | ||
} | ||
return entry[fields]; | ||
}, | ||
@@ -824,0 +830,0 @@ |
@@ -57,3 +57,3 @@ 'use strict'; | ||
async run(action, uid, properties, states = new Map()) { | ||
for (let i = 0; i < subscribers.length; i++) { | ||
for (let i = 0; i < subscribers.length; i += 1) { | ||
const subscriber = subscribers[i]; | ||
@@ -60,0 +60,0 @@ if (typeof subscriber === 'function') { |
@@ -209,2 +209,5 @@ /** | ||
attributes: { | ||
id: { | ||
type: 'increments', | ||
}, | ||
[joinColumnName]: { | ||
@@ -408,2 +411,5 @@ type: 'integer', | ||
attributes: { | ||
id: { | ||
type: 'increments', | ||
}, | ||
[joinColumnName]: { | ||
@@ -410,0 +416,0 @@ type: 'integer', |
@@ -74,3 +74,3 @@ 'use strict'; | ||
if (on) { | ||
for (const key in on) { | ||
for (const key of Object.keys(on)) { | ||
inner.onVal(`${alias}.${key}`, on[key]); | ||
@@ -77,0 +77,0 @@ } |
@@ -11,3 +11,3 @@ 'use strict'; | ||
for (const attributeName in meta.attributes) { | ||
for (const attributeName of Object.keys(meta.attributes)) { | ||
const attribute = meta.attributes[attributeName]; | ||
@@ -76,3 +76,3 @@ if (attribute.type === 'relation') { | ||
const finalPopulate = {}; | ||
for (const key in populateMap) { | ||
for (const key of Object.keys(populateMap)) { | ||
const attribute = meta.attributes[key]; | ||
@@ -124,3 +124,3 @@ | ||
for (const key in populate) { | ||
for (const key of Object.keys(populate)) { | ||
const attribute = meta.attributes[key]; | ||
@@ -546,3 +546,3 @@ const targetMeta = db.metadata.get(attribute.target); | ||
const map = {}; | ||
for (const type in idsByType) { | ||
for (const type of Object.keys(idsByType)) { | ||
const ids = idsByType[type]; | ||
@@ -611,3 +611,3 @@ | ||
const map = {}; | ||
for (const type in idsByType) { | ||
for (const type of Object.keys(idsByType)) { | ||
const ids = idsByType[type]; | ||
@@ -614,0 +614,0 @@ |
@@ -56,3 +56,3 @@ 'use strict'; | ||
for (const key in data) { | ||
for (const key of Object.keys(data)) { | ||
const attribute = attributes[key]; | ||
@@ -59,0 +59,0 @@ |
@@ -79,3 +79,3 @@ 'use strict'; | ||
for (const key in where) { | ||
for (const key of Object.keys(where)) { | ||
const value = where[key]; | ||
@@ -123,3 +123,3 @@ | ||
// for each key in where | ||
for (const key in where) { | ||
for (const key of Object.keys(where)) { | ||
const value = where[key]; | ||
@@ -126,0 +126,0 @@ |
@@ -30,4 +30,10 @@ 'use strict'; | ||
let counter = 0; | ||
const getAlias = () => `t${counter++}`; | ||
const getAlias = () => { | ||
const alias = `t${counter}`; | ||
counter += 1; | ||
return alias; | ||
}; | ||
return { | ||
@@ -34,0 +40,0 @@ alias: getAlias(), |
@@ -293,3 +293,2 @@ 'use strict'; | ||
// Update existing columns / foreign keys / indexes | ||
for (const updatedColumn of table.columns.updated) { | ||
@@ -300,3 +299,7 @@ debug(`Updating column ${updatedColumn.name}`); | ||
createColumn(tableBuilder, object).alter(); | ||
if (object.type === 'increments') { | ||
createColumn(tableBuilder, { ...object, type: 'integer' }).alter(); | ||
} else { | ||
createColumn(tableBuilder, object).alter(); | ||
} | ||
} | ||
@@ -316,3 +319,9 @@ | ||
debug(`Creating column ${addedColumn.name}`); | ||
createColumn(tableBuilder, addedColumn); | ||
if (addedColumn.type === 'increments' && !db.dialect.canAddIncrements()) { | ||
tableBuilder.integer(addedColumn.name).unsigned(); | ||
tableBuilder.primary(addedColumn.name); | ||
} else { | ||
createColumn(tableBuilder, addedColumn); | ||
} | ||
} | ||
@@ -319,0 +328,0 @@ |
@@ -28,3 +28,3 @@ 'use strict'; | ||
for (const key in meta.attributes) { | ||
for (const key of Object.keys(meta.attributes)) { | ||
const attribute = meta.attributes[key]; | ||
@@ -31,0 +31,0 @@ |
{ | ||
"name": "@strapi/database", | ||
"version": "4.4.0-alpha.0", | ||
"version": "4.4.0-beta.0", | ||
"description": "Strapi's database layer", | ||
@@ -42,6 +42,6 @@ "homepage": "https://strapi.io", | ||
"engines": { | ||
"node": ">=14.19.1 <=16.x.x", | ||
"node": ">=14.19.1 <=18.x.x", | ||
"npm": ">=6.0.0" | ||
}, | ||
"gitHead": "fc78298ae4f9b247d636beda568734d5f8ed7b3e" | ||
"gitHead": "cae16f7f259fa4473a55e8fea57839cda98f34ae" | ||
} |
179814
5764