Skip to content

feat(BAR-57): Adds JSON import and a step-by-step import dialog - #69

Open
Bare7a wants to merge 2 commits into
masterfrom
feat/BAR-57_json-import
Open

Bare7a wants to merge 2 commits into
masterfrom
feat/BAR-57_json-import

Conversation

@Bare7a

@Bare7a Bare7a commented Dec 1, 2026

Copy link
Copy Markdown
Owner

📝 What changed?

BarSQL imported only CSV files and SQL scripts, through one long dialog. Now it imports JSON too, and every import goes through four steps: File, Preview, Columns and Import. A SQL script only needs File and Import.

  • JSON: an array of objects (what BarSQL's own JSON export writes) or JSON Lines (mongoexport, BigQuery, logs). Objects printed one after another over several lines, as jq prints them, load too. Each key becomes a column, in the order the keys first appear, and a row without a key gets NULL there.
  • Values: nested objects and arrays load as JSON in one column (jsonb on PostgreSQL, JSON on MySQL, text elsewhere). Numbers load exactly as written, so no digits are lost. Column types come from the values: whole numbers, decimals, booleans, dates and timestamps. A string stays text even when it looks like a number, so "007" keeps its zeros.
  • Big files: the file is read one row at a time, so memory stays flat and Stop works mid-file. Files up to 64 MB are read whole to find their columns and count their rows. Bigger ones take their columns from the first 1,000 rows, and keys that only show up later are named in the result.
  • Bad rows are skipped and reported with their line number. In JSON Lines, only that line is lost.
  • File step: drop a file onto the dialog or browse for one. The format comes from the file's extension, then its first few KB, and Read as changes it. The target table is picked here too.
  • Preview step: the first rows in a grid, as the import will read them, under the CSV options. For JSON there's a line saying what the file holds instead.
  • Columns step: where each of the file's columns goes, with sample values and a mark showing whether it fits an existing table's column. A new table also gets a type per column, JSON included.
  • Import step: a summary of what will happen, then progress, then the result: rows loaded, rows skipped and why, and how long it took. Open table opens the table. Import another file starts over, aimed at the table the import just created.
  • Footer: one forward button at a time. Next shows on the first steps and Import only on the last, so the summary is always seen before anything runs. Enter does what the blue button does. Cancel becomes Close once something has run.
  • Deleting existing rows: the option moved to the Import step, next to the button it runs before. When it's ticked, the button reads Delete rows and import in red and the summary warns.
  • Also fixed: ticking any checkbox in the importer re-read the CSV and reset the column mapping. Now only the header and trim options re-read the file.
  • Round trips: BarSQL's JSON export loads back unchanged on all six engines, with one exception: a JSON null stored in a json column comes back as SQL NULL, because the export writes both as null.

🧩 Type of change

  • 🐛 Bug fix
  • ✨ Feature
  • ♻️ Refactor
  • ⬆️ Dependencies
  • 📝 Docs or landing page
  • 🛠️ Build, CI or packaging

🧪 Tested

  • By hand on Windows
  • By hand on macOS
  • By hand on Linux
  • Tests workflow on macOS and Windows

📖 Docs

  • Updated the guide
  • Updated the README or landing page
  • No docs needed

📌 Notes

  • CsvImportRequest and import_csv became TableImportRequest and import_table, with a TableFormat that is either Csv(CsvOptions) or Json { keys }. preview_json_file sits next to preview_import_file.
  • The reader is barsql_io::json_import, and format detection is barsql_io::detect. serde_json gains its raw_value feature so values keep their exact text. No new crates; the release exe size wasn't measured.
  • A new IMPORT_JSON column type: jsonb, JSON, TEXT, NVARCHAR(MAX) or Nullable(String) depending on the engine.
  • The dialog is split into import_dialog.rs plus one file per step under import_dialog/.
  • Screenshot 11 and the demo video now open the importer's Columns step, but their images weren't regenerated.
  • Strings in English, German, Bulgarian and Spanish.
  • Tests:
    • the reader: both shapes, jq output, BOM, bad and cut-off rows, a runaway row, exact numbers, type inference and sampling
    • format detection
    • app imports into new and existing tables
    • JSON round trips and value shapes on every engine (E2E)
    • the dialog's steps, footer, Enter, the delete option, file drops, Read as, Open table and Import another file
    • scenarios that export results as JSON and import them back
    • The new dialog tests were mutation-checked: each fails when the behaviour it guards is broken.

This branch has not been deployed

No deployments
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.

1 participant