# Databases

Elide includes three database drivers for JavaScript and TypeScript. Import the one you need; there is nothing to
install and no `Elide.db` global.

| Module | Database | API | Placeholders | Page |
| --- | --- | --- | --- | --- |
| `elide:sqlite` | SQLite file or in-memory | Synchronous | `?`, `?1`, `$name` | [SQLite](/docs/api-sqlite) |
| `elide:postgres` | PostgreSQL server | Promises, pooled | `$1` or `?` | [PostgreSQL](/docs/api-postgres) |
| `elide:mysql` | MySQL server | Promises, pooled | `?` | [MySQL](/docs/api-mysql) |

```javascript
import { Database } from "elide:sqlite";

const db = new Database(":memory:");
db.exec("CREATE TABLE notes (body TEXT)");
db.prepare("INSERT INTO notes VALUES (?)").run("hello");
console.log(db.query("SELECT body FROM notes").all());
```

`node:sqlite` (`DatabaseSync`) and `bun:sqlite` (`Database`) run on the same engine (see
[SQLite](/docs/api-sqlite#nodesqlite-and-bunsqlite)). `elide:postgres` and `elide:mysql` ship TypeScript declarations in
`@elide-dev/types`; `elide:sqlite` has none (see [TypeScript and modules](/docs/typescript-and-modules)).

## Other languages

| Language | Use |
| --- | --- |
| Python | The standard [`sqlite3`](https://docs.python.org/3/library/sqlite3.html) module, after `elide setup python`, on the same SQLite engine and sandbox as `elide:sqlite` |
| Java, Kotlin | JDBC, with the driver as a Maven dependency, such as `org.xerial:sqlite-jdbc` or `org.postgresql:postgresql` |

Python's `sqlite3` supports user-defined functions, aggregates, window functions, collations, the authorizer,
progress and trace callbacks, `blobopen`, `serialize`/`deserialize`, limits, `interrupt` and `file:` URIs (`mode`
and `cache` parameters; `mode=memory&cache=shared` shares an in-memory database between connections). A callback can
run statements on its own connection. An authorizer set with `set_authorizer` runs after the sandbox's checks and can
only deny more.

Where it differs from CPython:

- `getconfig` and `setconfig` raise `sqlite3.NotSupportedError`.
- `setlimit` can't raise the length limits above Elide's own.
- `PRAGMA threads` changes nothing: sorting stays on the statement's thread, where collations run.
- `PRAGMA temp_store_directory` and `PRAGMA data_store_directory` can't be set.
- A statement fails after 60 seconds of SQLite work; time spent in callbacks doesn't count.

The JavaScript drivers aren't on a JVM program's classpath: declare the JDBC driver like any other library (see
[Maven dependencies](/docs/toolchain/jvm/maven)).

## Samples

- [Embedded SQLite](/docs/code-samples#embedded-sqlite)
- [SQLite transactions](/docs/code-samples#sqlite-transactions)
- [PostgreSQL queries](/docs/code-samples#postgresql-queries)
