Skip to content

Commit

Permalink
Added command to list all users in the database NOTE: Whoever uses th…
Browse files Browse the repository at this point in the history
…is build WILL HAVE TO COMPILE IT YOURSELF THIS IS BEACUSE I HAVE TEMPORARILY SETTED THE MYSQL DATA IN CODE!
  • Loading branch information
TheCGuyGitHub committed Jul 1, 2024
1 parent 93573c2 commit 9081059
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,13 @@ class CloudNet_Rest_Module : DriverModule() {


fun sqlwr(sql: String) {
println("DEBUG:")
println(host)
println(port)
println(database)
println(password)




val host = "192.168.0.226"
val port = 3306
val database = "cloudnet_rest"
val username = "cloudnet"
val password = "cloudnet"


val CONNECT_URL_FORMAT: String = "jdbc:mysql://%s:%d/%s?serverTimezone=UTC"

val config = HikariConfig()

config.jdbcUrl = String.format(
CONNECT_URL_FORMAT,
host, port, database
Expand All @@ -144,23 +131,17 @@ class CloudNet_Rest_Module : DriverModule() {
config.addDataSourceProperty("cachePrepStmts", "true")
config.addDataSourceProperty("prepStmtCacheSize", "250")
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048")


val ds = HikariDataSource(config)
//println(ds)
ds.connection.use { connection ->
println("DEBUG SYM1 $sql")
connection.prepareStatement("SELECT * FROM cloudnet_rest_users").use { statement ->
println("DEBUG SYM2")
connection.prepareStatement("SELECT user FROM cloudnet_rest_users").use { statement ->
statement.executeQuery().use { resultSet ->
println("DEBUG SYM3")
if (resultSet.next()) {
println("Query Result: ${resultSet}")
while (resultSet.next()) {
val user = resultSet.getString("user")
}
ds.close()
}
}
}
ds.close()
}

@ModuleTask(order = 127, lifecycle = ModuleLifeCycle.STARTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,36 @@ class rest {
fun users(
source: CommandSource,
) {


println("ich binrunned")
val sql = CloudNet_Rest_Module()
println("so far so good")
sql.sqlwr("SELECT * FROM cloudnet_rest_users")
println("how the fuk")

val host = "127.0.0.1"
val port = 3306
val database = "cloudnet_rest"
val username = "cloudnet"
val password = "cloudnet"
val CONNECT_URL_FORMAT: String = "jdbc:mysql://%s:%d/%s?serverTimezone=UTC"
val config = HikariConfig()
config.jdbcUrl = String.format(
CONNECT_URL_FORMAT,
host, port, database
)
config.username = username
config.password = password
config.driverClassName = "com.mysql.cj.jdbc.Driver"
config.addDataSourceProperty("cachePrepStmts", "true")
config.addDataSourceProperty("prepStmtCacheSize", "250")
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048")
val ds = HikariDataSource(config)
ds.connection.use { connection ->
connection.prepareStatement("SELECT user FROM cloudnet_rest_users").use { statement ->
statement.executeQuery().use { resultSet ->
source.sendMessage("Current registered RestAPI users:")
while (resultSet.next()) {
val user = resultSet.getString("user")
source.sendMessage(user)
}
}
}
}
ds.close()
}


Expand Down

0 comments on commit 9081059

Please sign in to comment.