Commit graph

210 commits

Author SHA1 Message Date
Simon Willison
07b603e562
Preserve duplicate column names in query results
Queries returning duplicate column names - e.g. joins between tables
sharing column names - silently lost values because rows were built
with dict(zip(keys, row)), where the last duplicate wins.

Later occurrences are now renamed with a numeric suffix: id, id
becomes id, id_2 - skipping any suffix that would collide with a
real column in the same query.

The new utils.dedupe_keys() helper transforms the key list once per
query, so the per-row dict construction is unchanged and there is no
measurable performance impact.

Applied in Database.query() (including the PRAGMA and RETURNING
paths), Table.rows_where(), Table.search() and the CLI's JSON output.
CSV, TSV and table output keep the original duplicate headers.

Closes #624
2026-07-05 21:20:39 -07:00
Simon Willison
3cc27d69bc
New migrations system, ported from sqlite-migrate (#754)
Closes #752
2026-06-21 09:40:21 -07:00
Simon Willison
8f0c06e188
Test against Python 3.15-dev, bump ty and Black (#738)
* Add Python 3.15-dev to test matrix
* Run ty check only on 3.14
* Bump Black version
* Update tabulate and use that in 
* Bump to latest ty
2026-05-17 16:52:48 -07:00
Simon Willison
5a7f522980
sqlite-utils convert can now use callable references, closes #686
This now works:

    echo '{"date": "13th January 2025"}' | sqlite-utils insert dates.db dates -
    sqlite-utils convert dates.db dates date r.parsedate
    sqlite-utils rows dates.db dates

Previously the command would have been:

    sqlite-utils convert dates.db dates date 'r.parsedate(value)'
2025-11-29 14:43:02 -08:00
Simon Willison
35377a874b
Detect CSV/TSV column types by default (#683)
The `--detect-types` option is now automatically turned on for all commands that deal with CSV or CSV.

A new `--no-detect-types` option can be used to have all columns treated as text.

Closes #679
2025-11-23 22:23:15 -08:00
Simon Willison
0bbc68089c
--functions can take filenames, can be used multiple times (#681)
Closes #659

The --functions option now accepts:
- File paths ending in .py (e.g., --functions my_funcs.py)
- Multiple invocations (e.g., --functions foo.py --functions 'def bar(): ...')
- Inline Python code (existing behavior)

Implementation follows the same pattern as llm's --functions flag
(simonw/llm@a880c123).

Changes:
- Added multiple=True to --functions Click option in query, bulk, and memory commands
- Modified _register_functions() to detect and read .py files
- Updated _maybe_register_functions() to iterate over multiple function sources
- Removed unused bytes/bytearray handling
- Added comprehensive tests for file paths and multiple invocations
- Updated documentation with examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Shorter help for --functions

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-23 21:46:51 -08:00
Simon Willison
c872d27bb3
Use REAL not FLOAT as SQLite column type (#680)
* Use REAL not FLOAT as SQLite column type, refs #645
* Fix for REAL columns by CSV --detect-types

Refs https://github.com/simonw/sqlite-utils/issues/645#issuecomment-3568947189

* Removed note about strict and REAL
2025-11-23 21:37:59 -08:00
Simon Willison
fb93452ea8
Use double quotes not braces for tables and columns (#678)
Closes #677
2025-11-23 20:43:26 -08:00
Simon Willison
96fab69256 Removed convert skip_false and --skip-false, closes #542 2025-11-23 15:40:28 -08:00
Simon Willison
72f6c820f6 Small documentation updates to fix warnings 2025-05-07 17:54:29 -07:00
Simon Willison
88a83f0b7e
Link to JSON Lines instead
ndjson.org has an expired domain.
2025-05-04 22:50:10 -07:00
Simon Willison
0aefbb634d Removed trogon feature in favor of sqlite-util-tui
Refs #648, #545
2025-01-10 17:15:02 -08:00
Gavin Wahl
cbddfb28f9
typo in command name (#640) 2024-11-09 08:31:21 -08:00
Gert Goet
4c2628873c
Fix typo (#639) 2024-09-03 01:27:16 -07:00
Simon Willison
1feb0c4271 Docs for insert with multiple --pk, refs #621 2024-03-16 17:27:18 -07:00
Simon Willison
23be5be1dc create-table now supports multiple --pk, refs #620 2024-03-16 17:05:39 -07:00
Taj Khattra
1500c19bd0
Add more STRICT table support (#604)
* Add more STRICT table support per https://github.com/simonw/sqlite-utils/issues/344#issuecomment-982014776.
* Make `table.transform()` preserve STRICT mode.
* Fix mypy failures in PR #604
* Link to SQLITE strict page in a few places
2023-12-07 21:05:27 -08:00
Simon Willison
88bd372205 str, int, bytes aliases for column types, closes #606 2023-12-06 10:49:21 -08:00
Simon Willison
56093de078 sqlite-utils transform --add-foreign-key option, closes #585 2023-08-17 18:51:04 -07:00
Simon Willison
619cea8681 sqlite-utils convert --pdb option, closes #581 2023-07-26 14:06:05 -07:00
Simon Willison
37e374e05a Improved convert() function documentation 2023-07-25 07:47:44 -07:00
Simon Willison
18f190e283 sqlite-utils rename-table command, refs #565 2023-07-22 12:48:04 -07:00
Simon Willison
f7af23837d --empty-null option for CSV and TSV imports, closes #563 2023-07-02 22:42:26 -07:00
Simon Willison
8c739558f7 --stop-after option, closes #561 2023-06-27 11:50:04 -07:00
Simon Willison
8188acc1f1 Fix for missing csv Pygments support, refs #551 2023-05-21 14:03:10 -07:00
Simon Willison
d8fe1b0d89
Reformatted CLI examples in docs
Closes #551
2023-05-21 13:57:22 -07:00
Simon Willison
718b0cba9b
Experimental TUI powered by Trogon
* sqlite-utils tui command if Trogon is installed, closes #545
* Documentation for trogon TUI
* Screenshot of TUI
* Ignore trogon mypy error
* only run flake8 on Python 3.8 or higher, closes #550
2023-05-21 11:41:56 -07:00
Simon Willison
d2a7b15b2b
Analyze tables options: --common-limit, --no-most, --no-least
Closes #544
2023-05-21 09:19:30 -07:00
Simon Willison
e0ec4c3451 --no-skip-false option, plus docs - closes #527 2023-05-08 14:03:20 -07:00
Simon Willison
373b7886d2 --raw-lines option, closes #539 2023-05-07 11:26:14 -07:00
Simon Willison
eb67fc69a2 Run cog -r against latest tabulate, refs #501 2022-10-18 11:08:34 -07:00
Simon Willison
afbd2b2cba Link to convert command too, refs #483 2022-09-26 12:09:32 -07:00
Simon Willison
ee74bd5f81 Fix heading levels, refs #483 2022-09-26 12:03:54 -07:00
Simon Willison
85247038f7 install and uninstall commands, closes #483 2022-09-26 11:57:11 -07:00
Simon Willison
5b969273f1
Markup tweak 2022-09-01 18:44:56 -07:00
Simon Willison
087753cd42 sites.db is better name than dogs.db in this example 2022-08-27 21:01:55 -07:00
Simon Willison
104f37fa4d
db[table].create(..., transform=True) and create-table --transform
Closes #467
2022-08-27 16:17:55 -07:00
Simon Willison
a46a5e3a9e Improved code compilation pattern, closes #472 2022-08-26 22:20:09 -07:00
Simon Willison
31f062d4a7 sqlite-utils query --functions option, refs #471 2022-08-26 21:53:55 -07:00
Simon Willison
7a9a6363ff sqlite-utils rows --order option, closes #469 2022-08-26 21:10:20 -07:00
Simon Willison
f4fb78fa95
Cross-link CLI to Python docs (#460)
* Start cross-linking CLI to Python docs, refs #426
* More links to Python from CLI page, refs #426
2022-08-18 14:58:07 -07:00
Simon Willison
77ca051d4f
Link to installation instructions (#457) 2022-07-27 10:57:50 -07:00
Simon Willison
c710ade644 sqlite-utils duplicate command, closes #454, refs #449
Also made it so .duplicate() raises new NoTable exception rather than raising
an AssertionError if the source table does not exist.
2022-07-15 14:45:47 -07:00
Simon Willison
7ddf530088
A less potentially confusing parameter name 2022-06-13 08:22:59 -07:00
Yuri
9fedfc69d7
docs to dogs (#437) 2022-05-30 14:32:41 -07:00
Simon Willison
397183debd Switch docs theme to Furo, refs #435 2022-05-20 14:52:00 -07:00
Simon Willison
95522ad919 Clarified support for newline-delimited JSON, closes #417 2022-03-25 14:17:10 -07:00
Simon Willison
0b7b80bd40 Document the convert() with initialization pattern, closes #420 2022-03-25 13:07:29 -07:00
Simon Willison
878d5f5cea errors=r.SET_NULL/r.IGNORE options for parsedate/parsedatetime, closes #416 2022-03-20 21:01:35 -07:00
Simon Willison
8f528ed2b1 Fix ReST warning 2022-02-15 17:21:07 -08:00