Skip to content

A. Should you use NDatabase ?

Fabian edited this page Mar 1, 2023 · 9 revisions

The biggest strength of NDatabase is that you can create and operate your datamodel very fast without using any SQL languages. NDatabase is agnostic regarding what Database infrastructure you have, the API will work either with SQL databases or MongoDB. But the downside of it is that you have not a full control of what you can do in traditional relational databases can natively do.

NDatabase is an indexed key-value store, so let's explore the characteristics of a key-value store and how NDatabase is able to index it !

What is a key-value store ?

A key-value store works similary to a Map, you can store your data object given a key and access your data directly O(1) with the key. Using a key-value store have some pros and cons, so depending on your projects you would prefer using a key-value store over a traditional relational database and vice-versa.

The biggest advantage of using a key-value store is the fast development rapidity. You basicaly just have to create a class which extends NEntity and you're done with your database management. In my own server, I had to create a lot of new plugins in a very short time, spending time to configure and setup a relational database always took me a big portion of the time, so that's why I decided to create this project for my own server and share it.

The biggest disadvantage of using a key-value store is that you cannot retrieve and query your data by using a value property, thus you would need to retrieve your entire "HashMap" and filter the values yourself, which is not effecient. However NDatabase have a special mechanism in order to index your key-value store and query it given value's properties predicate. Read more about How key-value store are indexed and NQuery

If you have a very large project and need a strongly relational database with complex queries, an ORM like Hibernate will suit better but is take more time to develop and maintain.

Thus the choice of using a key-value store depends on if you do need more complex queries in your plugins. Note that in the case where you really need to index a specific field, you can still create another key-value store and use the field's value as key.