Skip to content

Commit

Permalink
feat(scan): rename only to include
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienaury committed Mar 27, 2024
1 parent 0034d2d commit 1a0b009
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Types of changes

## [0.2.0]

- `Added` flag `--only` (short `-o`) to only scan a specific list of fields
- `Added` flag `--alias` (short `-a`) to rename fields on the fly
- `Added` flag `--include` (short `-i`) to only scan a specific list of fields, this flag is repeatable
- `Added` flag `--alias` (short `-a`) to rename fields on the fly, this flag is repeatable
- `Fixed` self reference link are no longer counted in the links counter while scanning

## [0.1.0]
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ $ silo scan my-silo < input.jsonl

Analysis data is persisted on disk on the `my-silo` path relative to the current directory.

#### passthrough stdin to stdout

Use `--passthrough` (short : `-p`) to pass input to stdout instead of diplaying informations.

```console
$ silo scan my-silo --passthrough < input.jsonl
{"ID_CLIENT":"0001","EMAIL_CLIENT":"[email protected]","ACCOUNT_NUMBER":null}
{"ID_CLIENT":null,"EMAIL_CLIENT":null,"ACCOUNT_NUMBER":"C01"}
```

#### include only specific fields/columns

Use `--include <fieldname>` (short : `-i <fieldname>`, repeatable) to select only given columns to scan.

```console
$ silo scan my-silo --include ID_CLIENT --include EMAIL_CLIENT < input.jsonl
⣾ Scanned 5 rows, found 15 links (4084 row/s) [0s]
```

#### rename fields/columns on the fly

Use `--alias <fieldname>=<alias>` (short : `-a <fieldname>=<alias>`, repeatable) to rename fields before storing links.

```console
$ silo scan my-silo --alias ID_CLIENT=CLIENT --alias EMAIL_CLIENT=EMAIL < input.jsonl
⣾ Scanned 5 rows, found 15 links (4084 row/s) [0s]
```

### silo dump

The silo dump command is used to dump each connected entity into a file. This allows users to create a referential of all entities discovered within the JSONLine data. Here's how to use it:
Expand Down
10 changes: 5 additions & 5 deletions internal/app/cli/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func NewScanCommand(parent string, stderr *os.File, stdout *os.File, stdin *os.File) *cobra.Command {
var (
passthrough bool
only []string
include []string
aliases map[string]string
)

Expand All @@ -40,14 +40,14 @@ func NewScanCommand(parent string, stderr *os.File, stdout *os.File, stdin *os.F
Example: " lino pull database --table client | " + parent + " scan clients",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if err := scan(cmd, args[0], passthrough, only, aliases); err != nil {
if err := scan(cmd, args[0], passthrough, include, aliases); err != nil {
log.Fatal().Err(err).Int("return", 1).Msg("end SILO")
}
},
}

cmd.Flags().BoolVarP(&passthrough, "passthrough", "p", false, "pass stdin to stdout")
cmd.Flags().StringSliceVarP(&only, "only", "o", []string{}, "only scan these columns, exclude all others")
cmd.Flags().StringSliceVarP(&include, "include", "i", []string{}, "include only these columns, exclude all others")
cmd.Flags().StringToStringVarP(&aliases, "alias", "a", map[string]string{}, "use given aliases for each columns")

cmd.SetOut(stdout)
Expand All @@ -57,15 +57,15 @@ func NewScanCommand(parent string, stderr *os.File, stdout *os.File, stdin *os.F
return cmd
}

func scan(cmd *cobra.Command, path string, passthrough bool, only []string, aliases map[string]string) error {
func scan(cmd *cobra.Command, path string, passthrough bool, include []string, aliases map[string]string) error {
backend, err := infra.NewBackend(path)
if err != nil {
return fmt.Errorf("%w", err)
}

defer backend.Close()

driver := silo.NewDriver(backend, nil, silo.WithKeys(only), silo.WithAliases(aliases))
driver := silo.NewDriver(backend, nil, silo.WithKeys(include), silo.WithAliases(aliases))

var reader silo.DataRowReader

Expand Down

0 comments on commit 1a0b009

Please sign in to comment.