database.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. )
  6. // tableName is a const rather than an arg because using different BigTable instances
  7. // will be more common than having multiple tables in a single instance.
  8. // Table name is also passed to devnet guardians.
  9. const tableName = "v2Events"
  10. // These column family names match the guardian code that does the inserting.
  11. var columnFamilies = []string{
  12. "MessagePublication",
  13. "QuorumState",
  14. "TokenTransferPayload",
  15. "AssetMetaPayload",
  16. "NFTTransferPayload",
  17. "TokenTransferDetails",
  18. "ChainDetails"
  19. }
  20. func main() {
  21. project := flag.String("project", "", "The Google Cloud Platform project ID. Required.")
  22. instance := flag.String("instance", "", "The Google Cloud Bigtable instance ID. Required.")
  23. keyFilePath := flag.String("keyFilePath", "", "The Google Cloud Service Account json key file path.")
  24. setupDB := flag.Bool("setupDB", false, "Run database setup - create table and column families.")
  25. rowKey := flag.String("queryRowKey", "", "Query by row key, print the retrieved values.")
  26. previousMinutes := flag.Int("queryPreviousMinutes", 0, "Query for rows with a Timestamp in the last X minutes.")
  27. flag.Parse()
  28. for _, f := range []string{"project", "instance", "keyFilePath"} {
  29. if flag.Lookup(f).Value.String() == "" {
  30. log.Fatalf("The %s flag is required.", f)
  31. }
  32. }
  33. if *setupDB {
  34. RunSetup(*project, *instance, *keyFilePath)
  35. }
  36. if *rowKey != "" || *previousMinutes != 0 {
  37. Query(*project, *instance, *keyFilePath, *rowKey, *previousMinutes)
  38. }
  39. }