class PgConn::RoleMethods

def exist?(*rolenames, superuser: nil, can_login: nil)

Return true if role(s) exists
def exist?(*rolenames, superuser: nil, can_login: nil)
  rolenames = Array(rolenames).flatten.compact
  rolename_clause = "rolname in (#{PgConn.sql_values(rolenames)})"
  superuser_clause =
      case superuser
        when true; "rolsuper"
        when false; "not rolsuper"
      else
        nil
      end
  can_login_clause =
      case can_login
        when true; "rolcanlogin"
        when false; "not rolcanlogin"
      else
        nil
      end
  where_clause = [rolename_clause, superuser_clause, can_login_clause].compact.join(" and ")
  conn.value("select count(*) from pg_roles where #{where_clause}") == rolenames.size
end