simonw / sqlite-utils

Python CLI utility and library for manipulating SQLite databases
https://sqlite-utils.datasette.io
Apache License 2.0
1.58k stars 106 forks source link

Add more STRICT table support #604

Closed tkhattra closed 7 months ago

tkhattra commented 8 months ago

Make table.transform() preserve STRICT mode.


:books: Documentation preview :books:: https://sqlite-utils--604.org.readthedocs.build/en/604/

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (9286c1b) 95.77% compared to head (1698a9d) 95.72%. Report is 1 commits behind head on main.

:exclamation: Current head 1698a9d differs from pull request most recent head 61c6e26. Consider uploading reports for the commit 61c6e26 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #604 +/- ## ========================================== - Coverage 95.77% 95.72% -0.06% ========================================== Files 8 8 Lines 2842 2852 +10 ========================================== + Hits 2722 2730 +8 - Misses 120 122 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

simonw commented 7 months ago

This looks really great on first glance - design is good, implementation is solid, tests and documentation look great.

Looks like a couple of mypy failures in the tests at the moment:

  mypy sqlite_utils tests

sqlite_utils/db.py:543: error: Incompatible types in assignment (expression has type "type[Table]", variable has type "type[View]")  [assignment]
tests/test_lookup.py:156: error: Name "test_lookup_new_table" already defined on line 5  [no-redef]
Found 2 errors in 2 files (checked 54 source files)
Error: Process completed with exit code 1.
tkhattra commented 7 months ago

Apologies - I pushed a fix that addresses the mypy failures.

simonw commented 7 months ago

Also tested this manually like so:

sqlite-utils create-table strict.db strictint id integer size integer --strict
sqlite-utils create-table strict.db notstrictint id integer size integer         
sqlite-utils install sqlite-utils-shell
sqlite-utils shell strict.db                                             
Attached to strict.db
Type 'exit' to exit.
sqlite-utils> insert into strictint (size) values (4);
1 row affected
sqlite-utils> insert into strictint (size) values ('four');
An error occurred: cannot store TEXT value in INTEGER column strictint.size
sqlite-utils> insert into notstrictint (size) values ('four');
1 row affected
sqlite-utils> commit;
Done