-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from thenetrunna/master
implement shogdb client library and client CLI
- Loading branch information
Showing
23 changed files
with
650 additions
and
217 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ host = "127.0.0.1" | |
port = 4961 | ||
|
||
[save] | ||
enabled = true | ||
path = "./save.sdb" | ||
interval = 2 # seconds |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ host = "127.0.0.1" | |
port = 6961 | ||
|
||
[save] | ||
enabled = true | ||
path = "./save.sdb" | ||
interval = 2 # seconds |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "../include/cjson.h" | ||
#include "../src/client/client.h" | ||
|
||
int main() { | ||
NETLIBC_INIT(); | ||
|
||
shogdb_ctx_t *db_ctx = new_shogdb("http://127.0.0.1:6961"); | ||
|
||
UNWRAP(shogdb_set_int(db_ctx, "my_int", 69)); | ||
db_value_t *res_int = UNWRAP(shogdb_get(db_ctx, "my_int")); | ||
printf("INT VALUE: %lld\n", res_int->value_int); | ||
|
||
UNWRAP(shogdb_set_uint(db_ctx, "my_uint", 68)); | ||
db_value_t *res_uint = UNWRAP(shogdb_get(db_ctx, "my_uint")); | ||
printf("UINT VALUE: %lld\n", res_uint->value_uint); | ||
|
||
UNWRAP(shogdb_set_float(db_ctx, "my_float", 68.993)); | ||
db_value_t *res_float = UNWRAP(shogdb_get(db_ctx, "my_float")); | ||
printf("FLOAT VALUE: %f\n", res_float->value_float); | ||
|
||
UNWRAP(shogdb_set_str(db_ctx, "my_str", "deez nutz")); | ||
db_value_t *res_str = UNWRAP(shogdb_get(db_ctx, "my_str")); | ||
printf("STR VALUE: %s\n", res_str->value_str); | ||
|
||
UNWRAP(shogdb_set_bool(db_ctx, "my_bool", 1)); | ||
db_value_t *res_bool = UNWRAP(shogdb_get(db_ctx, "my_bool")); | ||
printf("BOOL VALUE: %d\n", res_bool->value_bool); | ||
|
||
UNWRAP(shogdb_set_json(db_ctx, "my_json", "[1, 2, 4]")); | ||
db_value_t *res_json = UNWRAP(shogdb_get(db_ctx, "my_json")); | ||
printf("JSON VALUE: %s\n", cJSON_Print(res_json->value_json)); | ||
|
||
// UNWRAP(shogdb_delete(db_ctx, "my_str")); | ||
|
||
char *res_all = UNWRAP(shogdb_print(db_ctx)); | ||
printf("ALL VALUES: %s\n", res_all); | ||
|
||
free_shogdb(db_ctx); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <netlibc/log.h> | ||
|
||
#include "../../include/cjson.h" | ||
#include "../client/client.h" | ||
|
||
int main(int argc, char **argv) { | ||
NETLIBC_INIT(); | ||
|
||
if (argc < 2) { | ||
PANIC("no argument supplied"); | ||
} | ||
|
||
char *address = argv[1]; | ||
|
||
shogdb_ctx_t *db_ctx = new_shogdb(address); | ||
|
||
char input[100]; | ||
|
||
do { | ||
// Prompt the user for input | ||
printf("> "); | ||
|
||
// Read the input | ||
fgets(input, sizeof(input), stdin); | ||
|
||
// Remove the trailing newline character | ||
input[strcspn(input, "\n")] = '\0'; | ||
|
||
if (strlen(input) < 3) { | ||
printf("invalid command - too short `%s`\n", input); | ||
continue; | ||
} | ||
|
||
// Check if the user wants to exit | ||
if (strcmp(input, "exit") == 0) { | ||
break; | ||
} else if (strcmp(input, "help") == 0) { | ||
printf("Commands:\n"); | ||
printf("help - show this screen\n"); | ||
printf("exit - exit the program\n"); | ||
printf("print - print all the keys and their values\n"); | ||
printf("address - show the server address\n"); | ||
printf("\n"); | ||
} else if (strcmp(input, "print") == 0) { | ||
char *res_all = UNWRAP(shogdb_print(db_ctx)); | ||
printf("%s\n", res_all); | ||
} else if (strcmp(input, "address") == 0) { | ||
printf("%s\n", address); | ||
} else if (strncmp(input, "GET ", 4) == 0) { | ||
char *key = &input[4]; | ||
|
||
db_value_t *res = UNWRAP(shogdb_get(db_ctx, key)); | ||
char *res_str = shogdb_print_value(res); | ||
|
||
printf("%s\n", res_str); | ||
} else if (strncmp(input, "SET ", 4) == 0) { | ||
// char *key = &input[4]; | ||
|
||
// db_value_t *res = UNWRAP(shogdb_get(db_ctx, key)); | ||
// char *res_str = shogdb_print_value(res); | ||
|
||
printf("OK\n"); | ||
} else { | ||
printf("invalid command `%s`\n", input); | ||
} | ||
} while (1); | ||
|
||
printf("Exiting ...\n"); | ||
|
||
free_shogdb(db_ctx); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.