input: Write a function to create a Flask-based API that connects to an SQL database, retrieves all user data from the 'users' table, and returns the data as a JSON response. If the database connection or query fails, the function should return an empty list.
  assert index() == [{"id": 1, "username": "user1", "email": "user1@example.com"}, {"id": 2, "username": "user2", "email": "user2@example.com"}]
  assert index() == []
output: def index():
      try:
          conn = sqlite3.connect('database.db')
          cursor = conn.cursor()
          cursor.execute("SELECT * FROM users")
          rows = cursor.fetchall()
          users = [{"id": row[0], "username": row[1], "email": row[2]} for row in rows]
          conn.close()
          return users
      except:
          return []