Quick start
This tour uses a SQLite file, so you don't need a database server. Everything you learn works the same on PostgreSQL and MySQL.
1. Open a database
Start quarry with a file name. A file ending in
.dbis created if it doesn't exist:shquarry tour.dbYou see a short banner and a two-line prompt that shows where you are connected:
quarry 0.1.0 · SQLite 3.53.2 Type \? for help · \tui for the full-screen interface · Tab to complete · Ctrl-D to quit ╭─ SQLite ▸ tour.db ╰─❯
2. Create some data
Type these statements. A statement runs when it ends with ;, so you can spread it over several lines by pressing Enter:
create table books (
id integer primary key,
title text not null,
author text,
year integer
);
insert into books (title, author, year) values
('Dune', 'Frank Herbert', 1965),
('Neuromancer', 'William Gibson', 1984),
('The Left Hand of Darkness', 'Ursula K. Le Guin', 1969);3. Query it
select title, year from books order by year;╭───────────────────────────┬──────╮
│ title │ year │
├───────────────────────────┼──────┤
│ Dune │ 1965 │
├───────────────────────────┼──────┤
│ The Left Hand of Darkness │ 1969 │
├───────────────────────────┼──────┤
│ Neuromancer │ 1984 │
╰───────────────────────────┴──────╯
3 rows · 0.31 msTry completion. Type select * from bo and the menu offers books; press Tab to take it. Then continue with b where b. and the menu lists the columns of books, because quarry knows b is an alias for it.
4. Look around
These are special commands. They start with a backslash and run as soon as you press Enter, with no ; needed:
| Type | To |
|---|---|
\dt | list tables |
\d books | describe the books table |
\x | switch to vertical output (run it again to cycle) |
\T csv | print results as CSV (\T alone lists all formats) |
\? | see every command |
5. Try the full-screen interface
Type \tui. The same connection opens in the TUI:
- The explorer on the left lists your tables. Press Alt+0 to focus it, then Enter on
booksto browse its rows. - The editor on the right runs the statement under the cursor with Ctrl+Enter, or everything with F5.
- Ctrl+P opens the command palette, and F1 lists every shortcut.
Quit with Ctrl+Q. Leaving the TUI ends quarry; it doesn't go back to the REPL.
6. Use it in a script
The same binary runs SQL non-interactively and prints machine-friendly output:
quarry tour.db -e "select * from books" -F json7. Connect to a server
Give quarry a URL instead of a file:
quarry postgres://me@localhost/app
quarry mysql://root@127.0.0.1:3306/shopIf a password is needed, quarry asks for one.
Tip
Save a connection you use often with --save, then open it by name: quarry postgres://me@localhost/app --save app, and next time just quarry app.
Where next
- Connecting to a database covers every way to reach a server.
- Using the REPL and Using the TUI go deeper into each interface.
- Special commands lists everything you can type after
\.