Skip to main content

# Update

Performs a query to update data in a table.

Possible crash

To prevent accidental update of all rows, this will throw an error on execute() if no where() was defined.

To enable the update of all rows use force().

## Methods​

### data()​

→ (`object` = Object) → `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

→ `this`

### selectDatabase()​

→ (`database` = String) → `this`

Selects a different database for this query.

Parameters

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

Returns

→ `this`

### force()​

→ () → `this`

Enables update of all rows.

Returns

→ `this`

### where()​

→ (`string` = String, `values` = Array<any>) → `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

→ `this`

### execute()​

`async` → () → any

Executes the prepared query.

Returns

→ any - Query result