Skip to content
Christoph Herrmann edited this page Nov 13, 2019 · 6 revisions

The return value is the count of the rows affected by the delete located in result.rowCount of the pg result object.

const rowCount = await sql.delete(
  'users',
  { name: 'name' }
)

// text: DELETE FROM "users" WHERE "name" = $1
// values: ['name']

table can also be given as an array with the schema. Otherwise if it's defined the defaultSchema option will be used.

Use SQL Tag deleting data

For more complex delete queries the SQL Tag can be used.

const name = 'name'

const rowCount = await sql.delete(
  sql`
    DELETE FROM "users" WHERE "name" = ${name}
  `
)

// text: DELETE FROM "users" WHERE "name" = $1
// values: ['name']

Where .delete() throws an error if no conditions are given, .deleteAll() comes in place allowing to be called without conditions.

Clone this wiki locally