Skip to content

Commit cb6e18b

Browse files
committed
Add Table Exists Check
1 parent 321d245 commit cb6e18b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/main/kotlin/io/codemc/api/database/database.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ fun addUser(
8080
fun getUser(
8181
username: String
8282
): User? = transaction(database) {
83+
if (!Users.exists()) return@transaction null
84+
8385
Users.selectAll().where { Users.username eq username }
8486
.map { row -> User(row[Users.username], row[Users.discord]) }
8587
.firstOrNull()
@@ -90,6 +92,8 @@ fun getUser(
9092
* @return All users in the database
9193
*/
9294
fun getAllUsers(): List<User> = transaction(database) {
95+
if (!Users.exists()) return@transaction emptyList()
96+
9397
Users.selectAll()
9498
.map { row -> User(row[Users.username], row[Users.discord]) }
9599
}
@@ -104,6 +108,8 @@ fun updateUser(
104108
username: String,
105109
discord: Long
106110
) = transaction(database) {
111+
if (!Users.exists()) return@transaction 0
112+
107113
Users.update({ Users.username eq username }) { row ->
108114
row[Users.discord] = discord
109115
}
@@ -117,6 +123,7 @@ fun updateUser(
117123
fun removeUser(
118124
username: String
119125
) = transaction(database) {
126+
if (!Users.exists()) return@transaction 1
120127
Users.deleteWhere { Users.username eq username }
121128
}
122129

@@ -125,5 +132,6 @@ fun removeUser(
125132
* @return The count of deleted members
126133
*/
127134
fun removeAllUsers() = transaction(database) {
135+
if (!Users.exists()) return@transaction 0
128136
Users.deleteAll()
129137
}

0 commit comments

Comments
 (0)