lucaong / cubdb

Elixir embedded key/value database
Apache License 2.0
556 stars 23 forks source link

How to remove all records in a database? #42

Closed undr closed 2 years ago

undr commented 3 years ago

Hey there.

I'm going to use cubdb to store temporary logs in my app. My app has to reset the database from time to time by user request. I didn't find a way how to reset the database. Should I remove (or rename) database dir, or is there a more native way to achieve this in one operation?

lucaong commented 3 years ago

Hello @undr , if you want to clear the database completely, you can remove or rename the data directory, as you mentioned. This needs to be done while CubDB is not running though, so you should probably stop the CubDB process, clear the data directory, then start it again.

Your question makes me realize that I should probably add a way to clear the database without needing to stop the process (that would be quite simple, I think I can add it in the next release).

undr commented 2 years ago

Thank you for your reply.

It would be awesome to have the ability to remove all records without a server halt. It will allow me to put the database process under the supervisor's control. Because, currently, I have to use a dynamic supervisor to stop/start a server to delete a database. It's not handy to use.

I am looking forward to the new feature. =)

lucaong commented 2 years ago

Hi @undr, #43 implements a new clear/1 function that atomically and efficiently deletes all entries in the database. I just need some more time to make sure everything is ok, then soon I will make a new release including it.

lucaong commented 2 years ago

Version v1.1.0 is released, and includes this feature. Closing the issue now, but feel free to comment further if necessary.