code: def database_exists(url):
      
  
      url = copy(make_url(url))
      database = url.database
      if url.drivername.startswith('postgresql'):
          url.database = 'template1'
      else:
          url.database = None
  
      engine = sa.create_engine(url)
  
      if engine.dialect.name == 'postgresql':
          text = "SELECT 1 FROM pg_database WHERE datname='%s'" % database
          return bool(engine.execute(text).scalar())
  
      elif engine.dialect.name == 'mysql':
          text = ("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA "
                  "WHERE SCHEMA_NAME = '%s'" % database)
          return bool(engine.execute(text).scalar())
  
      elif engine.dialect.name == 'sqlite':
          return database == ':memory:' or os.path.exists(database)
  
      else:
          text = 'SELECT 1'
          try:
              url.database = database
              engine = sa.create_engine(url)
              engine.execute(text)
              return True
  
          except (ProgrammingError, OperationalError):
              return False
docs: Check if a database exists.
  
      :param url: A SQLAlchemy engine URL.
  
      Performs backend-specific testing to quickly determine if a database
      exists on the server. ::
  
          database_exists('postgres://postgres@localhost/name')  #=> False
          create_database('postgres://postgres@localhost/name')
          database_exists('postgres://postgres@localhost/name')  #=> True
  
      Supports checking against a constructed URL as well. ::
  
          engine = create_engine('postgres://postgres@localhost/name')
          database_exists(engine.url)  #=> False
          create_database(engine.url)
          database_exists(engine.url)  #=> True