-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
key-value module for std-rfc #965
Conversation
Before anyone asks, I wrote this as a set of space-separated-commands, rather than a
... was clobbering/shadowing the internal
Option 1 resulted in some "less readable" code and was also more "dangerous", since if someone imported the module with So I went with Option 2 ;-) |
I have no real problem with this but I wonder what our process should be for adding something to the stdlib. Seems like it should be more formal with voting or something. Not sure. |
Agreed - I was thinking the same thing while i was working on these. It's something we have to figure out if we hope to open up Possibilities:
|
I'll add tests for this one as well before bringing out of draft. Any thoughts on whether I should use |
You'd have to do some tests to see if it makes any difference because with msgpackz you have to pay for creating msgpack and brotli for compression/decompression. |
3c3677f
to
167b164
Compare
1f5c1a2
to
d2f1a32
Compare
Overview
std-rfc/kv
is a straightforward but flexible interface for setting and getting key-value pairs.Use-cases
| kv set foo
.inspect
command) and examine the results viakv list
orkv get
after the command completes.Features
stor
) or on-disk (into sqlite
).| transpose -dr
. The resulting record is, of course, easily converted to environment variables usingload-env
.$in
can be used.Examples
Simple get/set (positional)
Multiple assignments, conversion to record, and conversion to environment variables
Using list of timestamps, pipeline examples
Note that, in the example above, the following would be roughly equivalent:
The difference is that the second form (pipeline input) results in pipeline output by default. Since the first form does not have any pipeline input, the value returned to the pipeline output is
null
.Using a closure to manipulate the value
Note that in the example above, the universal store is used (
-u
). The behavior of the commands is the same, with the only difference being that the universal kv pairs are stored on-disk and persist across Nushell sessions. Remember to "clean up" test values from the universal store:Universal variables hook
The module includes a hook that can be added to
pre_execution
to create and update environment variables from the universal store. If this hook is set during your startup, all Nushell sessions will share the same universal variables.Start two different Nushell sessions. In the first:
In the other shell, an environment variable of the same name is created and updated. There is no need to restart the shell.