Skip to content

Add --table: open one table over one connection from the command line - #6

Closed
MrLiuX wants to merge 1 commit into
kackerx:mainfrom
MrLiuX:table-cli
Closed

MrLiuX wants to merge 1 commit into
kackerx:mainfrom
MrLiuX:table-cli

Conversation

@MrLiuX

@MrLiuX MrLiuX commented Oct 28, 2026

Copy link
Copy Markdown

1 ## What
2
3 sqlmux <conn|file|url> --table <[schema.]table> opens a throwaway single-table view directly — for the "I look at this table a lot" case, instead of opening the TUI, navigating to the table, zooming (Spc+z), picking columns (gc) and typing a filter (/) every time.
4
5 Flags (each sets only the initial state; everything stays live in the TUI afterwards):
6
7 - --where <cond> — apply a filter immediately
8 - --cols <a,b,c> — show only these columns, in this order
9 - --hide <a,b,c> — hide these columns
10 - --order "col desc, col2" — sort
11 - --limit <n> — rows per page
12 - --zoom — fullscreen the pane
13 - --readonly — force read-only
14 - --db <name> — PG / Redis / SQL Server database
15 - --transpose — transposed view
16 - --sidebar — show the connection tree (hidden by default)
17
18 Example:
19
20 sh 21 sqlmux myconn --table users --cols id,name,amount --zoom --where "name = 'x'" 22
23
24 ## How
25
26 Non-destructive by construction: it synthesizes an in-memory config.Layout and reuses the existing Restore/Adopt path that --layout already takes — no changes to the Update / View / keymap state machine. --table exits without writing last.toml (a throwaway view).
27
28 --cols (show only) is the one small addition to the core: a LayoutTab.Show field, applied once the first page's columns arrive (in gotPage), after which column control is handed back to the user.
29
30 ## Docs & tests
31
32 - Documented in specs/design/14-config.md.
33 - Unit tests for flag parsing / layout synthesis and for the --cols application.
34
35 ## Check status
36
37 go vet, go test ./... (all packages), gofmt, and go mod tidy (no change) pass. I could not run just test-integration (needs Docker) or just lint (needs golangci-lint) in this environment.

sqlmux <conn|file|url> --table <[schema.]table> starts a throwaway single-table view with --where/--cols/--hide/--order/--limit/--zoom/--readonly/--db/--transpose/--sidebar. It synthesizes a config.Layout and reuses Restore/Adopt (no core change); --cols (show only these columns) is a new LayoutTab.Show, applied once the first page's columns are in. Exit writes no last.toml.
@kaixuan188

kaixuan188 commented Oct 30, 2026 •

Copy link
Copy Markdown

Okay, I've taken a rough look, and I'll test this as soon as possible to see if it works! Thank you for your contribution.

@kaixuan188

Copy link
Copy Markdown

Thanks for the PR and the clear write-up! I built 158a4f1 and ran it. vet, the unit tests, gofmt and golangci-lint all pass. Two things stop us from merging it as it is:

1. The documented order doesn't parse. Go's flag stops at the first positional argument. run then sees more than one positional and prints the usage error:

$ sqlmux play --table t_order
sqlmux: usage: sqlmux [--version] [--layout name-or-path] [connection | file | url]

The example in the description and in §14 (sqlmux myconn --table users --cols …) fails the same way. Only sqlmux --table t_order play, with every flag before the name, gets through. The usage line doesn't mention --table either, and no test calls run with these arguments.

2. Saved layouts already cover the "I open this table a lot" case. Set the table up once: zoom, gc, /, the order and the limit. Then run layout.save (palette: "保存布局为…"), give it a name, and open it with sqlmux --layout users. A layout already records the window's zoom and sidebar, and the tab's WHERE, ORDER, LIMIT, hidden columns, column order, transpose and database. --table builds that same layout from 11 flags and adds a show field to the layout file. Our rule is to reuse what exists before adding surface, so we'd rather not take the flags plus the new file field for something --layout already does.

If saving a layout misses part of your use case, please open an issue describing it, for example a quick one-off view you don't want to save, or a column whitelist instead of a hide list. New features start in our design doc (specs/design/) before code, so an issue is the place to settle the shape first.

@kackerx kackerx mentioned this pull request Oct 30, 2026
@kaixuan188

Copy link
Copy Markdown

Thanks again for this, and sorry for the earlier "no". On a second look we agree the use case is real: a saved layout per table does not scale when you just want a quick look at one table.

We built a narrowed version ourselves instead of merging this branch, because our design starts in specs/design/ and this touched a few things we wanted to keep small:

  • Two flags, not eleven. --table [schema.]table and --where "<condition>". Columns, order, limit, zoom, transpose and the rest are one or two keys once the table is open. As flags they would become a second configuration surface, and a combination you use every day is what a named layout is for.
  • Flags before or after the connection. sqlmux play --table t_order and sqlmux --table t_order play both work. Go's flag stops at the first positional argument, which is why the example in this PR's description printed the usage error.
  • The first connection when none is given. sqlmux --table orders uses the first connection in connections.toml, so a shell alias always means the same thing.
  • Nothing written on exit. Like your version, a --table run does not touch last.toml, so your saved workspace is still there next time.
  • On a Redis connection --table takes a key name and opens its key tab.

So alias orders='sqlmux prod --table orders --where "created_at > now() - interval '1 day'"' is one command for the throwaway single-table view this PR was after. The design is in specs/design/14-config.md (search for --table). It ships in v0.8.0, and the CHANGELOG credits this PR.

Closing this one in favour of that. Thanks for the idea and the clear write-up.

@kackerx kackerx closed this Oct 30, 2026
@kackerx

kackerx commented Nov 8, 2026

Copy link
Copy Markdown
Owner

A follow-up for anyone who lands here: v0.10.0, out today, builds on the --table this PR started.

  • --table [schema.]table [--where "…"] (since v0.8.0) opens one table.
  • --sql "<statement>" (new) runs one statement in a fresh query and shows the result below it. Joins, aggregates, or a Redis command on a Redis connection all work.
  • --schema (new) picks the schema for either one: [database.]schema on PostgreSQL and SQL Server, the database on MySQL, the db number on Redis. It covers what --db was for here.
  • default_connection = "<name>" in config.toml (new) is the connection used when you don't name one. Without it, the first connection in connections.toml is used, as before.

The flags go before or after the connection. Neither kind of run overwrites the layout sqlmux restores next time.

sqlmux prod --table orders --where "user_id = 42"
sqlmux prod --sql "select status, count(*) from orders group by 1"
sqlmux prod --schema sales --table orders
# ~/.config/sqlmux/config.toml
default_connection = "prod"   # then just: sqlmux --table orders

The other flags from this PR (--cols, --hide, --order, --limit, --zoom, --transpose, …) are still out, for the reason given above. Once the table is open, each of them is a key or two. As flags they would become a second place to configure the same things, and a combination you open every day is what a named layout (sqlmux --layout <name>) is for.

To upgrade: brew upgrade kackerx/tap/sqlmux, npm install -g sqlmux@latest, or go install github.com/kackerx/sqlmux/cmd/sqlmux@latest. All the flags are in the docs. Thanks again for the idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants