https://github.com/lovromazgon/badger-cli
A simple CLI for badger DB
https://github.com/lovromazgon/badger-cli
badger badgerdb cli go
Last synced: 12 months ago
JSON representation
A simple CLI for badger DB
- Host: GitHub
- URL: https://github.com/lovromazgon/badger-cli
- Owner: lovromazgon
- License: mit
- Created: 2024-07-28T12:41:44.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-31T16:53:10.000Z (over 1 year ago)
- Last Synced: 2025-07-21T22:51:26.051Z (12 months ago)
- Topics: badger, badgerdb, cli, go
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# badger-cli
[](https://github.com/ConduitIO/conduit/blob/main/LICENSE)
[](https://goreportcard.com/report/github.com/lovromazgon/badger-cli)
`badger-cli` is a simple command-line interface for interacting with [Badger DB](https://github.com/dgraph-io/badger),
a fast key-value database written in Go.

## Features
- Connect to an existing Badger DB
- Get, set, and delete key-value pairs
- List keys with optional glob pattern matching
- Read-only mode for safe database inspection
## Installation
Install using homebrew:
```sh
brew install lovromazgon/tap/badger-cli
```
Or build it from source using Go:
```sh
go install github.com/lovromazgon/badger-cli
```
Or download the binary manually from the [latest release](https://github.com/lovromazgon/badger-cli/releases/latest).
## Usage
```sh
$ badger-cli -h
Usage: badger-cli [options]
A command-line interface for a Badger key-value database.
Options:
-r, --readonly Open database in read-only mode
-h, --help Show help
Examples:
badger-cli /path/to/db
badger-cli --readonly /path/to/db
```
### Read-only Mode
To open the database in read-only mode (useful for inspecting production databases safely):
```sh
badger-cli --readonly /path/to/your/badger/db
# or
badger-cli -r /path/to/your/badger/db
```
In read-only mode:
- The prompt will show `[READONLY] >`
- Only `get` and `list` commands are available
- `set` and `delete` commands are disabled
- The database is opened with read-only permissions
- The database must already exist (will not create new databases)
- If the database is already in use by another process, you may need to run without -readonly first to ensure proper initialization
Once the CLI is running, you can use the following commands:
- `get `: Retrieve the value for a given key
- `set `: Set a value for a given key (not available in read-only mode)
- `delete `: Delete a key-value pair (not available in read-only mode)
- `list [pattern]`: List all keys, optionally filtered by a glob pattern
- `exit`: Exit the CLI
### Examples
Normal mode:
```sh
> set mykey myvalue
Value set successfully
> get mykey
myvalue
> list my*
mykey
> delete mykey
Value deleted successfully
> list
No matching keys found
> exit
```
Read-only mode:
```sh
[READONLY] > get mykey
myvalue
[READONLY] > list my*
mykey
[READONLY] > set newkey newvalue
Error: Cannot set values in read-only mode
[READONLY] > delete mykey
Error: Cannot delete values in read-only mode
[READONLY] > exit
```
## Glob Pattern Matching
The `list` command supports glob pattern matching:
- `*`: Matches any sequence of characters
- `?`: Matches any single character
- `[abc]`: Matches any character in the set
- `[a-z]`: Matches any character in the range
Examples:
- `list app_*`: Lists all keys starting with "app_"
- `list *_config`: Lists all keys ending with "_config"
- `list user_??`: Lists all keys starting with "user_" followed by exactly two characters
## Acknowledgements
The initial version of this CLI was developed with assistance from an AI language model. The code has since been modified and expanded.