Is a method to remove a record from both the display screen and the database of the user
xxxxxxxxxx
async delete(): Promise<void> {
To reveal the entity and database name, de-structure this page's subject.
xxxxxxxxxx
const [ename, dbname] = this.subject;
Get the selected table-row if any is selected and otherwise alert the user to make a selection
xxxxxxxxxx
const tr = this.document.querySelector(".TR");
if (tr === null) {
alert("Please select a row to delete");
return;
}
Get the primary key of the currently selected record .
xxxxxxxxxx
const pk = tr.getAttribute("pk");
Ensure that the entity name is enclosed with backticks and then formulate a SQL statement to perform the deletion.
xxxxxxxxxx
const ename_str = `\`${ename}\``;
const sql = `Delete from ${ename_str} where ${ename_str}
.${ename_str}='${pk}'`;
Execute the delete query on the server and return the number of affected records.
xxxxxxxxxx
const records = await server.exec("database", [dbname], "query", [sql]);
Finally check if the deletion was successful, if not report an error(mutall_error).
xxxxxxxxxx
if (records !== 1) {
throw new schema.mutall_error(`The following query was not successful:
${sql}`);
}
Refresh the homepage to reflect/show the changes that have been carried out i.e. remove the row from the table in the user interface.
xxxxxxxxxx
tr.parentNode!.removeChild(tr);
}