Skip to content

Conversation

getify
Copy link

@getify getify commented Sep 5, 2025

NOTE: this isn't explicitly intended to actually add to the repo in its current form. It may be added or not, but that's not the goal at the moment. The point here is only code review.

This code was heavily generated by ChatGPT, so my goal is to get a sense of whether any parts of this code are good, bad, or neutral, and learn better how such a program should be coded.


This is a first-draft of a tool that satisfies the following design priorities:

  • written in go
  • acts as CLI tool
  • embeds defradb in-process
  • persists to disk (via Badger)
  • creates a basic key-value type store (via an embedded type DDL)
  • accepts parameters to set config, like keyring-secret and data-root
  • primary input is a graphql-form query against the defra, such as query { .. } or mutation { .. }
  • accepts query input either via stdin or -query CLI parameter
  • includes a few helpful affordances such as home-dir expansion, default root dir, pretty JSON printing, etc.

now also includes KV actions via convenience parameters:

  • -has checks if a key exists in the KV store
  • -get looks up an entry by key name
  • -set inserts (or updates) a key/value into the KV store
  • -remove removes an entry by key name

This is a first-draft of a tool that satisfies the following design priorities:

- written in go
- acts as CLI tool
- embeds defradb in-process
- persists to disk (via Badger)
- creates a basic key-value type store (via an embedded `type` DDL)
- accepts parameters to set config, like keyring-secret and data-root
- primary input is a graphql-form query against the defra, such as `query { .. }` or `mutation { .. }`
- accepts query input either via stdin or `-query` CLI parameter
- includes a few helpful affordances such as home-dir expansion, default root dir, pretty JSON printing, etc.
Added `-has`, `-get`, `-set`, and `-remove` CLI commands
Per fix in #3992, now passing JSON objects as variables works, instead of needing to serialize and inline them into the query. Yay!
rename `defra-kv.go` to `defra-kv/main.go`

removed unnecessary/ineffective bits of stdio muting/override, fixed log_level env name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant