piskvorky / sqlitedict

Persistent dict, backed by sqlite3 and pickle, multithread-safe.
Apache License 2.0
1.17k stars 131 forks source link

Add example how to delete a key/value pair #109

Closed bluepuma77 closed 4 years ago

bluepuma77 commented 4 years ago

Thanks for this great piece of software, it really makes dealing with key/value pairs and sqlite so much easier.

The documentation is good, I am just missing SELECT error handling and a DELETE example.

try:
    value = db[key]
except KeyError:
    print('Key not found', key)

What's the best way to DELETE a key/value pair from sqlite?

luk3yx commented 4 years ago

The easiest way to delete items is del db[key], as SqliteDict implements __delitem__:

https://github.com/RaRe-Technologies/sqlitedict/blob/f5c57f1f833e251b8ffe2e63642d4923b52646cd/sqlitedict.py#L257-L266

bluepuma77 commented 4 years ago

Perfect, thanks!