input: Write a function to create a REST API in Python that fetches data from an SQL database and presents the data in the form of a JSON. The function should define a Flask application with a route for fetching all users from a table named "users". If the table "users" does not exist, the function should return an empty JSON object. The function should also include a dict_factory function to convert the database rows to dictionaries, and a debug mode that allows the application to run in debug mode.
  assert api_data().environ['werkzeug.server.shutdown']==True
output: def api_data():
      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('/users', methods=['GET'])
      def get_users():
          conn = sqlite3.connect('database.db')
          conn.row_factory = dict_factory
          cur = conn.cursor()
          cur.execute("SELECT * FROM users")
          users = cur.fetchall()
          conn.close()
          return jsonify(users)
  
      app.run(debug=True)