@@ -10,17 +10,33 @@ private val config: DatabaseConfig = DatabaseConfig {
10
10
defaultMaxAttempts = 5
11
11
}
12
12
13
+ /* *
14
+ * The [DBConfig] instance.
15
+ */
13
16
var dbConfig: DBConfig = DBConfig (" " , " " , " " )
14
17
18
+ /* *
19
+ * The MariaDB configuration.
20
+ * @param url The URl to the database.
21
+ * @param username The username into the database.
22
+ * @param password The password into the database.
23
+ */
15
24
data class DBConfig (
16
25
val url : String ,
17
26
val username : String ,
18
27
val password : String
19
28
)
20
29
30
+ /* *
31
+ * Represents the database connection.
32
+ */
21
33
lateinit var database: Database
22
34
private set
23
35
36
+ /* *
37
+ * Attempts to connect to the database.
38
+ * @return The new [database] value
39
+ */
24
40
fun connect (): Database {
25
41
database = Database .connect(
26
42
url = dbConfig.url,
@@ -32,6 +48,12 @@ fun connect(): Database {
32
48
return database
33
49
}
34
50
51
+ /* *
52
+ * Adds a user to the database.
53
+ * @param username The username of the jenkins user
54
+ * @param discord The Discord ID of the jenkins user
55
+ * @return The result of the `INSERT` statement.
56
+ */
35
57
fun addUser (
36
58
username : String ,
37
59
discord : Long
@@ -44,6 +66,11 @@ fun addUser(
44
66
}
45
67
}
46
68
69
+ /* *
70
+ * Gets a [User] by its jenkins username.
71
+ * @param username The username to lookup
72
+ * @return The user mapped to the jenkins username, or `null` if not found
73
+ */
47
74
fun getUser (
48
75
username : String
49
76
): User ? = transaction(database) {
@@ -52,11 +79,21 @@ fun getUser(
52
79
.firstOrNull()
53
80
}
54
81
82
+ /* *
83
+ * Gets all users currently linked in the database.
84
+ * @return All users in the database
85
+ */
55
86
fun getAllUsers (): List <User > = transaction(database) {
56
87
Users .selectAll()
57
88
.map { row -> User (row[Users .username], row[Users .discord]) }
58
89
}
59
90
91
+ /* *
92
+ * Updates the user linked in the database.
93
+ * @param username The jenkins user to update
94
+ * @param discord The new Discord ID mapped to the user
95
+ * @return `1` if updated, else `0`
96
+ */
60
97
fun updateUser (
61
98
username : String ,
62
99
discord : Long
@@ -66,12 +103,21 @@ fun updateUser(
66
103
}
67
104
}
68
105
106
+ /* *
107
+ * Removes a user from the database.
108
+ * @param username The jenkins user to remove
109
+ * @return `1` if removed, else `0`
110
+ */
69
111
fun removeUser (
70
112
username : String
71
113
) = transaction(database) {
72
114
Users .deleteWhere { Users .username eq username }
73
115
}
74
116
117
+ /* *
118
+ * Removes all users from the database.
119
+ * @return The count of deleted members
120
+ */
75
121
fun removeAllUsers () = transaction(database) {
76
122
Users .deleteAll()
77
123
}
0 commit comments