---
sidebar_position: 6
---

# Update

Performs a query to update data in a table.

:::warning Possible crash
To prevent accidental update of all rows, this will throw an error on [execute()](#execute) if no [where()](#where) was defined.

To enable the update of all rows use [force()](#force).
:::

## Methods

### data()
&rarr; (`object` = __Object__) &rarr; `this`

Updates all matching rows with the given object.

**Parameters**

| Parameter | Type | Description |
| -- | -- | -- |
| `object` | __Object__ | The object with the data to update to. Keys represent column names. |

**Returns**

&rarr; `this`

***

### selectDatabase()
&rarr; (`database` = __String__) &rarr; `this`

Selects a different database for this query.

**Parameters**

| Parameter | Type | Description |
| -- | -- | -- |
| `database` | __String__ | Name of the database to select |

**Returns**

&rarr; `this`

***

### force()
&rarr; () &rarr; `this`

Enables update of all rows.

**Returns**

&rarr; `this`

***

### where()
&rarr; (`string` = __String__, `values` = __Array__\<__any__\>) &rarr; `this`

Adds a where-clause to the query

- Values should be set as ? in the string and given in left-to-right order via the 'values'-array to minimize the risk of sql-injection
- If you are using joins, specify the table and column together: table.column

**Parameters**

| Parameter | Type | Description |
| -- | -- | -- |
| `string` | __String__ | The where-clause as a string with ? representing each values. |
| `values` | __Array__\<__any__\> | Array containing values replacing the ? in the string (from left to right) |

**Returns**

&rarr; `this`

***

### execute()
`async` &rarr; () &rarr; __any__

Executes the prepared query.

**Returns**

&rarr; __any__ - Query result

***