> For the complete documentation index, see [llms.txt](https://paultje52.gitbook.io/better-mysql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://paultje52.gitbook.io/better-mysql/v1.0.1/basics/setting-data.md).

# Setting data

Now let's set some data in to the database!

## Adding

First, let's start off with something simple! You have a database called `customers` with the columns `name, mail, ordersArray`. Now you want to add a customer. You can do that with the `table.add` function. Here are two examples.

{% tabs %}
{% tab title="Await example" %}

```javascript
// First, let's make the array of the order.
let orders = [1, 5, 9];

// Now add it to the table.
await table.add(["Paul", "paul@example.mail", orders]);
// Done!
```

{% endtab %}

{% tab title=".then example" %}

```javascript
// First, let's make the array of the order
let orders = [1, 5, 9];

// Now add it to the database
table.add(["Paul", "paul@example.mail", orders]).then(() => {
    // Done!
});
```

{% endtab %}
{% endtabs %}

## Updating

Now, the customer ordered product number three. Then you want to add that to the array. You can do that with the `table.update` function.

{% tabs %}
{% tab title="Await example" %}

```javascript
// First, let's get the customer information
let filter = new client.filter(1)
filter.add("name", "Paul");
let customer = await table.where(filter);

// Now, get the array, add order number two and sort it (because we can)
let orderArray = customer.orderArray;
orderArray.push(2);
orderArray.sort();

// Now, let's update the database
await table.update(filter, {column: "ordersArray", value: orderArray});
// Array updated!
```

{% endtab %}

{% tab title=".then example" %}

```javascript
// First, let's get the customer information
let filter = new client.filter(1)
filer.add("name", "Paul");
table.where(filter).then(customer => {
    // Now, get the array, add order number two and sort it (because we can)
    let orderArray = customer.orderArray;
    orderArray.push(2);
    orderArray.sort();
    
    // Now, let's update the database
    table.update(filter, {column: "ordersArray", value: orderArray}).then(() => {
        // Array updated!
    });
});
```

{% endtab %}
{% endtabs %}

## Deleting

Oke, finaly: deleting data! You can delete data with the `table.delete` function and a filter. Here a example.

{% tabs %}
{% tab title="Await example" %}

```javascript
let filter = new client.filter(1)
filter.add("name", "Paul");
await table.delete(filter);
// Row deleted!
```

{% endtab %}

{% tab title=".then example" %}

```javascript
let filter = new client.filter(1)
filter.add("name", "Paul");
table.delete(filter).then(() => {
    // Row deleted!
});
```

{% endtab %}
{% endtabs %}
