Search code examples
javaberkeley-dbberkeley-db-je

How to get all objects using Berkeley DB meeting a condition


I just found out about Berkeley DB and its performance yesterday. I'm willing to use it in a Java project.

What I would like to know is, how to get all objects stored in my DB that meet a certain condition.

For example, I have objects of type Message(int id, String value, Date date) stored, and I would like to get all the messages of the last 10 minutes.

In other words, what is the equivalent of this SQL query

SELECT * FROM messages WHERE date < 2016-04-12T23:20:50.52Z

in Berkeley DB.

Is it possible to do it with Berkeley DB's API or I should do it all by coding?

Thanks in advance.


Solution

  • Berkeley DB is a key-value store. If you want to do anything more sophisticated than get/set values by their identifiers, you're going to have to do the work. There is an SQL module for it. I've never used it, but I wouldn't place too many chips on that number.

    A problem such as you pose is much better solved in SQLite, which uses something like Berkeley DB under the hood, and (of course) supports SQL. It also supports date arithmetic on correctly formatted strings.