> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> The SQL Databases runtime API — the methods available on a bound database via env, plus the prepared-statement and result types they return.

<Note>
  The types in this reference are exported from `@telnyx/edge-runtime` (TypeScript) and describe version **≥ 0.9.0** — the first release that exports `SqlDatabase` and wires the `env` binding. They describe the **`env` binding**, the in-function surface. Running SQL from outside a function — schema changes, ad-hoc queries, migrations — goes over a separate REST path, covered in the [CLI reference](/docs/edge-compute/sqldb/cli).
</Note>

The SQL Databases Runtime API is a single binding type plus the statement and result types its methods return. A database declared as `[storage.sqldb.<NAME>]` in `telnyx.toml` resolves on `env.<NAME>` as a `SqlDatabase`.

| Surface                                                                                              | Where it lives                                            | What it's for                                                                                       |
| ---------------------------------------------------------------------------------------------------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [`SqlDatabase`](/docs/edge-compute/sqldb/reference/sql-database)                                     | `env.<BINDING>`                                           | The binding handle — `prepare`, `batch`, `exec`.                                                    |
| [`SqlPreparedStatement`](/docs/edge-compute/sqldb/reference/sql-database#prepare-query)              | returned by `prepare()`                                   | `bind()`, then one terminal: `first`, `run`, `all`, `raw`.                                          |
| [`SqlQueryResult<T>`](/docs/edge-compute/sqldb/reference/sql-database#run-and-all)                   | resolved by `run()`, `all()`, and each entry of `batch()` | `{ results, success, meta }` — the rows plus their envelope.                                        |
| [`SqlQueryResultMeta`](/docs/edge-compute/sqldb/reference/sql-database#reading-what-a-write-touched) | `SqlQueryResult.meta`                                     | `duration`, `rows_read`, `rows_written`, `last_row_id`, `changes` — the statement's own accounting. |
| [`SqlExecResult`](/docs/edge-compute/sqldb/reference/sql-database#exec-query)                        | resolved by `exec()`                                      | `{ count, duration }` — how many statements ran. Returns no rows.                                   |

## Getting the Binding

```ts theme={null}
import { env } from "@telnyx/edge-runtime";

// env.DB is a SqlDatabase, from [storage.sqldb.DB] in telnyx.toml
const { results } = await env.DB
  .prepare("SELECT id, email FROM users WHERE id = ?")
  .bind(1)
  .all<{ id: number; email: string }>();
```

<Warning>
  Read the binding off the **imported** `env` — not the `env` argument of `fetch(request, env)`. The object handed to `fetch` carries actor bindings only: `env.DB` on it is `undefined`, and the call fails at runtime with `Cannot read properties of undefined (reading 'prepare')` even though it type-checks cleanly. The generated types deliberately declare the binding in both places, so the compiler will not catch this.
</Warning>

Declaring the binding is covered in the [Quick Start](/docs/edge-compute/sqldb/quick-start). The binding resolves at runtime from `telnyx.toml`; run `telnyx-edge types` after editing the manifest to regenerate `telnyx-env.d.ts`, which types `env.<NAME>` as a `SqlDatabase`. That command checks the `@telnyx/edge-runtime` version declared in `package.json` and fails with `@telnyx/edge-runtime <version> does not export SqlDatabase (requires >= 0.9.0)` when the floor is not met.

## Related Resources

* [`SqlDatabase`](/docs/edge-compute/sqldb/reference/sql-database) — the method-by-method reference
* [Quick Start](/docs/edge-compute/sqldb/quick-start) — create a database, bind it, query it
* [How SQL Databases Work](/docs/edge-compute/sqldb/concepts/how-sqldb-works) — one primary per database, and what that means for consistency
* [Bindings](/docs/edge-compute/runtime/bindings) — how bindings resolve on `env`
* [CLI](/docs/edge-compute/sqldb/cli) — `telnyx-edge storage sqldb` for provisioning, ad-hoc SQL, and migrations
* [Limits](/docs/edge-compute/sqldb/limits) — database and value size, bound parameters, and query performance
* [Stateful Actor SQL](/docs/edge-compute/stateful-actors/guides/storage/sql) — a different product: the private embedded SQLite at `ctx.storage.sql`, visible to one actor instance only and called synchronously
