how to empty a table (postgres)

What's the best way to programatically empty a database table? I'm using
const emptied = await db.execute(sql`DELETE FROM featured_salons;`)
const emptied = await db.execute(sql`DELETE FROM featured_salons;`)
in the meantime Thank you
3 Replies
Dan
Dan•2y ago
looks pretty good to me one thing to improve is using the table as a parameter to reference its name:
sql`delete from ${featuredSalons};`
sql`delete from ${featuredSalons};`
ah, actually, you could just use the query builder syntax 😅
await db.delete(featuredSalons);
await db.delete(featuredSalons);
I got confused for a second
rubberduckies
rubberduckiesOP•2y ago
oh, that’s even better 🙂 gonna try it when i get home just to confirm: ‘db.delete’ removes the rows from the table, it doesn’t drop it right?
Dan
Dan•2y ago
yup that's why it's called delete and not drop 🙂
Want results from more Discord servers?
Add your server