DbLib

DbLib 1.0.1

Compatible API Versions
1.0.0
Sourcecode
https://github.com/Nukkit-coders/DbLib
Contributors
Fromgate, SupremeMortal
DbLib is a library, that bundles database drivers for simple use with your plugin.

Features
Provides access to popular database engines: SQLite and MySQL;
Includes popular library ORMLite, that provides access to database without using SQL-queries;
Organizes universal data storage for all plugins, that uses DbLib. Server owner must configure DbLib once and all plugins that use DbLib will work fine!

How to use plugin (Server owners must read this)
If any plugin requires a DbLib you just need to download and install it. Usually, it will be enough. But if you going to use to MySQL or another SQLite file you need to configure plugin (Read at Config section)

Note for plugin developers
ORMLite is popular engine, that provides access to databases using ORM technique. Practically it means that you can read and save data into the database without writing SQL-queries.

DbLib also includes database drivers:
SQLite driver
MySQL driver
If you would not like to use ORMLite, you can use MySQL (or SQLite) drivers as usually, using JDBC provided by Java.

How to connect to universal DbLib storage

DbLib suggests using universal database (by default it is a file nukkit.db, located in server folder or MySQL database defined by the user) for all plugins. If DbLib installed on the server you don't need to think about database drivers, URLs, names and passwords.

Here is example of creating new table (check API section for more info):

Maven Dependency
XML:
   <repositories>
       <repository>
           <id>nukkit-repo</id>
           <url>https://repo.nukkitx.com/snapshot</url>
       </repository>
   </repositories>

   <dependencies>
       <dependency>
           <groupId>ru.nukkit.dblib</groupId>
           <artifactId>DbLib</artifactId>
           <version>1.0-SNAPSHOT</version>
           <scope>provided</scope>
       </dependency>
   </dependencies>

Example:
Java:
  public boolean connectToDbLib(){
if (this.getServer().getPluginManager().getPlugin("DbLib") == null){
this.getLogger().info(TextFormat.RED+"DbLib plugin not found");
return false;
}
connectionSource = DbLib.getConnectionSource();
if (connectionSource == null) return false;
try {
passDao =  DaoManager.createDao(connectionSource, PasswordsTable.class);
TableUtils.createTableIfNotExists(connectionSource, PasswordsTable.class);
} catch (Exception e) {
return false;
}
return true;
}

But if you going to use any other database you must use this method:

Code:
DbLib.getConnectionSoruce(String url, String userName, String password)
Author
SupremeMortal
Downloads
13,581
Views
13,581
First release
Last update
Rating
5.00 star(s) 1 ratings

More resources from SupremeMortal

Latest updates

  1. Fix SQLite database locking.

    Concurrently using an SQLite database with ORMLite would cause lock SQLExceptions because SQLite...
  2. 0.2.5

    Update libraries.
  3. DBLib 0.2.4

    New Features: - Added English language

Latest reviews

Works perfect.
Top