This project is a library for working with databases.
It supports MariaDB, MySQL, PostgreSQL, H2SQL, SQLite, MongoDB and Redis.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Mischmaschine</groupId>
<artifactId>DatabaseLib</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
repositories {
maven { url = 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.Mischmaschine:DatabaseLib:master-SNAPSHOT'
}
Step 1. Add the repository
repositories {
maven("https://jitpack.io")
}
Step 2. Add the dependency
dependencies {
implementation("com.github.Mischmaschine:DatabaseLib:master-SNAPSHOT")
}
import de.mischmaschine.database.configuration.Configuration
Configuration("host", port, "username", "password", AbstractRedis::class)
import de.mischmaschine.database.configuration.Configuration;
new Configuration("host", port, "username", "password", AbstractRedis.class);
import de.mischmaschine.database.redis.AbstractRedis;
//Create a class which extends AbstractRedis
class Redis : AbstractRedis(database = 0, ssl = false, logging = true)
//Go to your main class and create an instance of your database class
main {
//Create an instance of your class
//This will automatically connect to the database
val redis = Redis()
//Do something with the database
with(redis) {
//Set a value in the database with the key "key" and the value "value"
//Returns a FutureAction out of a Unit (void) type to check when the action is completed
updateKeyAsync("key", "value")
//Get the value of the key "key"
//This will return a FutureAction which will be completed with the value.
//Use .onSuccess to get the value if present
//Use .onFailure to get the exception if present
getValueAsync("key")
}
//Disconnect from the database
redis.shutdown()
}
import de.mischmaschine.database.redis.AbstractRedis;
//Create a class which extends AbstractRedis
public class Redis extends AbstractRedis {
public Redis(){
super(0, false, true);
}
}
public class Main {
public static void main(String[] args) {
//Create an instance of your class
//This will automatically connect to the database
Redis redis = new Redis();
//Set a value in the database with the key "key" and the value "value"
//Returns a FutureAction out of a Unit (void) type to check when the action is completed
redis.updateKeyAsync("key", "value");
//Get the value of the key "key"
//This will return a FutureAction which will be completed with the value.
//Use .onSuccess to get the value if present
//Use .onFailure to get the exception if present
redis.getValueAsync("key");
redis.shutdown();
}
}
This is an example for Redis. You can use the process for all other databases like AbstractMongoDB.
import de.mischmaschine.database.redis.AbstractRedis
main {
val redis = ...
redis.subscribe("channel") { channel, message ->
//In this case, the message would be "Hello World"
println("Received message: $message")
}
//This will publish to the channel "channel" the message "Hello World!"
redis.publish("channel", "Hello World!")
//If you no longer want to subscribe to the channel "channel", you can unsubscribe
redis.unsubscribe("channel")
//Shutdown this client and close all open connections once this method is called. Once all connections are closed, the associated ClientResources are shut down/released gracefully considering quiet time and the shutdown timeout
redis.shutdown()
}
Please feel free to fork this project and make a pull request.
This project is licensed under the LGPL-2.1 license.
$ git describe --tags --always
$ git log --oneline --decorate --graph --all --color=always
$ git shortlog -sn --all