> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL

> Store workspace files in the tables of a SQL database.

![](https://mintcdn.com/struktoai/F9Lv_nTaj6By6crk/images/python-logo.svg?fit=max\&auto=format\&n=F9Lv_nTaj6By6crk\&q=85\&s=cf5b268d330f7db46ea5cf6083f309a1)

Node.js

![](https://mintcdn.com/struktoai/CsxMCKUyfoQQJYHB/images/cloudflare-logo.svg?fit=max\&auto=format\&n=CsxMCKUyfoQQJYHB\&q=85\&s=23668457afa14abb3b0db0f5b9c0541a)

SQL keeps workspace files in a database's tables, laid out as
[AgentFS](https://github.com/tursodatabase/agentfs)'s. The files last as long
as the database does.

## Connect

> [tab] YAML
>
> ```yaml workspace.yaml theme={null}
> mounts:
>   /sql:
>     vfs: sql
>     mode: write
>     config:
>       path: ./workspace.db
> ```
>
> ```bash theme={null}
> mirage workspace create workspace.yaml --id db
> mirage shell -w db -c 'ls /sql'
> ```

> [tab] Python
>
> ```python theme={null}
> from mirage import MountMode, Workspace
> from mirage.vfs.sql import SqlVFS
>
> ws = Workspace({"/sql": SqlVFS("./workspace.db")}, mode=MountMode.WRITE)
> result = await ws.shell("ls /sql")
> print(await result.stdout_str())
> await ws.close()
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { MountMode, SqlVFS, Workspace } from '@struktoai/mirage-node'
>
> const ws = new Workspace(
>   { '/sql': new SqlVFS({ path: './workspace.db' }) },
>   { mode: MountMode.WRITE },
> )
> const result = await ws.shell('ls /sql')
> console.log(result.stdoutText)
> await ws.close()
> ```

## Layout

```text theme={null}
/sql/
  notes/
    hello.txt
  users.csv
```

* `path` is a SQLite file; leave it out to keep the database in memory. The
  file holds the tables `fs_inode`, `fs_dentry`, `fs_data` and `fs_config`.
* `root: /workspace` under `config` serves only that folder, made when
  missing. Several mounts can share one database this way, and a mount of the
  whole database lists the folder too.
* A Postgres server, a Durable Object's storage or a D1 database mounts from
  code, through its driver; see the SDK guides.

## Sample runs

```bash theme={null}
$ tree /sql
/sql
|-- notes
|   `-- hello.txt
`-- users.csv

2 directories, 2 files
```

```bash theme={null}
$ cut -d, -f2 /sql/users.csv
name
ada
linus
```

```bash theme={null}
$ cat /sql/notes/hello.txt
hello world
```

Every command that writes works on a `write` mount. Add `capacity: 100MB`
under `config` to cap the bytes the database's files hold, whichever folder
they are in; see [capacity](https://docs.mirage.strukto.ai/home/setup/vfs.md#mount-capacity).

## SDK guides

> [card] [Python](https://docs.mirage.strukto.ai/python/vfs/sql.md)
>
> Every config field, the VFS.md and write support.

> [card] [TypeScript](https://docs.mirage.strukto.ai/typescript/vfs/sql.md)
>
> Every config field, the VFS.md and write support.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.