@strapi/database
Advanced tools
Comparing version 0.0.0-c39ddc8bb0f591395e2060bd2236d1cf08f609d7 to 0.0.0-c44f21d5ba95d3f2fbba239cf241081dddd54dd7
@@ -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; |
@@ -779,3 +779,2 @@ 'use strict'; | ||
// TODO: support multiple relations at once with the populate syntax | ||
// TODO: add lifecycle events | ||
@@ -792,12 +791,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`); | ||
} | ||
}); | ||
@@ -807,5 +808,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; | ||
}, {}), | ||
}); | ||
@@ -817,3 +819,7 @@ | ||
return entry[field]; | ||
if (Array.isArray(fields)) { | ||
return _.pick(fields, entry); | ||
} | ||
return entry[fields]; | ||
}, | ||
@@ -820,0 +826,0 @@ |
@@ -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', |
@@ -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 @@ |
{ | ||
"name": "@strapi/database", | ||
"version": "0.0.0-c39ddc8bb0f591395e2060bd2236d1cf08f609d7", | ||
"version": "0.0.0-c44f21d5ba95d3f2fbba239cf241081dddd54dd7", | ||
"description": "Strapi's database layer", | ||
@@ -45,3 +45,3 @@ "homepage": "https://strapi.io", | ||
}, | ||
"gitHead": "c39ddc8bb0f591395e2060bd2236d1cf08f609d7" | ||
"gitHead": "c44f21d5ba95d3f2fbba239cf241081dddd54dd7" | ||
} |
179602
5760