Documentation Tutorials

Deleting (MYSQL)

The following examples are using this migration

  id: 'id',
  name: 'string',
  created: 'datetime'

All examples below are using these const definitions.

import {
} from 'js-web'

const { mysql } = storage

const users = mysql.table('users')

How to delete

Use the delete(where) function on the return object from the table function. In the example below, the users is const users = db.table('users')

users.delete({name: 'Simon'})
users.delete({id: 1})

Soft deleting

js-web has a soft deleting build in. All you need is a bit field on all your tables and set the .env file correct. In the example below, all tables need to have a field named deleted with the type of bool.
The delete function will only set the boolean to true and not delete the row. All reading functions will automatically filter the deleted rows.