code: def setup_database(config=None):
      """Create the Database instance from a configuration.
  
      Parameters
      ----------
      config: dict
          Configuration for the database backend. If not defined, global configuration
          is used.
  
      """
      if config is None:
          # TODO: How could we support orion.core.config.storage.database as well?
          config = orion.core.config.database.to_dict()
  
      db_opts = config
      dbtype = db_opts.pop("type")
  
      log.debug(
          "Creating %s database client with args: %s", dbtype, db_opts
      )
  
      return database_factory.create(dbtype, **db_opts)
  
imports: import contextlib
  import datetime
  import logging
  import pickle
  import time
  import orion.core
  import orion.core.utils.backward
  from orion.core.io.database import Database, OutdatedDatabaseError, database_factory
  from orion.core.worker.trial import Trial, validate_status
  from orion.storage.base import BaseStorageProtocol, FailedUpdate, LockAcquisitionTimeout, LockedAlgorithmState, get_trial_uid_and_exp, get_uid
label_desc: Use image node_id 1 for calling a global function with example usage: setup_database(config) and returns: database_factory