@deaquinodev/querky 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +230 -0
- package/dist/index.js +2310 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arthur D'Aquino
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# Querky
|
|
2
|
+
|
|
3
|
+
A quirky terminal SQL client with vim keybindings, schema-aware autocomplete, query aliases, and AI-powered query explanation.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Beautiful tables** — clean, aligned output with automatic expanded mode for wide results
|
|
10
|
+
- **Vim mode** — full normal/insert mode with motions, operators, yank/paste
|
|
11
|
+
- **Query history** — persisted across sessions, navigate with ↑↓
|
|
12
|
+
- **AI explanation** — explain any SQL query in plain English via Groq or Ollama
|
|
13
|
+
- **Slash commands** — with Tab autocomplete and ↑↓ suggestion navigation
|
|
14
|
+
- **Responsive layout** — auto-switches to vertical key=value mode when the table is wider than the terminal
|
|
15
|
+
- **Connection wizard** — interactive form on startup if no connection string is provided
|
|
16
|
+
- **Multiple drivers** — PostgreSQL, MySQL, and SQLite
|
|
17
|
+
- **Credential storage** — passwords saved to OS keychain automatically
|
|
18
|
+
- **Schema-aware autocomplete** — Tab-completes table names, column names, and SQL keywords based on context
|
|
19
|
+
- **Query aliases** — save queries under short names, scoped per database, with positional and named parameters
|
|
20
|
+
- **Pagination** — navigate large result sets with `/next` and `/prev`
|
|
21
|
+
- **Export** — save results to CSV or JSON
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Node.js 18+
|
|
28
|
+
- pnpm
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/arthurdaquinosilva/querky.git
|
|
36
|
+
cd querky
|
|
37
|
+
pnpm install
|
|
38
|
+
pnpm build
|
|
39
|
+
pnpm install -g .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
After that, `querky` is available globally.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Connecting
|
|
47
|
+
|
|
48
|
+
### With a connection string
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
# PostgreSQL
|
|
52
|
+
querky --connection postgresql://user:pass@localhost/mydb
|
|
53
|
+
querky -c postgresql://user:pass@localhost/mydb
|
|
54
|
+
|
|
55
|
+
# MySQL
|
|
56
|
+
querky -c mysql://user:pass@localhost/mydb
|
|
57
|
+
|
|
58
|
+
# SQLite
|
|
59
|
+
querky -c sqlite:///path/to/database.db
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### With the interactive wizard
|
|
63
|
+
|
|
64
|
+
Run `querky` with no arguments and fill in the form:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
querky
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Use **Tab** or **↑↓** to move between fields, **←→** to cycle the driver, **Enter** to connect. Passwords are saved to the OS keychain after a successful connection and pre-filled on the next run.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## AI Setup
|
|
75
|
+
|
|
76
|
+
Querky can explain your queries using any OpenAI-compatible API.
|
|
77
|
+
|
|
78
|
+
### Groq (recommended — fast and free)
|
|
79
|
+
|
|
80
|
+
1. Get a free API key at [console.groq.com](https://console.groq.com)
|
|
81
|
+
2. Set the key in your shell:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Add to ~/.zshrc or ~/.bashrc
|
|
85
|
+
export QUERKY_API_KEY=gsk_...
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
3. Connect with Groq:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
querky -c postgresql://... \
|
|
92
|
+
--ai-url https://api.groq.com/openai/v1 \
|
|
93
|
+
--ai-model llama-3.1-8b-instant
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Ollama (local, offline)
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
ollama pull llama3.2
|
|
100
|
+
ollama serve
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
querky -c postgresql://... --ai-model llama3.2
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Ollama is the default endpoint (`http://localhost:11434/v1`).
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Slash Commands
|
|
112
|
+
|
|
113
|
+
| Command | Description |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `/explain <SQL>` | Explain a SQL query in plain English |
|
|
116
|
+
| `/explain-previous` | Explain the last query you ran |
|
|
117
|
+
| `/databases` | List available databases |
|
|
118
|
+
| `/tables` | List tables in the current database |
|
|
119
|
+
| `/export csv` | Export last result to a CSV file |
|
|
120
|
+
| `/export json` | Export last result to a JSON file |
|
|
121
|
+
| `/next` | Next page of results |
|
|
122
|
+
| `/prev` | Previous page of results |
|
|
123
|
+
| `/toggle-vim-mode` | Toggle vim keybindings on/off |
|
|
124
|
+
| `/save <name>` | Save the last query as an alias |
|
|
125
|
+
| `/alias <name> <SQL>` | Define an alias inline |
|
|
126
|
+
| `/aliases` | List all aliases for the current database |
|
|
127
|
+
| `/unalias <name>` | Remove a saved alias |
|
|
128
|
+
|
|
129
|
+
Type `/` and use **Tab** or **↑↓** to navigate and complete commands.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Schema-aware Autocomplete
|
|
134
|
+
|
|
135
|
+
Querky fetches your schema on connect and completes as you type. Press **Tab** to cycle through suggestions, **Enter** to accept.
|
|
136
|
+
|
|
137
|
+
| Context | Completes |
|
|
138
|
+
|---|---|
|
|
139
|
+
| After `FROM`, `JOIN`, `INTO` | Table names |
|
|
140
|
+
| After `SELECT`, `WHERE`, `ON` | Column names + tables |
|
|
141
|
+
| After `table.` | Columns for that specific table |
|
|
142
|
+
| Anywhere else | SQL keywords + tables + columns |
|
|
143
|
+
|
|
144
|
+
Works with PostgreSQL, MySQL, and SQLite. Suggestions appear after 1 character.
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## Query Aliases
|
|
149
|
+
|
|
150
|
+
Save any query under a short name, scoped to the current database.
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Save the last executed query
|
|
154
|
+
/save get_all_users
|
|
155
|
+
|
|
156
|
+
# Or define one inline
|
|
157
|
+
/alias get_user SELECT * FROM users WHERE id = $1
|
|
158
|
+
/alias add_user INSERT INTO users(name, email) VALUES (:name, :email)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Then invoke them like any other command:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
/get_all_users
|
|
165
|
+
/get_user 42
|
|
166
|
+
/add_user name="Alice" email="alice@example.com"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Positional params** use `$1, $2, …` — pass values in order.
|
|
170
|
+
**Named params** use `:param` — pass `key=value` pairs (quote values with spaces).
|
|
171
|
+
|
|
172
|
+
Aliases are stored in `~/.config/querky/aliases.json` and are Tab-completable.
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## psql Aliases
|
|
177
|
+
|
|
178
|
+
Users coming from `psql` can use familiar meta-commands:
|
|
179
|
+
|
|
180
|
+
| Command | Equivalent |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `\l` | List databases |
|
|
183
|
+
| `\d` or `\dt` | List tables |
|
|
184
|
+
| `\du` | List users |
|
|
185
|
+
| `\c` | Show current database |
|
|
186
|
+
| `\c <dbname>` | Switch to a different database |
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## Vim Mode
|
|
191
|
+
|
|
192
|
+
Querky starts in INSERT mode. Press `Escape` to enter NORMAL mode.
|
|
193
|
+
|
|
194
|
+
| Keys | Action |
|
|
195
|
+
|---|---|
|
|
196
|
+
| `i` / `a` / `A` | Enter INSERT mode |
|
|
197
|
+
| `h` / `l` | Move left/right |
|
|
198
|
+
| `w` / `b` / `e` | Word forward/backward/end |
|
|
199
|
+
| `0` / `$` | Start/end of line |
|
|
200
|
+
| `dd` / `cc` / `S` | Clear line |
|
|
201
|
+
| `dw` / `cw` | Delete/change word |
|
|
202
|
+
| `x` / `s` | Delete/substitute character |
|
|
203
|
+
| `D` / `C` | Delete/change to end of line |
|
|
204
|
+
| `yy` / `p` | Yank line / paste |
|
|
205
|
+
|
|
206
|
+
In INSERT mode, **↑↓** navigates query history.
|
|
207
|
+
|
|
208
|
+
Disable vim mode with `/toggle-vim-mode` or pass `--no-vim` for plain input.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## All Flags
|
|
213
|
+
|
|
214
|
+
| Flag | Default | Description |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `--connection`, `-c` | — | Connection string (optional — wizard shown if omitted) |
|
|
217
|
+
| `--ai-url` | `http://localhost:11434/v1` | OpenAI-compatible API base URL |
|
|
218
|
+
| `--ai-model` | `llama3.2` | Model name |
|
|
219
|
+
| `--api-key` | `$QUERKY_API_KEY` | API key for remote endpoints |
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Development
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
pnpm dev --connection postgresql://user:pass@localhost/mydb
|
|
227
|
+
pnpm test
|
|
228
|
+
pnpm lint
|
|
229
|
+
pnpm build
|
|
230
|
+
```
|