input: Write a function to develop a REST API using Flask that connects to an SQL database, fetches all user data, and returns the data as JSON. The function should include setting up a connection to the database, executing a query to retrieve all user data, and returning the results as a JSON response. Ensure that the API endpoint is exposed at the root URL (`/`). If an exception occurs during this process, an error message should be returned instead. The following assertion test cases can be used to validate the function:
  
  
  import json 
  import sqlite3 
  from flask import Flask, request, jsonify 
  
  app = Flask(__name__) 
  
  def dict_factory(cursor, row):
      d = {}
      for idx, col in enumerate(cursor.description):
          d[col[0]] = row[idx]
      return d 
  
  @app.route('/', methods=['GET'])
  def index(): 
      try:
          connection = sqlite3.connect('database.db')
          connection.row_factory = dict_factory
          cur = connection.cursor() 
          all_users = cur.execute('SELECT * FROM users;').fetchall() 
          return jsonify(all_users) 
      except Exception as e:
          return jsonify({"error": str(e)})
  
  if __name__ == '__main__': 
      app.run(debug = True)
  
  # Test cases
  assert index() == jsonify([{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Jane'}])
  assert index() == jsonify({"error": "database not found"})
  
output: 
  def index(): 
      try:
          connection = sqlite3.connect('database.db')
          connection.row_factory = dict_factory
          cur = connection.cursor() 
          all_users = cur.execute('SELECT * FROM users;').fetchall() 
          return jsonify(all_users) 
      except Exception as e:
          return jsonify({"error": str(e)})
  