It’s hard for me to suggest anything without knowing what you’re trying to achieve in detail.
But you can delete records from the ItemsForSale database table either from client side or cloud functions, the code is basically the same. The choice can be related to security or the way you prefer to use the api.
In cloud functions you will need to override CLP and ACL security that is set on tables using the MasterKey. Be sure to read about CLP and ACL when you plan to go towards production, because per default all tables are open to public read and write access when you start a server.
Most important, keep trying, keep learning, keep reading and never give up
I see in your screenshot you want to remove an item from the marketplace. If you use a marketplace contract for that, you will need to remove the item in the contract and not the database. Removing it from the contract should send an event which can be watched by a moralis Plugin, which then runs a cloud Job that deletes or updates the item in the database.
An example from my client side code doing that:
const removeFromMarket = () => {
const web3 = new Moralis.Web3()
const sender = user.value.get('ethAddress')
marketContract.value.methods.removeItemFromMarket(props.market_id, props.token_id, props.token_address).send({from: sender})
.on('receipt', receipt => {
console.log('receipt:', receipt)
// do stuff here when tx has been confirmed
})
.on('error', (err) => {
console.log('error removing nft:', err)
// do stuff with error
})
}
So this calls the market contract through the ABI method. The contract then emits an event that is caught by the moralis Plugin Sync and Watch Contract Events (all explained in tutorial videos).
This is my cloud function to delete the database record:
// remove items from sale ETH
Moralis.Cloud.beforeSave('EthRemovedItems', async (request) => {
const query = new Moralis.Query('EthItemsForSale')
query.equalTo('token_address', request.object.get('token_address'))
query.equalTo('token_id', request.object.get('token_id'))
const object = await query.first({useMasterKey:true})
const logger = Moralis.Cloud.getLogger()
if (object) {
object.destroy(null, {useMasterKey:true}).then(() => {
logger.info('The object was deleted from EthRemovedItems.');
}, (error) => {
logger.info(error);
});
}
})
Hope that helps