Skip to content

Commit

Permalink
Fixed inline call and added query selector
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Aug 6, 2022
1 parent 6e80c2e commit d72012d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ object DatabaseApi {
* @return null or T
*/
suspend fun createUserTable() = catching {
SQLDatabase.createTable(User::class.java)
SQLDatabase.createTable<User>()
}

suspend fun createRatingTable() = catching {
SQLDatabase.createTable(RatingRelation::class.java)
SQLDatabase.createTable<RatingRelation>()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ abstract class DatabaseCore() {
inline fun <reified T> select(where: String = "") = select(T::class.java, where)
inline fun <reified T> insert(instance: T) = insert(T::class.java, instance)
inline fun <reified T> createTable() = createTable(T::class.java)
inline fun <reified T> querySelect(query: String, noinline rsBuilder: (ResultSet) -> T?) =
querySelect(T::class.java, query, rsBuilder)
fun <T> update(clazz: Class<out T>, instance: T): Boolean? {
val info = AnnotationUtils.EntityInfo.create(clazz, instance)
val primaryKeyInfo =
Expand Down Expand Up @@ -64,6 +66,14 @@ abstract class DatabaseCore() {
}



fun <T> querySelect(clazz: Class<out T>, query: String = "", rsBuilder: (ResultSet) -> T?): List<T>? {
return connection?.createStatement()?.executeQuery(query)?.mapNotNull { rs ->
rsBuilder.invoke(rs)
}
}


fun <T> insert(clazz: Class<out T>, instance: T): Long? {
val info = AnnotationUtils.EntityInfo.create(clazz, instance)
val keys = info?.columns?.mapNotNull {
Expand Down

0 comments on commit d72012d

Please sign in to comment.