-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
227 additions
and
121 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
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
47 changes: 47 additions & 0 deletions
47
sqiffy/src/main/kotlin/com/dzikoysk/sqiffy/dsl/DslHandle.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,47 @@ | ||
package com.dzikoysk.sqiffy.dsl | ||
|
||
import com.dzikoysk.sqiffy.SqiffyDatabase | ||
import com.dzikoysk.sqiffy.dsl.statements.AutogeneratedKeyInsertStatement | ||
import com.dzikoysk.sqiffy.dsl.statements.DeleteStatement | ||
import com.dzikoysk.sqiffy.dsl.statements.InsertStatement | ||
import com.dzikoysk.sqiffy.dsl.statements.SelectStatement | ||
import com.dzikoysk.sqiffy.dsl.statements.UpdateStatement | ||
import com.dzikoysk.sqiffy.dsl.statements.UpdateValues | ||
import com.dzikoysk.sqiffy.transaction.HandleAccessor | ||
import org.jdbi.v3.core.Handle | ||
|
||
abstract class DslHandle { | ||
|
||
abstract fun getDatabase(): SqiffyDatabase | ||
|
||
abstract fun getHandleAccessor(): HandleAccessor | ||
|
||
fun select(table: Table): SelectStatement = | ||
SelectStatement(getDatabase(), getHandleAccessor(), table) | ||
|
||
fun insert(table: TableWithAutogeneratedKey, values: (Values) -> Unit): AutogeneratedKeyInsertStatement = | ||
AutogeneratedKeyInsertStatement(getDatabase(), getHandleAccessor(), table, Values().also { values.invoke(it) }) | ||
|
||
fun insert(table: Table, values: (Values) -> Unit): InsertStatement = | ||
InsertStatement(getDatabase(), getHandleAccessor(), table, Values().also { values.invoke(it) }) | ||
|
||
fun update(table: Table, values: (UpdateValues) -> Unit): UpdateStatement = | ||
UpdateStatement(getDatabase(), getHandleAccessor(), table, UpdateValues().also { values.invoke(it) }) | ||
|
||
fun delete(table: Table): DeleteStatement = | ||
DeleteStatement(getDatabase(), getHandleAccessor(), table) | ||
|
||
} | ||
|
||
class JdbiDslHandle(private val database: SqiffyDatabase, private val handle: Handle) : DslHandle(), HandleAccessor { | ||
|
||
override fun <R> inHandle(body: (Handle) -> R): R = | ||
body.invoke(handle) | ||
|
||
override fun getHandleAccessor(): HandleAccessor = | ||
this | ||
|
||
override fun getDatabase(): SqiffyDatabase = | ||
database | ||
|
||
} |
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
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
Oops, something went wrong.