33[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
44[ ![ jitpack] ( https://jitpack.io/v/hteppl/DataManager.svg )] ( https://jitpack.io/#hteppl/DataManager )
55
6- DataManager is a simple library plugin for Nukkit Minecraft Bedrock core (and forks), that will help you to create and
6+ DataManager is a simple library plugin for [ PowerNukkitX] ( https://github.com/PowerNukkitX/PowerNukkitX ) Minecraft
7+ Bedrock core, that will help you to create and
78manage your SQL connections with ease.
89
9- ## Libraries
10-
11- [ ** Nukkit** ] ( https://github.com/CloudburstMC/Nukkit ) is nuclear-powered server software for Minecraft: Pocket Edition
12- (you can also use PowerNukkit or PowerNukkitX).
13-
14- [ ** Sql2o** ] ( https://github.com/aaberg/sql2o ) is small useful framework that makes coding for database easy.
15-
16- [ ** HikariCP** ] ( https://github.com/brettwooldridge/HikariCP ) is a "zero-overhead" production ready JDBC connection pool.
17- At roughly 130Kb, the library is very light.
18-
19- ## Performance of SELECT
10+ ## Build JAR File
2011
21- Execute 1000 SELECT statements against a DB and map the data returned to a POJO.
22-
23- | Method | Duration |
24- | ------------------------------------------| -------------------|
25- | Hand coded <code >ResultSet</code > | 15ms |
26- | [ Sql2o] ( https://github.com/aaberg/sql2o ) | 24ms (60% slower) |
12+ ``` shell
13+ $ git clone https://github.com/hteppl/DataManager
14+ $ cd DataManager
15+ $ mvn clean package
16+ ```
2717
2818## How to install
2919
@@ -45,7 +35,7 @@ enough. Also, you can configure some default database settings in `config.yml`.
4535<dependency >
4636 <groupId >com.github.hteppl</groupId >
4737 <artifactId >DataManager</artifactId >
48- <version >2.1 .0-SNAPSHOT</version >
38+ <version >2.2 .0-SNAPSHOT</version >
4939</dependency >
5040```
5141
@@ -61,7 +51,7 @@ allprojects {
6151
6252``` groovy
6353dependencies {
64- implementation 'com.github.hteppl:DataManager:2.1 .0-SNAPSHOT'
54+ implementation 'com.github.hteppl:DataManager:2.2 .0-SNAPSHOT'
6555}
6656```
6757
@@ -70,102 +60,106 @@ dependencies {
7060Default plugin ` config.yml ` settings.
7161
7262``` yaml
73- # sqlite path settings for method SQLiteDatabase(String database)
74- sqlite :
75- # use global folder for saving sqlite tables (near plugins, worlds, etc.) or plugin folder
76- global : true
77- # name for folder if "global" is set to true
78- folder-name : " database"
79-
80- # mysql settings
81- mysql :
82- # default mysql connection properties
83- properties : " useSSL=false&autoReconnect=true&useUnicode=true&serverTimezone=UTC"
84- # Hikari connection pool settings (https://github.com/brettwooldridge/HikariCP)
85- hikari :
86- auto-commit : true
87- connection-timeout : 30000
88- idle-timeout : 600000
89- keepalive-time : 0
90- max-lifetime : 1800000
91- maximum-pool-size : 10
63+ # sqlite directory name for anonymous databases
64+ # set empty, for creating database file in plugin's folder by default
65+ sqlite-directory : " database"
66+
67+ # default mysql connection properties
68+ mysql-properties : " useSSL=false&autoReconnect=true&useUnicode=true&serverTimezone=UTC"
69+
70+ # Hikari connection pool settings (https://github.com/brettwooldridge/HikariCP)
71+ hikari :
72+ auto-commit : true
73+ connection-timeout : 30000
74+ idle-timeout : 600000
75+ keepalive-time : 0
76+ max-lifetime : 1800000
77+ maximum-pool-size : 10
9278` ` `
9379
9480## How to use
9581
9682Firstly we recommend to read:
9783
98- - [*Sql2o Documentation *](https ://github.com/aaberg/sql2o/wiki )
84+ - [*Jdbi Developer Guide *](http ://jdbi.org/ )
9985- [*HikariCP Configuration*](https://github.com/brettwooldridge/HikariCP#gear-configuration-knobs-baby)
10086
101- Here is very basic example of your MySQL database class:
87+ Very basic example of MySQL database class:
10288
10389` ` ` java
10490import me.hteppl.data.database.MySQLDatabase;
105- import org.sql2o.Connection ;
91+ import org.jdbi.v3.core.Handle ;
10692
10793public class MyDatabase extends MySQLDatabase {
10894
10995 public MyDatabase() {
11096 super("host", "database", "user", "password");
111- // also you can execute your db scheme with
112- this.executeScheme("CREATE TABLE IF NOT EXISTS ...");
113-
114- // or use openConnection() method
115- try (Connection connection = this.openConnection()) {
116- connection.createQuery("SELECT ...").executeUpdate();
117- }
11897
119- // if you need disable auto commit, use beginTransaction() method
120- try (Connection connection = this.beginTransaction()) {
121- connection.createQuery("SELECT ...").executeUpdate();
98+ try (Handle handle = this.getHandle()) {
99+ handle.createUpdate("...")
100+ .bind("var1", "data1")
101+ .bind("var2", "data2")
102+ .execute();
122103 }
123104 }
124105}
125106```
126107
127- or SQLite database class:
108+ Example of SQLite database class:
128109
129110``` java
130111import me.hteppl.data.database.SQLiteDatabase ;
131- import org.sql2o.Connection ;
112+ import org.jdbi.v3.core.Handle ;
132113
133114public class MyDatabase extends SQLiteDatabase {
134115
135116 public MyDatabase () {
136117 super (" database" );
137- // also you can execute your db scheme with
138- this . executeScheme(" CREATE TABLE IF NOT EXISTS ..." );
139-
140- // or use openConnection() method
141- try (Connection connection = this . openConnection()) {
142- connection. createQuery(" SELECT ..." ). executeUpdate();
143- }
144118
145- // if you need disable auto commit, use beginTransaction() method
146- try (Connection connection = this . beginTransaction()) {
147- connection. createQuery(" SELECT ..." ). executeUpdate();
119+ try (Handle handle = this . getHandle()) {
120+ handle. createUpdate(" ..." )
121+ .bind(" var1" , " data1" )
122+ .bind(" var2" , " data2" )
123+ .execute();
148124 }
149125 }
150126}
151127```
152128
153- After that, you can easily do what you want with your [ * Sql2o * ] ( https ://www.sql2o. org) connections :
129+ After that, you can easily do what you want with your [ * Jdbi * ] ( http ://jdbi. org/ ) handles :
154130
155131``` java
156132/* import your database class */
157133
158134public class Main {
159135
160136 public static void main (String [] args ) {
161- MyDatabase db = new MyDatabase ();
137+ MyDatabase database = new MyDatabase ();
162138
163- try (Connection connection = db. openConnection()) {
164- connection. createQuery(" SELECT ..." );
139+ try (Handle handle = database. getHandle()) {
140+ handle. createUpdate(" ..." )
141+ .bind(" var1" , " data1" )
142+ .bind(" var2" , " data2" )
143+ .execute();
165144 }
166-
167- // also you can execute your db scheme with
168- db. executeScheme(" CREATE TABLE IF NOT EXISTS ..." );
169145 }
170146}
171- ```
147+ ```
148+
149+ ## Libraries
150+
151+ [ ** PowerNukkitX** ] ( https://github.com/PowerNukkitX/PowerNukkitX ) is a branch version based on PowerNukkit,
152+ developed and maintained by PowerNukkitX.
153+
154+ [ ** MariaDB Connector** ] ( https://github.com/mariadb-corporation/mariadb-connector-j ) MariaDB Connector/J is a Type 4 JDBC
155+ driver. It was developed specifically as a lightweight JDBC connector for use with MariaDB and MySQL database servers.
156+
157+ [ ** Jdbi** ] ( https://github.com/jdbi/jdbi ) The Jdbi library provides convenient, idiomatic access to relational databases
158+ in Java.
159+
160+ [ ** HikariCP** ] ( https://github.com/brettwooldridge/HikariCP ) is a "zero-overhead" production ready JDBC connection pool.
161+ At roughly 130Kb, the library is very light.
162+
163+ ## License
164+
165+ This project is licensed under the [ MIT License] ( https://opensource.org/licenses/MIT )
0 commit comments