NDatabase - Fast data model creation - Powerful Async / Sync API icon

NDatabase - Fast data model creation - Powerful Async / Sync API -----

Lightweight opensource and easy to use INDEXED key-value database multi-platform framework



[​IMG]

[​IMG] [​IMG] [​IMG] [​IMG] [​IMG] [​IMG]

What is NDatabase API ?

NDatabase is a lightweight and easy to use indexed key-value store database framework mainly aimed for minecraft servers and is multi-platform (currently supporting Bukkit / Spigot servers).
It can be used as a plugin, so you can install it once and use it everywhere without having to configure a database and duplicate connection pool each time you develop a new plugin.

The API provide a fluent way to handle Async data fetch and server main thread callback with async to sync mechanism. NDatabase can support multiple databases (currently MySQL, SQLite, and MongoDB implementation). NDatabase can support java 8 from 18 and higher and all minecraft server version (tested from 1.8 to 1.19+).

NDatabase WIKI - Github page

Benefits of using NDatabase
  • Fast to use, you don't have to write any Repository class or write SQL: this framework is designed in a way that you just have to create your data model object (DTO) and a fully usable repository will be created automatically. See NDatabase Installation & Quickstart
  • Install once, use it everywhere: It's obvious that a server always have a lot of plugins, most of them require a database, and you need to re-implement, and configure your database for every plugin. Connection pool duplication cost a lot of resources. With NDatabase, you just install the plugin once, and you can use the API in every plugins without configuration needed.
  • Indexed key-value store: by design, a key-value store is very easy and fast to operate but is not indexed. But in some case we really need to retrieve data by field's value. NDatabase provide you a very easy way to index some of your fields and query your data. find more infos how key-value store are indexed
  • Fluent Async to Sync API: You are probably aware that you should never do database and I/O operations in the minecraft main-thread, NDatabase natively expose an API that can be used to retrieve data asynchronously and consume in synchronously.
  • Database type agnostic: You can develop your plugin once with NDatabase, and multiple database types will be supported through the same API. If you are a plugin creator, and you sell plugins it's very convenient because you don't have to care about if your customer use MongoDB, MySQL etc.

Create a Repository

When NDatabase is running on your server, Creating the schema and repository for your data model is very easy, you can actually do that with one line of code.
Code (Java):
Repository <UUID, PlayerStatsDTO > repository = NDatabase. api ( ). getOrCreateRepository (PlayerStatsDTO. class ) ;
Async / Sync usage of your repository

You should never do I/O and database operation in your minecraft main thread, that's why the repository provide a fluent API to retrieve data asynchronously and then run a callback in your main thread if needed.

Code (Java):

// Async to Sync (get data async and consume it in the main thread)
blockRepository. getAsync ( "id" )
        . thenSync ( (bloc ) -> {
            placeBlockInWorld (bloc ) ;
        } ) ;

// Full Async (get data async and consume it in the same async thread)
playerRepository. getAsync (joinedPlayer. getUUID ( ) )
        . thenAsync ( (playerDTO ) -> {
            loadPlayer (playerDTO ) ;
        } ) ;
 
Code (Java):

List <PlayerData > bestPlayers = repository. find (NQuery. predicate (
          "$.statistics.score >= 100 || $.discordId == 3432487284963298"
) ) ;
 
[​IMG]
  • Async to Aync: in the first example we retrieve the data of a block asynchronously, as we know we should not change the game state asynchronously, we give a consumer callback that will be scheduled and run in the main thread. This approach doesn't affect main thread's performances as we retrieve the data in another thread.
  • Full Async: in the second example, we retrieve the data of a player who just connected to the server asynchronously and consume this data in the same async thread, because we don't necessarily have to do bukkit operation but just cache some informations, so all this can be done of the main thread. Keep in mind that you should use concurrent collections to avoid getting ConcurrentModificationException
Wanna try this out ?

You can get the API of NDatabase with gradle or maven and try it.
I also recommend your to check out the github page for the full documentation about the installation, best practice and future updates.
Code (Text):

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

<dependency>
    <groupId>com.github.NivixX.NDatabase</groupId>
    <artifactId>ndatabase-api</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>
Resource Information
Author:
----------
Total Downloads: 1,067
First Release: Feb 3, 2023
Last Update: Dec 16, 2024
Category: ---------------
All-Time Rating:
4 ratings
Find more info at github.com...
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings