-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(exposed): add layer extensions & DbManager
- Loading branch information
1 parent
40c0467
commit dae24f0
Showing
5 changed files
with
112 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
kraftx/exposed/src/main/kotlin/sh/illumi/kraft/x/exposed/dsl/ConfigureDsl.kt
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
kraftx/exposed/src/main/kotlin/sh/illumi/kraft/x/exposed/dsl/config.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package sh.illumi.kraft.x.exposed.dsl | ||
|
||
open class ExposedConfigurationDsl { | ||
var jdbcUrl: String = "" | ||
var driverClassName: String = "" | ||
var username: String = "" | ||
var password: String = "" | ||
|
||
open fun check() { | ||
require(jdbcUrl.isNotBlank()) { "jdbcUrl must be set" } | ||
require(driverClassName.isNotBlank()) { "driverClassName must be set" } | ||
require(username.isNotBlank()) { "username must be set" } | ||
require(password.isNotBlank()) { "password must be set" } | ||
} | ||
|
||
class Hikari : ExposedConfigurationDsl() { | ||
lateinit var hikari: ExposedHikariConfigurationDsl | ||
|
||
fun hikari(block: ExposedHikariConfigurationDsl.() -> Unit) { | ||
hikari = ExposedHikariConfigurationDsl().apply(block) | ||
} | ||
|
||
override fun check() { | ||
super.check() | ||
hikari.check() | ||
} | ||
} | ||
} | ||
|
||
class ExposedHikariConfigurationDsl { | ||
var maximumPoolSize = 10 | ||
var isReadOnly = false | ||
var transactionIsolationLevel: String? = null | ||
|
||
fun check() { | ||
require(maximumPoolSize > 0) { "maximumPoolSize must be greater than 0" } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
kraftx/exposed/src/main/kotlin/sh/illumi/kraft/x/exposed/extensions/layer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package sh.illumi.kraft.x.exposed.extensions | ||
|
||
import sh.illumi.kraft.layer.RootLayer | ||
import sh.illumi.kraft.x.exposed.DbManager | ||
import sh.illumi.kraft.x.exposed.dsl.ExposedConfigurationDsl | ||
import sh.illumi.kraft.x.exposed.layer.LayerWithExposed | ||
|
||
fun <TLayer> TLayer.createExposedHikari(configure: ExposedConfigurationDsl.Hikari.() -> Unit) | ||
where | ||
TLayer : RootLayer, | ||
TLayer : LayerWithExposed | ||
= DbManager.Hikari(this, configure) | ||
|
||
|
||
fun <TLayer> TLayer.createExposedSingle(configure: ExposedConfigurationDsl.() -> Unit) | ||
where | ||
TLayer : RootLayer, | ||
TLayer : LayerWithExposed | ||
= DbManager.Single(this, configure) |
7 changes: 7 additions & 0 deletions
7
kraftx/exposed/src/main/kotlin/sh/illumi/kraft/x/exposed/layer/LayerWithExposed.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package sh.illumi.kraft.x.exposed.layer | ||
|
||
import sh.illumi.kraft.x.exposed.DbManager | ||
|
||
interface LayerWithExposed { | ||
val db: DbManager | ||
} |