Getting started
We will connect the sample legislators database and ask how many vice presidents became president by election in the 20th century.
You need an API key from Anthropic, OpenAI, Google, Groq, xAI, Mistral, Cohere, or Hugging Face. You can instead use a ChatGPT subscription through OpenAI Codex.
If SQLsaber is not installed, follow Installation first.
1. Download the sample database
Section titled “1. Download the sample database”curl -L -o legislators.db https://github.com/SarthakJariwala/sqlsaber/raw/refs/heads/main/legislators.dbYou should now have legislators.db in the current directory.
To use your own database instead, see Database setup.
2. Start SQLsaber
Section titled “2. Start SQLsaber”saber -d ./legislators.dbOn first launch, SQLsaber asks you to choose an AI provider. API-key providers use an environment variable or your operating system credentials store. OpenAI Codex uses browser authentication with a ChatGPT subscription.
After setup you should see the interactive prompt.
3. Ask a question
Section titled “3. Ask a question”> How many VPs have become presidents via election in the 20th century?SQLsaber lists relevant tables, reads their schema, writes SQL, runs the query, and explains the result. You should see the generated SQL and a short answer.
To leave interactive mode, type /exit or press Ctrl+D.
Type /help for slash commands. Type @ and press Tab to complete a table name. The full list is in Commands.
Ask a question without the prompt
Section titled “Ask a question without the prompt”saber -d ./legislators.db "How many VPs became president by election in the 20th century?"Pipe a question:
echo "Top 10 customers by revenue" | saberWrite the answer to a file:
saber "Monthly active users" > report.mdIf setup fails
Section titled “If setup fails”If you see No database connections configured, run saber db add mydb.
If you see Authentication not configured, run saber auth setup.
If you see Database connection failed, run saber db test mydb.
Next steps
Section titled “Next steps”- Database setup to connect PostgreSQL, MySQL, SQLite, DuckDB, CSV, or Parquet
- Knowledge base to store KPI definitions and SQL patterns
- Conversation threads to resume a later session
- Models to change the AI provider or model