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:
committed by
Facebook GitHub Bot
parent
b57612a116
commit
54bf6440de
@@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user