Skip to content

Latest commit

 

History

History
136 lines (107 loc) · 5.66 KB

README.md

File metadata and controls

136 lines (107 loc) · 5.66 KB

SQL Table Generator

CI Release Go License: MIT

A spreadsheet-like editor in the browser that turns your data, as you type, into a text table formatted exactly like the mysql command-line client output — ready to paste into a ticket, a chat or documentation:

+----+-------------+-------------------+-------+
| id | name        | email             | note  |
+----+-------------+-------------------+-------+
|  1 | Alice Smith | alice@example.com | café  |
|  2 | Wang Lei    | wang@example.com  | NULL  |
| 10 | José García | jose@example.com  | naïve |
+----+-------------+-------------------+-------+
3 rows in set (0.00 sec)

Typing a row, pasting a block from a spreadsheet and switching output options

It is a single binary with the web interface built in. Everything runs locally: the page loads nothing from the internet and your data never leaves your machine.

Install

go install github.com/master2sid2/sql-table-generator@latest

Or download a binary for Linux, macOS or Windows from the releases page, or build from source (see Build).

Usage

sql-table-generator                       # http://127.0.0.1:8080
sql-table-generator -addr 127.0.0.1:9000  # another address
sql-table-generator -version

Then open the address in a browser.

Features

  • Spreadsheet-like editor: cells grow with their content and behave as in Excel. A click selects a cell, dragging or Shift+click / Shift+arrows select a range, a click on a row number or column letter selects the whole row or column, Ctrl+A selects everything. Double-click, F2 or just typing edits a cell (Escape cancels the edit). Enter / Tab move down / right; finishing an edit on the last row adds a new one. Delete clears the selection, Ctrl+Z / Ctrl+Y undo and redo.
  • Copy and paste with Ctrl+C / Ctrl+X / Ctrl+V:
    • selected cells are copied as TSV, so they paste into Excel or Google Sheets;
    • pasted rows go in from the selected cell, split into neighbouring cells by tabs (Excel, TSV), , / ; (CSV) or | (pieces of mysql or psql output, e.g. 05:00:02 | 05:00:02 | <1 s); the table grows as needed. To paste a value containing | as it is, paste it while editing the cell (double-click or F2);
    • a single value fills the whole selection;
    • a complete mysql table (+---+ boxes, \G vertical output) or a Markdown table pasted into the top-left header cell, or anywhere outside the grid, replaces the whole table, so a table generated earlier can be pasted back and edited.
  • Open or drop files: CSV, TSV, TXT. The delimiter (, ; Tab |) is detected automatically; the encoding may be UTF-8, UTF-16 with BOM (Excel "Unicode text") or Windows-1251 (Cyrillic Excel exports).
  • Options: alignment (like MySQL — numbers to the right — or all left / all right), empty cells as NULL, hiding empty rows and columns, an N rows in set footer.
  • Character widths as a terminal shows them: combining marks take no space, CJK characters and emoji take two columns.
  • Copy to the clipboard or download as table.txt.
  • The current draft is kept in the browser's localStorage.

Security

The server listens on 127.0.0.1 by default. It has no authentication, so only bind it to another address (-addr 0.0.0.0:8080) on a network you trust. Requests are limited to 20 MiB.

API

The web page uses a small JSON API, which can be used directly:

Method Path Body → response
POST /api/render {"table":{"headers":[],"rows":[[]]},"options":{...}} → {"text"}
POST /api/parse {"text":"...","format":"auto","header":true} → {"headers","rows","format","hasHeader"}
POST /api/upload multipart form: file, format, header → same as /api/parse

options: align (auto, left, right), emptyAsNull, footer, skipEmpty. format: auto, csv, tsv, mysql, pipe, vertical. hasHeader is false when the headers were generated (col1, col2, ...) and every input line is in rows.

Errors come back as {"error":"..."} with status 400, 413 or 422.

curl -s localhost:8080/api/render -d '{"table":{"headers":["id","name"],"rows":[["1","Alice"]]}}'

Build

Requires Go 1.26+.

make build      # bin/sql-table-generator, version taken from the VERSION file
make test       # unit tests
make lint       # go vet and gofmt check
make install    # copy to /usr/local/bin (PREFIX=... to change)
make dist       # release binaries for Linux, macOS and Windows in dist/
make demo       # re-record docs/demo/sql-table-generator.gif (Node.js, Playwright, ffmpeg)

Releases on GitHub are built by GoReleaser in GitHub Actions when a v* tag is pushed; the tag must match the VERSION file.

Layout

main.go              flags, HTTP server, graceful shutdown
handlers.go          JSON API
version.go           version information
internal/table/      parsing (CSV/TSV/mysql/\G/Markdown), rendering, widths, encodings
web/                 the page, embedded into the binary

License

MIT