Skip to content
This repository has been archived by the owner on May 31, 2022. It is now read-only.
/ DbLibX Public archive

NukkitX Database Dependency with Kotlin Coroutine.

License

Notifications You must be signed in to change notification settings

WetABQ/DbLibX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DbLibX

NukkitX Database Dependency with Kotlin Coroutine.

  • DbLibX base on the Kotlin Coroutine auto async control database.
  • DbLibX base on the Alibaba Druid Connection Pool
  • DbLibX has friendly interface for developer.
  • Main interface:
    createAction<R>(sql: kotlin.String, vararg args: kotlin.Any,
     noinline action: suspend (java.sql.PreparedStatement) -> R)
    • Example 1:
    val insertAction = 
      createAction<Int>( // Kotlin can infer class type, you can ignore the INT type
              "INSERT INTO wacban (player, violationId, violationDuration, 
              violationType, checkType, time, extra)
              VALUES (?, ?, ?, ? ,? ,?, ?)", // SQL statement
              player, // arg 1
              violationData.violationId, // arg 2
              violationData.violationDuration, // args...
              violationData.violationType.toString(),
              violationData.getCheckType().getName(),
              violationData.time,
              violationData.extra) {
                  it.executeUpdate() // The action you want to execute
              }
      insertAction.doAction() // Return action status
    • Example 2:
    val cacheHelperDataAction = 
      createAction("select * from wachelper") { // Construct database action
          val rs = it.executeQuery() // execute query
          val result = ArrayList<String>()
          while (rs.next()) result.add(rs.getString("player")) // get data
          result // return data
      }
      cacheBanDataAction.doAction() // execute action and get return data