input: Write a function named 'index' that establishes a connection to an SQLite database, fetches all records from a table named 'users', and returns the data as a JSON response. Ensure the function uses a dictionary factory to format the rows into dictionaries before converting them to JSON.
  assert index('database.db')==jsonify([{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}])
  assert index('database.db')==jsonify([{'id': 1, 'name': 'Charlie'}, {'id': 2, 'name': 'David'}])
  assert index('database.db')==jsonify([])
  assert index('database.db')==jsonify([{'id': 5, 'name': 'Eve'}, {'id': 6, 'name': 'Frank'}])
output: def index(db_name):
      import sqlite3
      import json
  
      def dict_factory(cursor, row):
          d = {}
          for idx, col in enumerate(cursor.description):
              d[col[0]] = row[idx]
          return d
  
      conn = sqlite3.connect(db_name)
      conn.row_factory = dict_factory
      cursor = conn.cursor()
      cursor.execute("SELECT * FROM users")
      rows = cursor.fetchall()
      conn.close()
      return json.dumps(rows)