nushell/crates/nu-command/src
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
..
bytes Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
charting Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
conversions Rename Value::CustomValue to Value::Custom (#12309) 2024-03-27 22:10:56 +01:00
database into sqlite: Fix insertion of null values (#12328) 2024-03-29 06:41:16 -05:00
date Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
debug Rename Value::CustomValue to Value::Custom (#12309) 2024-03-27 22:10:56 +01:00
env Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
experimental Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
filesystem Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
filters Make Record.cols private (#12317) 2024-03-28 20:18:43 +00:00
formats Avoid uses of Record internals again (#12312) 2024-03-28 11:36:12 +01:00
generators Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
hash Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
help ♻️ rework some help strings (#12306) 2024-03-27 08:41:02 -05:00
math Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
misc Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
network Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
path Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
platform Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
random Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
removed Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
shells Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
stor Rename Value::CustomValue to Value::Custom (#12309) 2024-03-27 22:10:56 +01:00
strings Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
system Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
viewers Rename Value::CustomValue to Value::Custom (#12309) 2024-03-27 22:10:56 +01:00
default_context.rs Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
example_test.rs Initial --params implementation (#12249) 2024-03-24 15:40:21 -05:00
lib.rs Initial --params implementation (#12249) 2024-03-24 15:40:21 -05:00
progress_bar.rs remove cp-old (#11622) 2024-01-24 07:38:15 +08:00
sort_utils.rs Rename Value::CustomValue to Value::Custom (#12309) 2024-03-27 22:10:56 +01:00