feat(cmd): added listcmd and refactored transactions to use TransactionArgs

This commit is contained in:
Lewis Wynne 2025-11-06 17:48:38 +00:00
parent cc206a7c8a
commit 2da42de7ab
5 changed files with 146 additions and 23 deletions

View file

@ -36,17 +36,26 @@ var getCmd = &cobra.Command{
func get(cmd *cobra.Command, args []string) error {
store := &Store{}
var v []byte
if err := store.Transaction(args[0], true, func(tx *badger.Txn, k []byte) error {
item, err := tx.Get(k)
if err != nil {
trans := TransactionArgs{
key: args[0],
readonly: true,
sync: false,
transact: func(tx *badger.Txn, k []byte) error {
item, err := tx.Get(k)
if err != nil {
return err
}
v, err = item.ValueCopy(nil)
return err
}
v, err = item.ValueCopy(nil)
return err
}); err != nil {
},
}
if err := store.Transaction(trans); err != nil {
return err
}
store.Print("%s", v)
return nil
}