Skip to main content

commit()

Last updated 10/09/2024

Example

The following code checks if the database connection is ok and starts a transaction to insert data into the database. If the transaction is successful the data will be committed to the database using the

commit()
.

Commits the transaction to the database using commit()
function CreateRemoteRecord(five: Five, context: any, result: FiveError) : FiveError {
const db = five.getDatabaseConnectionByID('OffsiteDatabase');
if (db.isOk() === false ) {
return five.createError(db, 'Cannot get connection to database');
}

const tx = five.startTransaction(db);
if (tx.isOk() === false ) {
return five.createError(tx, 'Cannot start transaction');
}

const insertSQL = `INSERT INTO Receipt (ReceiptKey, CreateDateTime, CreatedBy, ReceiptNumber, Description) VALUES (?, SysDateTime(), ?, ?, ?)`;
const insertResult = five.executeQuery(tx, insertSQL, 0, five.uuid(), five.currentUserKey(), context.ReceiptNumber, conttext.Description);
const commitResult = five.commit(tx);
if (commitResult.isOk() === false ) {
return five.createError(commitResult, 'Failed to commit update');
}

return five.success(result);
}