diff options
author | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-14 14:55:08 -0400 |
---|---|---|
committer | bpc2003 <wpesfriendnva@gmail.com> | 2025-03-14 14:55:08 -0400 |
commit | 879f22e8cc5ac396dc7037212c15f7bec0eba17b (patch) | |
tree | 75bf10fdc6efd229d9740742c98f86a8670eb10f | |
parent | a9880a6f40ed6f55bc56d7f59c5f88a6718e8549 (diff) |
Update README.md
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | README.md | 33 | ||||
-rw-r--r-- | src/main.c | 11 |
3 files changed, 41 insertions, 5 deletions
@@ -2,7 +2,7 @@ *.db *.db~ -# compiled files +# build files target/ # lsp @@ -1,2 +1,33 @@ # mdb -mdb is a embedded key-value database written in C +mdb is a simple embedded key-value database written in C. + +## Table of Contents +- [Installation](##Installation) +- [Reference](##Reference) +- [Removal](##Removal) +- [License](./LICENSE) + +## Installation +In order to install mdb clone this repository then run: +```sudo make install``` + +## Reference +There are four basic commands in mdb: +- exit: exits the program +- GET: gets a given key from a given object +- SET: sets a given key-value pair in a given object +- DEL: deletes a given key-value pair from a given object +### API Reference +There are six functions in mdb.h +- readdb: reads a database from a given file +- writedb: writes a database to a given file +- getkeys: gets every key-value pair from a given object +- getkey: gets a single key-value pair from a given object +- setkey: sets a given key-value pair in a given object +- delkey: deletes a given key-value pair from a given object + +## Removal +In order to remove mdb run: +```sudo make remove``` +or +```sudo make uninstall``` @@ -12,9 +12,13 @@ void delkeys(struct keytablist *list, int id, char **keys, int klen); int main(int argc, char **argv) { - if (argc != 2) + if (argc > 2) { + printf("usage: %s [db file]\n", argv[0]); exit(1); - char *filename = argv[1]; + } + char *filename = NULL; + if (argc == 2) + filename = argv[1]; struct keytablist *list = readdb(filename); char *cmd = calloc(1024, sizeof(char)); @@ -62,7 +66,8 @@ int main(int argc, char **argv) } free(cmd); - writedb(filename, list); + if (filename != NULL) + writedb(filename, list); for (int i = 0; i < list[0].len; ++i) { int *indexes = getkeys(list, i); for (int j = 0; indexes[j]; ++j) |