input: Write a function that develops an API in Python to fetch data from an SQL database and return the data as JSON. The function should be able to connect to a SQLite database named 'database.db' and retrieve all entries from the 'users' table. The API should return the data in a JSON format when accessed via a GET request to the root URL.
  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(): 
      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) 
    
  if __name__ == '__main__': 
      app.run(debug = True)
  
  assert requests.get('http://127.0.0.1:5000/').json() == [{'id': 1, 'name': 'Alice'}, {'id': 2, 'name': 'Bob'}]
  assert requests.get('http://127.0.0.1:5000/').json() == [{'id': 3, 'name': 'Charlie'}, {'id': 4, 'name': 'David'}]
output: 
  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(): 
      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)
  