sqlNukkitLib

Experimental sqlNukkitLib 1.0

Compatible API Versions
2.0.0
Sourcecode
https://github.com/Ragnok123/sqlNukkitLib/tree/cloudburst
Contributors
Ragnok123
Simple SQL library for Cloudburst server

SqlNukkitLib is asynchronous library plugin, which contains sql drivers and which can be used as a plugin for your server and also as a library in your external java programs.

CONNECTIONS:
Currently, library supports only two types of database connections:
  1. MySQL
  2. SQLite3
To connect to database, use this:
Java:
Database db = SQLLib.init(SQLType type, SQLConnectionInfo info);
Where SQLType can be SQLType.MySQL or SQLType.SQLITE3

For mysql, SQLConnection info is like this:
Java:
info = new MySQLConnectionInfo(String ip, String user, String password, String database, String port);
And for SQLite3:
Java:
info = new SQLite3ConnectionInfo(new File(path_to_db));
To connect and disconnect from database, you must use this:
Java:
db.connect();
db.close();
METHODS
To make life easier for developers, sqlNukkitLib contains built-in methods to make sql queries more quicker and easier.

First and very basic method is db.query();
Java:
db.query("INSERT INTO `players` (`nickname`,`money`) VALUES ('ragnok123','0');");
There are others basic queries and many others will be added with every next update.

To insert data, use function db.insert();. Example:
Java:
db.insert("players", new Pair[]{
    new Pair("nickname", "Ragnok"), new Pair("money", 0.0), new Pair("rank","User")
});
To update data, you can use method db.update():
Java:
db.update("players", "nickname", "Ragnok", new Pair[]{
    new Pair("money", 100.0), new Pair("rank", "VIP")
});
Finally, to select data, there is db.select() method.
Note, that select method does return void with HashMap in Consumer instead of HashMap object.
Java:
db.select("players", "nickname", "Ragnok", map -> {
    if(map.isEmpty()){
        getLogger().info("This player doesn't exists");
    } else {
        double money = (double)map.get("money");
        String rank = (String)map.get("rank");
        
        getLogger().info("Player Ragnok information:");
        getLogger().info(">> Money: " + String.valueOf(money));
        getLogger().info(">> Rank: " + rank);
    }
});
Author
Ragnok123
Downloads
962
Views
1,915
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Ragnok123

Top