Lamedb
Simplistic key-value store/database
Install / Use
/learn @ogonna-anaekwe/LamedbREADME
lamedb
This is a simplistic database that functions as a key-value store. It doesn't do much: it's that lame, hence lamedb. lamedb has only 2 fields: key and value. The db is .txt file named lamedb_kv.txt. This file holds all the records in the db. So what little does lamedb do?
- Adds record or updates (existing) record.
- Gets a specific record.
- Deletes a specific record.
- Deletes all records.
- Shows all records.
Why is it lame?
- It only does the aforementioned things.
- It only supports two fields:
keyandvalue. (key, which MUST be greater than0, is our guarantee of uniquess: no two records can have the same key.) - It's not thread safe, hence ill-suited for concurrent queries. (Even though you can pass multiple queries each time, we process said queries sequentially.)
- It uses linked lists which are terrible for search. (The cpu time taken to search for records in the db grows linearly with the number of records - the time complexity is
O(n),nbeing the number of records in the db.)
Implementation
While the db is a .txt file, every query (get, put, etc) works with an in-memory linked list. This list contains all the records in the db. And now the implementation:
- init(ialize) db: Returns a list containing the db records. (Creates an empty file and by extension, an empty list if the db doesn't exist). Other methods can accept this list as a param.
- p(ut) record: Adds a record to the list (if it doesn't exist). Updates existing record (if it exists). Finally, overwrites the file with the updated list.
- g(et) record: Looks up
<key>in the list. Also prints the corresponding record if the<key>exists. - d(elete) record: Overwrites db file with list (leaving out the record that we seek to delete).
- c(lear) db: Drops all records. Here, we simply overwrite the db file with an empty file.
- a(all) db: Prints all records in the db.
Compilation
$ make
Example Queries
Get a record:
$ ./lamedb g,<key>
Add a record:
$ ./lamedb p,<key>,"<value>"
Update an existing record:
$ ./lamedb p,<key>,"<value>"
Delete a record:
$ ./lamedb d,<key>
Delete/Clear all records:
$ ./lamedb c
Show all records:
$ ./lamedb a
NOTE:
- Ideally,
<value>should be a string. - To add a record:
./lamedb p,1,"first"; to get that record:./lamedb g,1; to update that record:./lamedb p,1,"one"; to delete that record./lamedb d,1. - To do the above in one command:
./lamedb p,1,"first" g,1 p,1,"one" d,1. (Queries must be space separated.)
Related Skills
feishu-drive
348.0k|
things-mac
348.0kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
348.0kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
postkit
PostgreSQL-native identity, configuration, metering, and job queues. SQL functions that work with any language or driver
