go-bond / bond

Other
10 stars 3 forks source link

gobond-cli utils #55

Closed marino39 closed 2 years ago

marino39 commented 2 years ago

The go-bond cli functionality for database inspection:

Example:

Adding handler:

insp, err := bond.NewInspect([]bond.TableInfo{ExampleStructTable})
if err != nil {
    panic(err)
}

_ = http.ListenAndServe(":5555", bond.NewInspectHandler(insp))

Interacting using bond-cli:

⋊> ~/P/h/bond on cli ⨯ ./bond-cli --url http://localhost:5555/ tables | json_pp                                                                                     10:32:28
[
   "example_stuct_table"
]
⋊> ~/P/h/bond on cli ⨯ ./bond-cli --url http://localhost:5555/ indexes --table example_stuct_table | json_pp                                                        10:32:56
[
   "primary",
   "type_idx",
   "main_ord_amount_desc_idx",
   "main_isactive_true_idx"
]
⋊> ~/P/h/bond on cli ⨯ ./bond-cli --url http://localhost:5555/ entry-fields --table example_stuct_table | json_pp                                                   10:33:08
{
   "Amount" : "uint64",
   "Description" : "string",
   "Id" : "uint64",
   "IsActive" : "bool",
   "Type" : "string"
}
⋊> ~/P/h/bond on cli ⨯ ./bond-cli --url http://localhost:5555/ query --table example_stuct_table | json_pp                                                          10:33:18
[
   {
      "Amount" : 1,
      "Description" : "test description",
      "Id" : 1,
      "IsActive" : true,
      "Type" : "test"
   },
   {
      "Amount" : 7,
      "Description" : "test description 2",
      "Id" : 2,
      "IsActive" : false,
      "Type" : "test"
   },
   {
      "Amount" : 5,
      "Description" : "test description 3",
      "Id" : 3,
      "IsActive" : true,
      "Type" : "test"
   },
   {
      "Amount" : 3,
      "Description" : "test description 4",
      "Id" : 4,
      "IsActive" : true,
      "Type" : "test"
   },
   {
      "Amount" : 2,
      "Description" : "test description 5",
      "Id" : 5,
      "IsActive" : true,
      "Type" : "test2"
   }
]

⋊> ~/P/h/bond on cli ⨯ ./bond-cli --url http://localhost:5555/ query --table example_stuct_table --after '{"Id": 4}' | json_pp                                      10:34:28
[
   {
      "Amount" : 2,
      "Description" : "test description 5",
      "Id" : 5,
      "IsActive" : true,
      "Type" : "test2"
   }
]