Skip to content

Commit

Permalink
Refactor result conversion and metadata properties
Browse files Browse the repository at this point in the history
Updated function names from `toKotlinResult` to `toResult` to enhance clarity and consistency across the codebase. Refactored `name` and `type` properties in `Column` class to use `by lazy` for improved performance and readability.
  • Loading branch information
smyrgeorge committed Nov 3, 2024
1 parent cfc3e4c commit 236a7f3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class MySQL(

override suspend fun fetchAll(sql: String): Result<ResultSet> {
val res = sqlx { c -> sqlx4k_fetch_all(sql, c, Driver.fn) }
return ResultSet(res).toKotlinResult()
return ResultSet(res).toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down Expand Up @@ -115,7 +115,7 @@ class MySQL(
}

tx = res.getRaw().tx!!
return res.toKotlinResult()
return res.toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PostgreSQL(

override suspend fun fetchAll(sql: String): Result<ResultSet> {
val res = sqlx { c -> sqlx4k_fetch_all(sql, c, Driver.fn) }
return ResultSet(res).toKotlinResult()
return ResultSet(res).toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down Expand Up @@ -172,7 +172,7 @@ class PostgreSQL(
}

tx = res.getRaw().tx!!
return res.toKotlinResult()
return res.toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SQLite(

override suspend fun fetchAll(sql: String): Result<ResultSet> {
val res = sqlx { c -> sqlx4k_fetch_all(sql, c, Driver.fn) }
return ResultSet(res).toKotlinResult()
return ResultSet(res).toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down Expand Up @@ -107,7 +107,7 @@ class SQLite(
}

tx = res.getRaw().tx!!
return res.toKotlinResult()
return res.toResult()
}

override suspend fun fetchAll(statement: Statement): Result<ResultSet> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ResultSet(
* @return A successful [Result] containing the current [ResultSet] if no error,
* or a failed [Result] with the appropriate [SQLError].
*/
fun toKotlinResult(): Result<ResultSet> =
fun toResult(): Result<ResultSet> =
if (isError()) {
val error = toError()
close()
Expand Down Expand Up @@ -166,7 +166,7 @@ class ResultSet(
* This property provides access to the name of the column
* as defined in the metadata, based on the column's ordinal index.
*/
val name: String get() = metadata.getColumn(ordinal).name
val name: String by lazy { metadata.getColumn(ordinal).name }

/**
* Retrieves the ordinal position of this column within the database table.
Expand All @@ -184,7 +184,7 @@ class ResultSet(
*
* @return The type of the column in String format.
*/
val type: String get() = metadata.getColumn(ordinal).type
val type: String by lazy { metadata.getColumn(ordinal).type }

/**
* Retrieves the value of the column as a nullable String.
Expand Down

0 comments on commit 236a7f3

Please sign in to comment.