Giter Club home page Giter Club logo

kv-bash's Introduction

kv-bash Build Status

About

  • tiny key/value dabatase
  • database store in home directory
  • each user has 1 database
  • usage by importing 5 bash functions via $ source ./kv-bash

Requirements

unix-like environement, no dependencies

Usage

import all database functions

$ source ./kv-bash         # import kv-bash functions

use database functions

$ kvset <key> <value>      # create or change value of key
$ kvget <key>              # get value of key
$ kvdel <key>              # delete by key
$ kvlist                   # list all current key/value pairs
$ kvclear                  # clear database

Examples

$ source ./kv-bash
$ kvset user mr.bob
$ kvset pass abc@123
$ kvlist
user mr.bob
pass abc@123
$ kvget user
mr.bob
$ kvget pass
abc@123
$ kvdel pass
$ kvget pass

$ kvclear

Run tests

git clone https://github.com/damphat/kv-bash.git
cd kv-bash
./kv-test

test result

RUN ALL TEST CASES:
===================
  1 call kvget for non-exist key should return empty  [  OK  ]
  2 kvset then kvget a variable                       [  OK  ]
  3 kvset then kvset again with different value       [  OK  ]
  4 deleted variable should be empty                  [  OK  ]
  5 kvdel non exist should be OK                      [  OK  ]
  6 kvset without param return error                  [  OK  ]
  7 kvget without param return error                  [  OK  ]
  8 kvdel without param return error                  [  OK  ]
  9 kvset 3 keys/value; kvlist => line count = 3      [  OK  ]
 10 non-exist-var => empty value => line count = 1    [  OK  ]
 11 kvclear; kvlist => line count = 0                 [  OK  ]
 12 kvget return empty value => error code != 0       [  OK  ]
 13 spaces in value                                   [  OK  ]

kv-bash's People

Contributors

damphat avatar digitalkram avatar fattredd avatar timmattison avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kv-bash's Issues

feat: multiple db support

# list all databases, and mark the current database with the '*'
kvuse
    * default-db
      test-1
      todo-app

# switch to todo-app
kvuse todo-app

TODO

  • kvuse switch the current database
  • kvuse print all database if there no parameter supplied to the kvuse command
  • kvset create the database if it not exists
  • kvclear should also remove database
  • kvlist should print current database name at the top?
  • how to go back to default-db

Questions

  • Q: how to see current database?
  • A: kvuse
  • Q: how to list all databases?
  • A: kvuse
  • Q: how to create database?
  • A: kvuse <db-name>
  • Q: how to delete a database?
  • A: kvuse <db-name> then kvclear

What about @ char in key vars?

@ Is an invalid symbol atm in keys in kv-bash.
I've added @ to the regexp and kv-test pass all the tests.

Is there any specific reason @ simbol was excluded from allowed key ?

kvget always include new-line character

small problem

"bob" has 3 chars, but kvget return string of 4 chars

[kv-bash]# source ./kv-bash
[kv-bash]# kvset name "bob"
[kv-bash]# kvget name > output
[kv-bash]# stat -c%s output
4
[root@localhost kv-bash]# rm -f output

The reason is kvget echo with a new-line character

Line ending issue when using git for windows

REPRODUCTION:

  1. clone this repository using git for windows,
    C:\> git clone http://github.com/damphat/kv-bash
  2. run these bash scripts in WSL
C:\> wsl
/mnt/c$ cd kv-bash

/mnt/c/kv-bash$ source kv-bash
: command not found
: command not found
: command not found
: command not found
-bash: kv-bash: line 47: syntax error near unexpected token `$'{\r''
'bash: kv-bash: line 47: `kv_echo_err() {

WHY?
Git for Windows using CRLF for line-endings by default. Bash does not accept these line-endings.

SOLUTION:
Add ".gitattributes" to tell git use LF for bash script files.

Use atomic rename

Looks like you don't have any locking and don't do an atomic rename, this could lead to data loss on unexpected OS termination.

TESTCASE 12 - spaces in value [FAILED]

RUN ALL TEST CASES:
===================
  1 get unset var should return empty                 [  OK  ]
  2 set then get a variable                           [  OK  ]
  3 set again with different value                    [  OK  ]
  4 del variable should be empty                      [  OK  ]
  5 del non existing valriable is no-error            [  OK  ]
  6 set without param return error                    [  OK  ]
  7 get without param return error                    [  OK  ]
  8 del without param return error                    [  OK  ]
  9 set 3 keys/value; list => line count = 3          [  OK  ]
 10 clear => line count = 0                           [  OK  ]
 11 empty value => error code != 0                    [  OK  ]
 12 spaces in value                                   [FAILED]

Can not run on MacOS

When I run db-test script, I got this error

➜  test git:(master) ✗ cd db-bash 
➜  db-bash git:(master) ./db-tests
db-bash: line 46: `echo-err': not a valid identifier

[Question] Is it possible to also have "in-memory" only get and set of values?

Hey there,
I came across this the other day and it seems like it should fit my need quite well. I am using it to store the values of system stats (temperatures, memory, etc) that I gather from running a script for system monitoring and display. It is much more helpful to be able to run my script once on an interval then kvset the values then just let everything else access that stored values until the script runs it's next interval to update instead having each thing that needs the value run the script for it.

My question is, is it possible to have a 'mode' in which to run kv-sh, where either some specific key/values (or all, if just doing some of them is not possible) are not saved to disk at all, but instead just stored in memory but can be set and get the same way? Some of these values I have updating once per 10 seconds, some once per 5 seconds, but for temp, I have it update once per second and I can't help but feel that writing a tiny bit of data to disk once per second, while very convenient for my use case, might be a bad idea for my SSD, especially considering there is no need to actually save that data for more than one second anyways.

I thank you for making this tool, and for your consideration,
Thanks,
-MH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.