nushell/crates/nu-command/tests/commands/database
Skyler Hawthorne cf923fc44c
into sqlite: Fix insertion of null values (#12328)
# Description

In #10232, the allowed input types were changed to be stricter, only
allowing records with types that can easily map onto sqlite equivalents.
Unfortunately, null was left out of the accepted input types, which
makes inserting rows with null values impossible.

This change fixes that by accepting null values as input.

One caveat of this is that when the command is creating a new table, it
uses the first row to infer an appropriate sqlite schema. If the first
row contains a null value, then it is impossible to tell which type this
column is supposed to have.

Throwing a hard error seems undesirable from a UX perspective, but
guessing can lead to a potentially useless database if we guess wrong.

So as a compromise, for null columns, we will assume the sqlite type is
TEXT and print a warning so the user knows. For the time being, if users
can't avoid a first row with null values, but also wants the right
schema, they are advised to create their table before running `into
sqlite`.

A future PR can add the ability to explicitly specify a schema.

Fixes #12225

# Tests + Formatting

* Tests added to cover expected behavior around insertion of null values
2024-03-29 06:41:16 -05:00
..
into_sqlite.rs into sqlite: Fix insertion of null values (#12328) 2024-03-29 06:41:16 -05:00
mod.rs Initial --params implementation (#12249) 2024-03-24 15:40:21 -05:00
query_db.rs Initial --params implementation (#12249) 2024-03-24 15:40:21 -05:00