#209 - Provide extensions on TypedExecuteSpec and GenericExecuteSpec.
The original extensions did not allow for executing fetch operations because they where on BindSpec. Original pull request: #210.
This commit is contained in:
committed by
Mark Paluch
parent
6667f7a230
commit
bd2cc60480
@@ -31,17 +31,37 @@ suspend fun DatabaseClient.GenericExecuteSpec.await() {
|
||||
* Extension for [DatabaseClient.BindSpec.bind] providing a variant leveraging reified type parameters
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Ibanga Enoobong Ime
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> DatabaseClient.BindSpec<*>.bind(index: Int, value: T?) = bind(index, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
inline fun <reified T : Any> DatabaseClient.TypedExecuteSpec<*>.bind(index: Int, value: T?) = bind(index, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
|
||||
/**
|
||||
* Extension for [DatabaseClient.BindSpec.bind] providing a variant leveraging reified type parameters
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Ibanga Enoobong Ime
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> DatabaseClient.BindSpec<*>.bind(name: String, value: T?) = bind(name, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
inline fun <reified T : Any> DatabaseClient.GenericExecuteSpec.bind(index: Int, value: T?) = bind(index, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
|
||||
/**
|
||||
* Extension for [DatabaseClient.BindSpec.bind] providing a variant leveraging reified type parameters
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Ibanga Enoobong Ime
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> DatabaseClient.TypedExecuteSpec<*>.bind(name: String, value: T?) = bind(name, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
|
||||
/**
|
||||
* Extension for [DatabaseClient.BindSpec.bind] providing a variant leveraging reified type parameters
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Ibanga Enoobong Ime
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> DatabaseClient.GenericExecuteSpec.bind(name: String, value: T?) = bind(name, SettableValue.fromOrEmpty(value, T::class.java))
|
||||
|
||||
/**
|
||||
* Extension for [DatabaseClient.GenericExecuteSpec. as] providing a
|
||||
|
||||
@@ -48,6 +48,21 @@ class DatabaseClientExtensionsTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-209
|
||||
fun typedExecuteSpecBindByIndexShouldBindValue() {
|
||||
|
||||
val spec = mockk<DatabaseClient.TypedExecuteSpec<String>>()
|
||||
every { spec.bind(eq(0), any()) } returns spec
|
||||
|
||||
runBlocking {
|
||||
spec.bind<String>(0, "foo")
|
||||
}
|
||||
|
||||
verify {
|
||||
spec.bind(0, SettableValue.fromOrEmpty("foo", String::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-162
|
||||
fun bindByIndexShouldBindNull() {
|
||||
|
||||
@@ -63,6 +78,21 @@ class DatabaseClientExtensionsTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-209
|
||||
fun typedExecuteSpecBindByIndexShouldBindNull() {
|
||||
|
||||
val spec = mockk<DatabaseClient.TypedExecuteSpec<String>>()
|
||||
every { spec.bind(eq(0), any()) } returns spec
|
||||
|
||||
runBlocking {
|
||||
spec.bind<String>(0, null)
|
||||
}
|
||||
|
||||
verify {
|
||||
spec.bind(0, SettableValue.empty(String::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-162
|
||||
fun bindByNameShouldBindValue() {
|
||||
|
||||
@@ -78,6 +108,21 @@ class DatabaseClientExtensionsTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-162
|
||||
fun typedExecuteSpecBindByNameShouldBindValue() {
|
||||
|
||||
val spec = mockk<DatabaseClient.TypedExecuteSpec<String>>()
|
||||
every { spec.bind(eq("field"), any()) } returns spec
|
||||
|
||||
runBlocking {
|
||||
spec.bind<String>("field", "foo")
|
||||
}
|
||||
|
||||
verify {
|
||||
spec.bind("field", SettableValue.fromOrEmpty("foo", String::class.java))
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-162
|
||||
fun bindByNameShouldBindNull() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user