input: Write a function that creates a Flask API to fetch data from an SQL database and return the data in JSON format. The function should establish a connection to the database, execute an SQL query to fetch all user data, and present the results in a JSON object. If the database query is successful, the function should return the JSON response. Otherwise, it should return an appropriate error message.
  
  def create_api():
      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 create_api.__name__ == 'create_api'
  assert create_api.index.__name__ == 'index'
  assert create_api.index.methods == ['GET']
  assert create_api.dict_factory.__name__ == 'dict_factory'
  assert create_api.cursor.__name__ == 'Cursor'
  assert create_api.fetchall.__name__ == 'fetchall'
  assert create_api.jsonify.__name__ == 'jsonify'
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(): 
      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)})
  