Skip to main content

Delete

Use .delete to delete data from your table. This will return the number of rows deleted.

const { db } = useEasybase();

await db('MOVIES').delete().one();
> 1

// { "title": "Avatar", "rating": 83 },

Executing a delete query with .one only deletes the first row found, whereas .all will delete all rows found.

await db('MOVIES').delete().where(e.gt('rating', 55)).all();
> 3

// [
// { "title": "Avatar", "rating": 83 },
// { "title": "Titanic", "rating": 75 },
// { "title": "Jurassic World", "rating": 59 }
// ]

Where

tip

Note that .where works in delete queries just as it does in select queries.

Filter the rows to delete with .where.

await db('MOVIES').delete().where(
e.or(
e.eq("title", "The Lion King"), // Equals
e.gt("rating", 80) // Greater than
)
).all()
> 2

// [
// { "title": "Avatar", "rating": 83 },
// { "title": "The Lion King", "rating": 55 }
// ]

Delete specific record with .where.

let singleRecord = table.return().one() // Select returns a unique identifier called _key

await db('MOVIES').delete().where({ _key: singleRecord._key }).one()
> 1