mirror of
https://github.com/allankoechke/turso.git
synced 2026-11-30 11:12:58 +00:00
Wrap the open-database map in an OpenHandles type whose only insertion path enforces the cap, so nothing can push it past --sync-max-databases. Restrict database names to lowercase so that one name is one file and one handle on case-insensitive filesystems too. Drop the Windows reserved device name list: opening such a name simply fails. Open directory databases with the caller's options as given instead of the CLI shell options, which turn on extension loading. Keep the server error message free of CLI flag names, tighten the help text for --sync-max-databases, use TempDir in the unit tests, and trim the docs and README to the essentials. Note that VACUUM INTO can write outside the served directory alongside the existing ATTACH caveat. Tests: cargo test -p turso_cli sync_server; cargo clippy --workspace --all-features --all-targets; cargo check -p turso --features sync --tests Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y1uLrzBq9CGq6yUDpiqHnJ
155 lines
3.7 KiB
Plaintext
155 lines
3.7 KiB
Plaintext
---
|
|
title: Getting Started
|
|
description: Install and use the Turso interactive SQL shell
|
|
sidebarTitle: Getting Started
|
|
---
|
|
|
|
# Getting Started
|
|
|
|
The Turso CLI (`tursodb`) is an interactive SQL shell for working with Turso databases. It supports in-memory and file-based databases, multiple output modes, CSV import, database cloning, and built-in documentation.
|
|
|
|
## Quick Start
|
|
|
|
### In-Memory Database
|
|
|
|
Launch the shell with a transient in-memory database:
|
|
|
|
```bash
|
|
tursodb
|
|
```
|
|
|
|
### Open a Database File
|
|
|
|
```bash
|
|
tursodb mydata.db
|
|
```
|
|
|
|
### Run a Query Directly
|
|
|
|
Pass SQL as a command-line argument to run it and exit:
|
|
|
|
```bash
|
|
tursodb mydata.db "SELECT * FROM users;"
|
|
```
|
|
|
|
### Pipe SQL from stdin
|
|
|
|
```bash
|
|
echo "SELECT sqlite_version();" | tursodb -q
|
|
```
|
|
|
|
## Interactive Shell
|
|
|
|
When launched without a SQL argument, the shell provides an interactive REPL with command history and syntax highlighting.
|
|
|
|
### Multi-line Input
|
|
|
|
Unfinished statements (missing semicolons, unbalanced parentheses) automatically continue on the next line. The prompt indicates nesting depth:
|
|
|
|
```
|
|
tursodb> SELECT *
|
|
...> FROM employees
|
|
...> WHERE department = 'Engineering';
|
|
```
|
|
|
|
### Command History
|
|
|
|
Command history is saved automatically to `~/.limbo_history` and accessible with up/down arrow keys.
|
|
|
|
### Exiting
|
|
|
|
Use `.quit` or `.exit` to leave the shell. Pressing Ctrl+C twice also exits.
|
|
|
|
## Output Modes
|
|
|
|
Turso supports three output modes, selectable with the `-m` flag or the `.mode` dot command.
|
|
|
|
### Pretty (Default)
|
|
|
|
Human-readable table with borders:
|
|
|
|
```bash
|
|
tursodb -q -m pretty
|
|
```
|
|
|
|
```
|
|
┌────┬─────────┬─────────────┬─────────┐
|
|
│ id │ name │ department │ salary │
|
|
├────┼─────────┼─────────────┼─────────┤
|
|
│ 1 │ Alice │ Engineering │ 95000.0 │
|
|
├────┼─────────┼─────────────┼─────────┤
|
|
│ 2 │ Bob │ Marketing │ 72000.0 │
|
|
└────┴─────────┴─────────────┴─────────┘
|
|
```
|
|
|
|
### List
|
|
|
|
Pipe-delimited values suitable for scripting:
|
|
|
|
```bash
|
|
tursodb -q -m list
|
|
```
|
|
|
|
```
|
|
1|Alice|Engineering|95000.0
|
|
2|Bob|Marketing|72000.0
|
|
```
|
|
|
|
### Line
|
|
|
|
One column per line, with column names:
|
|
|
|
```bash
|
|
tursodb -q -m line
|
|
```
|
|
|
|
```
|
|
id = 1
|
|
name = Alice
|
|
department = Engineering
|
|
salary = 95000.0
|
|
```
|
|
|
|
## Non-Interactive Mode
|
|
|
|
When input is piped (not a terminal), the shell runs in non-interactive mode:
|
|
|
|
- Output defaults to `list` mode (override with `-m`)
|
|
- No startup banner, history, or syntax highlighting
|
|
- Exits with code 1 on query errors
|
|
|
|
```bash
|
|
echo "SELECT 1 + 2;" | tursodb -q
|
|
```
|
|
|
|
## Server Modes
|
|
|
|
The CLI can also run as a server instead of an interactive shell.
|
|
|
|
### MCP Server
|
|
|
|
Start a [Model Context Protocol](https://modelcontextprotocol.io/) server, allowing AI assistants to interact with the database:
|
|
|
|
```bash
|
|
tursodb --mcp mydata.db
|
|
```
|
|
|
|
### Sync Server
|
|
|
|
Start a sync server for database replication:
|
|
|
|
```bash
|
|
tursodb --sync-server 0.0.0.0:8080 mydata.db
|
|
```
|
|
|
|
### Sync Server for a Directory of Databases
|
|
|
|
Serve every database under a directory instead of a single file, with each database addressed by name at `/db/{name}`:
|
|
|
|
```bash
|
|
tursodb --sync-server 127.0.0.1:8080 --sync-dir ./dbs
|
|
```
|
|
|
|
A client syncing against `http://localhost:8080/db/db1` reads and writes `./dbs/db1/data`, which is created on first request unless the server was started with `--readonly`. Database names must match `^[a-z0-9_-]+$` and be at most 128 characters. See [Command-Line Options](./command-line-options.mdx) for the full details and limitations.
|
|
|