@@ -15,7 +15,7 @@ import java.sql.ResultSet
15
15
import java.sql.SQLException
16
16
17
17
/* *
18
- * Execute a SQL query and map the results to a Flow of instances of the specified class.
18
+ * Execute a SQL queryAsFlow and map the results to a Flow of instances of the specified class.
19
19
*
20
20
* This function uses reflection to automatically map the result set columns to the properties of the specified class.
21
21
* For advanced mappings, use the overloaded version with a custom `mapper` function.
@@ -26,7 +26,7 @@ import java.sql.SQLException
26
26
* data class User(val id: Int, val name: String)
27
27
*
28
28
* // Fetch all users where "active" is true
29
- * val users: Flow<User> = connection.query (
29
+ * val users: Flow<User> = connection.queryAsFlow (
30
30
* sql = "SELECT id, name FROM users WHERE active = :active",
31
31
* "active" to true
32
32
* )
@@ -35,27 +35,27 @@ import java.sql.SQLException
35
35
* users.collect { println(it) }
36
36
* ```
37
37
*
38
- * @param sql The SQL query to execute.
39
- * @param args Optional key-value pairs representing named parameters to substitute into the query .
40
- * @return The query result as a [Flow] of [T] instances.
38
+ * @param sql The SQL queryAsFlow to execute.
39
+ * @param args Optional key-value pairs representing named parameters to substitute into the queryAsFlow .
40
+ * @return The queryAsFlow result as a [Flow] of [T] instances.
41
41
* @throws java.sql.SQLException If there's a database error.
42
42
*/
43
- inline fun <reified T : Any > Connection.query (
43
+ inline fun <reified T : Any > Connection.queryAsFlow (
44
44
sql : String ,
45
45
vararg args : Pair <String , Any ?>,
46
46
): Flow <T > =
47
- query (
47
+ queryAsFlow (
48
48
sql,
49
49
createMapper(T ::class .java)::createInstance,
50
50
* args,
51
51
)
52
52
53
53
/* *
54
- * Execute a SQL query and map the results to a Flow of instances of the specified class with a custom mapper.
54
+ * Execute a SQL queryAsFlow and map the results to a Flow of instances of the specified class with a custom mapper.
55
55
*
56
56
* **Example**:
57
57
* ```kotlin
58
- * val users: Flow<User> = connection.query (
58
+ * val users: Flow<User> = connection.queryAsFlow (
59
59
* sql = "SELECT id, name FROM users",
60
60
* mapper = { resultSet, _ ->
61
61
* User(
@@ -67,18 +67,18 @@ inline fun <reified T : Any> Connection.query(
67
67
* users.collect { println(it) }
68
68
* ```
69
69
*
70
- * @param sql The SQL query to execute.
70
+ * @param sql The SQL queryAsFlow to execute.
71
71
* @param mapper Custom mapping function to transform the [ResultSet] into the target class.
72
- * @param args Optional parameters to be substituted in the SQL query during execution.
73
- * @return The query result as a [Flow] of [T] instances.
72
+ * @param args Optional parameters to be substituted in the SQL queryAsFlow during execution.
73
+ * @return The queryAsFlow result as a [Flow] of [T] instances.
74
74
* @throws KapperQueryException If there's a database error.
75
75
*/
76
- inline fun <reified T : Any > Connection.query (
76
+ inline fun <reified T : Any > Connection.queryAsFlow (
77
77
sql : String ,
78
78
noinline mapper : (ResultSet , Map <String , Field >) -> T ,
79
79
vararg args : Pair <String , Any ?>,
80
80
): Flow <T > {
81
- require(sql.isNotBlank()) { " SQL query cannot be empty or blank" }
81
+ require(sql.isNotBlank()) { " SQL queryAsFlow cannot be empty or blank" }
82
82
this .executeQuery(Query (sql), args.toMap()).let { rs ->
83
83
return queryFlow(rs, mapper, sql)
84
84
}
@@ -102,7 +102,7 @@ fun <T : Any> queryFlow(
102
102
logger.info(" Query results processing cancelled: ${e.message} " )
103
103
throw e
104
104
} catch (e: SQLException ) {
105
- " Error executing query : $sql " .also {
105
+ " Error executing queryAsFlow : $sql " .also {
106
106
logger.warn(it, e)
107
107
throw KapperQueryException (it, e)
108
108
}
0 commit comments