Guest User

Untitled

a guest
Jul 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. package network
  2.  
  3. import org.jetbrains.exposed.sql.*
  4. import org.jetbrains.exposed.sql.transactions.transaction
  5. import java.beans.Encoder
  6. import javax.crypto.EncryptedPrivateKeyInfo
  7.  
  8. object Accounts : Table() {
  9.  
  10. val id = integer("id").autoIncrement().primaryKey() // Column<Int>
  11. val username = varchar("username", 255) // Column<String>
  12. var password = varchar("password", 255) // Column<String>
  13. }
  14.  
  15. object DbHandler {
  16.  
  17. private const val url = "jdbc:mysql://root:root@localhost:3306/game?autoReconnect=true&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC"
  18. private const val driver = "com.mysql.cj.jdbc.Driver"
  19. private val connect = Database.connect(url, driver)
  20.  
  21. fun createAccount(username: String, password: String) {
  22.  
  23. transaction {
  24. if (Accounts.selectAll().any { it[Accounts.username] == username }) {
  25. // Username already exist
  26. } else {
  27. Accounts.insert {
  28. it[Accounts.username] = username
  29. it[Accounts.password] = password
  30. }
  31. }
  32. }
  33.  
  34. }
  35.  
  36. fun deleteAccount(username : String) {
  37. transaction {
  38. Accounts.deleteWhere { Accounts.username.eq(username) }
  39. }
  40. }
  41.  
  42.  
  43.  
  44. fun test() {
  45.  
  46. }
  47.  
  48.  
  49. }
Add Comment
Please, Sign In to add comment