# Database operations

## Overview

Use a flow that executes any database operation in your connected database.

This requires a GraphQL connection setting, as SQL is not directly supported, and current LLMs do not work correctly with this sort of prompts.

### Database operations

**CRUD Operations**: Create, Read, Update, Delete data.

* **Transactions**: Ensure data integrity with ACID properties.
* **Indexes**: Improve query performance.
* **Joins**: Combine data from multiple tables.
* **Backup and Recovery**: Safeguard and restore data.
* **Data Security**: Protect data through

## Prompt Engineering

Specific props will be matched, while new props or collections will be created.

```
create a new post for the user
```

Here there can be 3 possible outcomes:

1. The collection post exists and the data is matched with the parameters in the flow
2. The collection post doesnt exists and is created with the data parameters as props
3. The collection exists but the data parameters doesnt and they are added as props to the existing collection

## Usage

Leverage Base to easily design your API and prototype apps, UX, or screens. To experiment with different outcomes, set "`cached`" to `false`

Using `/base` with "`cached`" is equivalent to direclty calling the function after is creation, all none neccesary params will be ignored.

<mark style="color:green;">`POST`</mark> `/base`

Creates a new flow with one or more actions, installs dependencies, builds tests and executes the resulting code.

Actions can be agents, backend functions, or cloud functions.

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

<table><thead><tr><th width="219">Name</th><th width="101">Type</th><th width="103" data-type="checkbox">Required</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>true</td><td>Name of the flow to summarize the actions</td></tr><tr><td><code>prompt</code></td><td>string</td><td>true</td><td>The instructions for AgentBase to transform in to code</td></tr><tr><td><code>data</code></td><td>object</td><td>false</td><td>The data example or parameters for your function to work</td></tr><tr><td><code>schedule</code></td><td>string</td><td>false</td><td>The cron calendar for the function to run automatically</td></tr><tr><td><code>return</code></td><td>object</td><td>false</td><td>The data example of your expected return</td></tr><tr><td><code>model</code></td><td>string</td><td>false</td><td>The model to run for your prompt</td></tr><tr><td><code>errors</code></td><td>array</td><td>false</td><td>List or possible errors your function needs to catch</td></tr><tr><td><code>cached</code></td><td>boolean</td><td>false</td><td>It will use the last version of the function whenever is available to save time and tokens</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "run_id": 1,
  "return": {
    "post_id":"id"
  },
  "error": null
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

#### Body Example

{% code overflow="wrap" lineNumbers="true" %}

```json

{
    "function": "crate_post",
    "prompt": "create a new post for the user",
    "data" : {
        "email": "email",
        "message": "message example"
    },
    "return" : {
        "post_id":"id"
    }
}
```

{% endcode %}
