Hello
Is it possible to create a button that will completely erase a database, please?
Hello
Is it possible to create a button that will completely erase a database, please?
Hi Karl,
You could use the truncate function within an onClick event of a button.
I will try. Thanks
Yes it’s possible, here’s how.
import wixData from 'wix-data';
export function button1_click(event) {
//Add your code for this event here:
}
wixData.query("collectionName")
.find()
.then( (results) => {
let items = results.items
// Next code will be here
})
for (let i = 0; i < items.length; i++) {
let item = items[i];
wixData.remove("collectionName", item);
}
And that’s it, you may need to change some identifiers to let the code runs for you.
Here is the complete code:
import wixData from 'wix-data';
export function button1_click(event) {
//Add your code for this event here:
wixData.query("collectionName")
.find()
.then( (results) => {
let items = results.items;
for (let i = 0; i < items.length; i++) {
let item = items[i];
wixData.remove("collectionName", item);
}
})
}
I didn’t tested out though, test it and and tell me if it worked.
Everything you need to change is marked in blue
Happy Coding
Ahmad.