sqlite FK analyser, query runs in transaction

This commit is contained in:
Jan Prochazka
2021-05-06 14:11:51 +02:00
parent e251459512
commit 615397f332
2 changed files with 67 additions and 33 deletions

View File

@@ -46,6 +46,23 @@ class Analyser extends DatabaseAnalyser {
};
}
const fklist = await this.driver.query(this.pool, `pragma foreign_key_list('${tableName}')`);
tableObj.foreignKeys = _.values(_.groupBy(fklist.rows, 'id')).map((fkcols) => {
const fkcol = fkcols[0];
const fk = {
pureName: tableName,
refTableName: fkcol.table,
columns: fkcols.map((col) => ({
columnName: col.from,
refColumnName: col.to,
})),
updateAction: fkcol.on_update,
deleteAction: fkcol.on_delete,
constraintName: `FK_${tableName}_${fkcol.id}`,
};
return fk;
});
// console.log(info);
}