Created
April 25, 2021 19:53
-
-
Save seamusv/6267d1a1886fceffd574e49d553e75ac to your computer and use it in GitHub Desktop.
DynamoDB Table Querier with RxGo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cmd | |
import ( | |
"context" | |
"fmt" | |
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types" | |
"github.com/seamusv/sparx/table_scanner/scanner" | |
"time" | |
"github.com/spf13/cobra" | |
) | |
var usersShardCmd = &cobra.Command{ | |
Use: "shard", | |
Short: "A brief description of your command", | |
RunE: func(cmd *cobra.Command, args []string) error { | |
env := cmd.Flag("env").Value.String() | |
scanner, err := scanner.NewScanner(region, scanner.WithEnvironment(env)) | |
if err != nil { | |
return err | |
} | |
showId := cmd.Flag("show_id").Value.String() | |
ctx, cancelFunc := context.WithTimeout(context.Background(), 300 * time.Millisecond) | |
defer cancelFunc() | |
result := make([]map[string]types.AttributeValue, 0) | |
if err := <-scanner.UsersShard(ctx, showId, &result); err != nil { | |
return err | |
} | |
fmt.Printf("Total items: %d\n", len(result)) | |
//for _, item := range result { | |
// fmt.Println(item) | |
//} | |
return nil | |
}, | |
} | |
func init() { | |
usersCmd.AddCommand(usersShardCmd) | |
usersShardCmd.Flags().String("env", "qa", "Environment") | |
usersShardCmd.Flags().StringP("show_id", "s", "", "Show ID") | |
usersShardCmd.MarkFlagRequired("show_id") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment