diff --git a/src/main/java/io/supertokens/storage/postgresql/Start.java b/src/main/java/io/supertokens/storage/postgresql/Start.java index eeee4ded..b1395e19 100644 --- a/src/main/java/io/supertokens/storage/postgresql/Start.java +++ b/src/main/java/io/supertokens/storage/postgresql/Start.java @@ -1535,8 +1535,13 @@ public int deleteAllRolesForUser(String userId) throws StorageQueryException { @Override public boolean deleteRoleForUser_Transaction(TransactionConnection con, String userId, String role) throws StorageQueryException { - // TODO - return false; + Connection sqlCon = (Connection) con.getConnection(); + + try { + return UserRolesQueries.deleteRoleForUser_Transaction(this, sqlCon, userId, role); + } catch (SQLException e) { + throw new StorageQueryException(e); + } } @Override @@ -1586,7 +1591,12 @@ public int deleteAllPermissionsForRole_Transaction(TransactionConnection con, St @Override public boolean doesRoleExist_Transaction(TransactionConnection con, String role) throws StorageQueryException { - // TODO - return false; + Connection sqlCon = (Connection) con.getConnection(); + try { + return UserRolesQueries.doesRoleExist_transaction(this, sqlCon, role); + } catch (SQLException e) { + throw new StorageQueryException(e); + } } + } diff --git a/src/main/java/io/supertokens/storage/postgresql/queries/UserRolesQueries.java b/src/main/java/io/supertokens/storage/postgresql/queries/UserRolesQueries.java index 2f34f38e..7522b864 100644 --- a/src/main/java/io/supertokens/storage/postgresql/queries/UserRolesQueries.java +++ b/src/main/java/io/supertokens/storage/postgresql/queries/UserRolesQueries.java @@ -155,4 +155,23 @@ public static String[] getRolesForUser(Start start, String userId) throws SQLExc return roles.toArray(String[]::new); }); } + + public static boolean deleteRoleForUser_Transaction(Start start, Connection con, String userId, String role) + throws SQLException, StorageQueryException { + String QUERY = "DELETE FROM " + getConfig(start).getUserRolesTable() + " WHERE user_id = ? AND role = ? ;"; + + // store the number of rows updated + int rowUpdatedCount = update(con, QUERY, pst -> { + pst.setString(1, userId); + pst.setString(2, role); + }); + return rowUpdatedCount > 0; + } + + public static boolean doesRoleExist_transaction(Start start, Connection con, String role) + throws SQLException, StorageQueryException { + String QUERY = "SELECT 1 FROM " + getConfig(start).getRolesTable() + " WHERE role = ? FOR UPDATE"; + return execute(con, QUERY, pst -> pst.setString(1, role), ResultSet::next); + } + }