input: Write a function to create a Flask API that retrieves data from an SQLite database and serves it as a JSON response. The function should define a route that connects to the SQLite database, fetches all users from a table named 'users', and returns the data in JSON format. The function should also define a helper function to convert database rows into dictionaries.
  
  
  from flask import Flask, jsonify
  import sqlite3
  
  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()
      connection.close()
      return jsonify(all_users)
  
  if __name__ == '__main__':
      app.run(debug=True)
  
  assert index() == jsonify([{'id': 1, 'name': 'John'}, {'id': 2, 'name': 'Jane'}])
  assert index() == jsonify([])
  assert index() == jsonify([{'id': 3, 'name': 'Doe'}, {'id': 4, 'name': 'Smith'}])
output: 
  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()
      connection.close()
      return jsonify(all_users)
  