ORK is a small project aiming to utilizing Kotlin dataclasses to use as ORM System
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.github.CoasterFreakDE:ork:0.7-SNAPSHOT'
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.CoasterFreakDE</groupId>
<artifactId>ork</artifactId>
<version>0.7-SNAPSHOT</version>
</dependency>
- Connect to jdbc url
- Create Tables from DataClass
- Save (INSERT OR UPDATE) DataClasses directly to your database with
.save()
- Delete Data with
.delete()
- Select Data from database
- References (Foreign Keys)
- Move the PrimaryKey Annotation directly to the field
Connecting to your database is easy. Just add your credentials in a "connect" block at the start of your app.
To use sqlite just use driver { "sqlite" }
and host { "your.db" }
connect {
host { "localhost" }
port { 3306 }
driver { "mariadb" } // Supported: mysql, mariadb, sqlite
database { "database" }
username { "root" }
password { "1234" }
autoReconnect { true }
}
To create a table there are two steps you need to follow.
A Tableclass consists of 3 different parts.
- Implementing the interface
ITable
- At least one PrimaryKey
- FieldNames
@PrimaryKey("name", "gamegroup")
data class MyTable(
@FieldName("name")
val name: String = "Peter",
@FieldName("gamegroup")
val gamegroup: String = "Orks",
@FieldName("xp")
val xp: Int = 0,
) : ITable
This is as simple as putting butter on bread.
You can add all your tables into a single statement by separating them with a ,
createTable(MyTable::class.java)
Now here comes the fun part. As you will use these functions most of the time they need to be super simple.
val myDataToSave = MyTable("Hulk")
myDataToSave.save() // Insert or update data to the database
myDataToSave.delete() // Delete data from the database
Feel free to leave a pull request or ticket for feature requests.
Try to cover as much as possible with tests. Check here