Skip to content

KDatabases/Kuery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kuery

MySQL Kotlin wrapper based on HikariCP

How to get it!

Maven

<dependency>
    <groupId>com.sxtanna.database</groupId>
    <artifactId>Kuery</artifactId>
    <version>LATEST</version>
</dependency>

Gradle

compile "com.sxtanna.database:Kuery:+"

How it works!

1-0. To create a new instance of Kuery, you would follow this syntax

From Kotlin

val kuery = Kuery[file: File]
val kuery = Kuery[config: KueryConfig]

From Java

final Kuery kuery = Kuery.get(file: File);
final Kuery kuery = Kuery.get(config: KueryConfig);

1-1. To initialize and shutdown a database use these two methods

kuery.enable()

and

kuery.disable()

2-0. After you have an instance, to get a resource

From Kotlin

val resource = kuery.resource()

From Java

final Connection resource = kuery.resource();

Database#resource will throw an IllegalStateException if it's unable to into a resource a/o the database isn't enabled

2-1. Or you could utilize the Database's ability to automatically manage the connection with various sql functions

Creating a Table

From Kotlin
kuery {
  create("User", "name" co VarChar.of(255, true)) // deprecated in favour of the cacheable builders
ex.
  Create.table("User").co("name", VarChar(255, true))()
}                                                                                                                                           
From Java
kuery.execute(task -> {                                                                  
  task.execute(Create.table("User").co("name", new VarChar(255, true)));
});                                                                                    
Storing a Create Statement (syntax is nearly the same for Kotlin and Java)
val createUser = Create.table("User").co("name", VarChar.of(255, true))

vs 

final CreateBuilder createUser = Create.table("User").co("name", VarChar.of(255, true));

Using them however is quite different

From Kotlin
kuery {
  createUser()
}
From Java
kuery.execute(task -> {
  task.execute(createUser);
});

More examples soon.

For Java examples.

For Kotlin examples.