Code Monkey home page Code Monkey logo

datamanager's Introduction

DataManager

License: MIT jitpack

DataManager is a simple library plugin for Nukkit Minecraft Bedrock core (and forks), that will help you to create and manage your SQL connections with ease.

Libraries

Nukkit is nuclear-powered server software for Minecraft: Pocket Edition (you can also use PowerNukkit or PowerNukkitX).

Sql2o is small useful framework that makes coding for database easy.

HikariCP is a "zero-overhead" production ready JDBC connection pool. At roughly 130Kb, the library is very light.

Performance of SELECT

Execute 1000 SELECT statements against a DB and map the data returned to a POJO.

Method Duration
Hand coded ResultSet 15ms
Sql2o 24ms (60% slower)

How to install

If any plugin requires a DataManager, you just need to download and put it in plugins folder. Usually it will be enough. Also, you can configure some default database settings in config.yml.

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.hteppl</groupId>
    <artifactId>DataManager</artifactId>
    <version>2.1.0-SNAPSHOT</version>
</dependency>

Gradle

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.hteppl:DataManager:2.1.0-SNAPSHOT'
}

Configuration

Default plugin config.yml settings.

# sqlite path settings for method SQLiteDatabase(String database)
sqlite:
  # use global folder for saving sqlite tables (near plugins, worlds, etc.) or plugin folder
  global: true
  # name for folder if "global" is set to true
  folder-name: "database"

# mysql settings
mysql:
  # default mysql connection properties
  properties: "useSSL=false&autoReconnect=true&useUnicode=true&serverTimezone=UTC"
  # Hikari connection pool settings (https://github.com/brettwooldridge/HikariCP)
  hikari:
    auto-commit: true
    connection-timeout: 30000
    idle-timeout: 600000
    keepalive-time: 0
    max-lifetime: 1800000
    maximum-pool-size: 10

How to use

Firstly we recommend to read:

Here is very basic example of your MySQL database class:

import me.hteppl.data.database.MySQLDatabase;
import org.sql2o.Connection;

public class MyDatabase extends MySQLDatabase {

    public MyDatabase() {
        super("host", "database", "user", "password");
        // also you can execute your db scheme with
        this.executeScheme("CREATE TABLE IF NOT EXISTS ...");

        // or use openConnection() method
        try (Connection connection = this.openConnection()) {
            connection.createQuery("SELECT ...").executeUpdate();
        }

        // if you need disable auto commit, use beginTransaction() method
        try (Connection connection = this.beginTransaction()) {
            connection.createQuery("SELECT ...").executeUpdate();
        }
    }
}

or SQLite database class:

import me.hteppl.data.database.SQLiteDatabase;
import org.sql2o.Connection;

public class MyDatabase extends SQLiteDatabase {

    public MyDatabase() {
        super("database");
        // also you can execute your db scheme with
        this.executeScheme("CREATE TABLE IF NOT EXISTS ...");

        // or use openConnection() method
        try (Connection connection = this.openConnection()) {
            connection.createQuery("SELECT ...").executeUpdate();
        }

        // if you need disable auto commit, use beginTransaction() method
        try (Connection connection = this.beginTransaction()) {
            connection.createQuery("SELECT ...").executeUpdate();
        }
    }
}

After that, you can easily do what you want with your Sql2o connections:

/* import your database class */

public class Main {

    public static void main(String[] args) {
        MyDatabase db = new MyDatabase();

        try (Connection connection = db.openConnection()) {
            connection.createQuery("SELECT ...");
        }

        // also you can execute your db scheme with
        db.executeScheme("CREATE TABLE IF NOT EXISTS ...");
    }
}

datamanager's People

Contributors

hteppl avatar iwareq avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.