Allow to Edit only When There Is Primary Key in Table

Summary: To be able to edit correct cell, identifiers are needed. Assume that the primary key is unique, this should be safe to allow the query to find exactly one row to edit

Reviewed By: jknoxville

Differential Revision: D21788239

fbshipit-source-id: b09d1b6da1b46cbc961f08010467e973546acbef
This commit is contained in:
Chaiwat Ekkaewnumchai
2020-06-02 01:44:21 -07:00
committed by Facebook GitHub Bot
parent b57612a116
commit 54bf6440de
2 changed files with 26 additions and 2 deletions

View File

@@ -71,3 +71,17 @@ export function constructUpdateQuery(
SET ${constructQueryClause(change, ',')}
WHERE ${constructQueryClause(where, 'AND')}`;
}
export function isUpdatable(
columnMeta: Array<string>,
columnData: Array<Array<Value>>,
): boolean {
const primaryKeyIdx = columnMeta.indexOf('primary_key');
return (
primaryKeyIdx >= 0 &&
columnData.reduce((acc: boolean, column) => {
const primaryValue = column[primaryKeyIdx];
return acc || (primaryValue.type === 'boolean' && primaryValue.value);
}, false)
);
}