nushell/crates/nu-command/src/stor
João Fidalgo 073d8850e9
Allow stor insert and stor update to accept pipeline input (#12882)
- this PR should close #11433 

# Description
This PR implements pipeline input support for the stor insert and stor
update commands,
enabling users to directly pass data to these commands without relying
solely on flag parameters.

Previously, it was only possible to specify the record data using flag
parameters,
which could be less intuitive and become cumbersome:

```bash
stor insert --table-name nudb --data-record {bool1: true, int1: 5, float1: 1.1, str1: fdncred, datetime1: 2023-04-17}
stor update --table-name nudb --update-record {str1: nushell datetime1: 2020-04-17}
```

Now it is also possible to pass a record through pipeline input:

```bash
{bool1: true, int1: 5, float1: 1.1, str1: fdncred, datetime1: 2023-04-17} | stor insert --table-name nudb
{str1: nushell datetime1: 2020-04-17} | stor update --table-name nudb"
```

Changes made on code:

- Modified stor insert and stor update to accept a record from the
pipeline.
- Added logic to handle data from the pipeline record.
- Implemented an error case to prevent simultaneous data input from both
pipeline and flag.

# User-facing changes

Returns an error when both ways of inserting data are used.

The examples for both commands were updated and in each command, when
the -d or -u fags are being used at the same time as input is being
passed through the pipeline, it returns an error:


![image](https://github.com/nushell/nushell/assets/120738170/c5b15c1b-716a-4df4-95e8-3bca8f7ae224)

Also returns an error when both of them are missing:


![image](https://github.com/nushell/nushell/assets/120738170/47f538ab-79f1-4fcc-9c62-d7a7d60f86a1)


# Tests + Formating
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

Co-authored-by: Rodrigo Friães <rodrigo.friaes@tecnico.ulisboa.pt>
2024-06-06 10:30:06 -05:00
..
create.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
delete.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
export.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
import.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
insert.rs Allow stor insert and stor update to accept pipeline input (#12882) 2024-06-06 10:30:06 -05:00
mod.rs Simplify the feature gates for stor commands (#11416) 2023-12-24 13:31:46 +01:00
open.rs Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
reset.rs Shrink the size of Expr (#12610) 2024-04-24 15:46:35 +00:00
stor_.rs Make get_full_help take &dyn Command (#12903) 2024-05-19 19:56:33 +02:00
update.rs Allow stor insert and stor update to accept pipeline input (#12882) 2024-06-06 10:30:06 -05:00