Last active
June 10, 2018 03:23
-
-
Save thiagoh/ab66e8495bb634fa726f28b7b258760b to your computer and use it in GitHub Desktop.
RiverDB the simplest and smallest db of all
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cmd=$1 | |
key=$2 | |
value=$3 | |
file=db.data | |
if [[ "$cmd" = "" ]]; then | |
echo "Invalid command"; | |
exit 1; | |
fi | |
if [[ "$key" = "" ]] || [[ "$key" = *":"* ]] ; then | |
echo "Invalid key. Key cannot be empty or have such characters: ':'"; | |
exit 1; | |
fi | |
if [[ "$cmd" = "get" ]]; then | |
# Using tac and sed GNU Commands in OSX | |
gtac $file | gsed -r -n 0,/^$key:\(.+\)/s/^$key:\(.+\)/\\1/p | |
exit 0; | |
fi | |
if [[ "$cmd" = "set" ]]; then | |
echo "$key:$value" >> $file | |
exit 0; | |
fi | |
## Used for testing purposes | |
if [[ "$cmd" = "fill" ]]; then | |
n=0 | |
while [[ $n -lt $2 ]]; do | |
key=`gdate +%s%N | md5` | |
./river set ${key:0:8} pre_value_`gdate +%s%N | md5`_pos_value | |
n=$(($n+1)) | |
done | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ riverdb set foo bar | |
$ riverdb get foo | |
bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment