# execute

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run-write/execute/
Language: en

`storage.run({ action: "execute", sql, params })`

The same action as reading, with a statement that changes data. It comes back with its effect rather than with rows.

Status: relational database · free · one statement

There is no separate write action on a relational database, and that is worth stating plainly: `execute` reads and writes, and only the statement says which.

```javascript
await storage.run({
  action: "execute",
  sql: "UPDATE users SET active = ? WHERE id = ?",
  params: [0, id],
});
```

> **A guard keyed on the action name cannot tell the two apart**
>
> If your own code decides what an agent or a job may do, read the statement, not the action. « execute » is as true of a SELECT as of a DROP TABLE.

```javascript
const WRITES = /^\s*(insert|update|delete|replace|create|alter|drop|truncate)\b/i;

function isWrite(sql) {
  return WRITES.test(sql);
}

if (isWrite(sql) && !allowedToWrite) throw new Error("read-only here");
```

## A statement with no WHERE is refused {#where}

Same reasoning as the empty filter on a document database: an `UPDATE` or a `DELETE` without a condition touches every row, and that has to be meant rather than typed.

## One statement {#one}

Several in one call are refused. A batch where only the first is examined defeats every guard that looks at the statement — including yours.

## Bind the values {#params}

```javascript
// Never
sql: `DELETE FROM sessions WHERE token = '${token}'`

// Always
sql: "DELETE FROM sessions WHERE token = ?", params: [token]
```

## Writes are refused when the space is full {#quota}

Statements that can grow the database are stopped past the quota; `DELETE` and `DROP` stay allowed, so there is always a way to make room.

## One call is one statement, so plan for a partial failure {#transactions}

A sequence of calls is not atomic: the third can fail with the first two applied. Make each step repeatable, or write a statement that is — and keep enough in your own records to say what landed.

- [execute · read](/sdk/ref/connected-storage/run/execute): La même action, du côté lecture.
- [tables](/sdk/ref/connected-storage/run/tables): Les colonnes, et la clé primaire.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(
    action="execute",
    sql="UPDATE users SET active = ? WHERE id = ?",
    params=[0, user_id],
)
```

```python
import re

WRITES = re.compile(r"^\s*(insert|update|delete|replace|create|alter|drop|truncate)\b", re.I)

def is_write(sql):
    return bool(WRITES.match(sql))

if is_write(sql) and not allowed_to_write:
    raise PermissionError("read-only here")
```

```python
# Never
storage.run(action="execute", sql=f"DELETE FROM sessions WHERE token = '{token}'")

# Always
storage.run(action="execute", sql="DELETE FROM sessions WHERE token = ?", params=[token])
```
