class_docstr: Command for importing databases, datasets, charts, dashboards and saved queries.
  
  This command is used for managing Superset assets externally under source control,
  and will overwrite everything.
class_docstr_tok: ["Command","for","importing","databases",",","datasets",",","charts",",","dashboards","and","saved","queries",".","This","command","is","used","for","managing","Superset","assets","externally","under","source","control",",","and","will","overwrite","everything","."]
code: def _import(session: Session, configs: dict[str, Any]) -> None:
      # import databases first
      database_ids: dict[str, int] = {}
      for file_name, config in configs.items():
          if file_name.startswith("databases/"):
              database = import_database(
                  session, config, overwrite=True
              )
              database_ids[str(database.uuid)] = database.id
  
      # import saved queries
      for file_name, config in configs.items():
          if file_name.startswith("queries/"):
              config["db_id"] = database_ids[config["database_uuid"]]
              import_saved_query(session, config, overwrite=True)
  
      # import datasets
      dataset_info: dict[str, dict[str, Any]] = {}
      for file_name, config in configs.items():
          if file_name.startswith("datasets/"):
              config["database_id"] = database_ids[
                  config["database_uuid"]
              ]
              dataset = import_dataset(session, config, overwrite=True)
              dataset_info[str(dataset.uuid)] = {
                  "datasource_id": dataset.id,
                  "datasource_type": dataset.datasource_type,
                  "datasource_name": dataset.table_name,
              }
  
      # import charts
      chart_ids: dict[str, int] = {}
      for file_name, config in configs.items():
          if file_name.startswith("charts/"):
              dataset_dict = dataset_info[config["dataset_uuid"]]
              config.update(dataset_dict)
              # pylint: disable=line-too-long
              dataset_uid = f"{dataset_dict['datasource_id']}__{dataset_dict['datasource_type']}"
              config["params"].update({"datasource": dataset_uid})
              if "query_context" in config:
                  config["query_context"] = None
              chart = import_chart(session, config, overwrite=True)
              chart_ids[str(chart.uuid)] = chart.id
  
      # import dashboards
      for file_name, config in configs.items():
          if file_name.startswith("dashboards/"):
              config = update_id_refs(config, chart_ids, dataset_info)
              dashboard = import_dashboard(
                  session, config, overwrite=True
              )
  
              # set ref in the dashboard_slices table
              dashboard_chart_ids: list[dict[str, int]] = []
              for uuid in find_chart_uuids(config["position"]):
                  if uuid not in chart_ids:
                      break
                  chart_id = chart_ids[uuid]
                  dashboard_chart_id = {
                      "dashboard_id": dashboard.id,
                      "slice_id": chart_id,
                  }
                  dashboard_chart_ids.append(dashboard_chart_id)
  
              session.execute(
                  delete(dashboard_slices).where(
                      dashboard_slices.c.dashboard_id == dashboard.id
                  )
              )
              session.execute(
                  insert(dashboard_slices).values(dashboard_chart_ids)
              )
  
imports: from typing import Any, Optional
  from marshmallow import Schema
  from marshmallow.exceptions import ValidationError
  from sqlalchemy.orm import Session
  from sqlalchemy.sql import delete, insert
  from superset import db
  from superset.charts.schemas import ImportV1ChartSchema
  from superset.commands.base import BaseCommand
  from superset.commands.chart.importers.v1.utils import import_chart
  from superset.commands.dashboard.importers.v1.utils import find_chart_uuids, import_dashboard, update_id_refs
  from superset.commands.database.importers.v1.utils import import_database
  from superset.commands.dataset.importers.v1.utils import import_dataset
  from superset.commands.exceptions import CommandInvalidError, ImportFailedError
  from superset.commands.importers.v1.utils import load_configs, load_metadata, validate_metadata_type
  from superset.commands.query.importers.v1.utils import import_saved_query
  from superset.dashboards.schemas import ImportV1DashboardSchema
  from superset.databases.schemas import ImportV1DatabaseSchema
  from superset.datasets.schemas import ImportV1DatasetSchema
  from superset.models.dashboard import dashboard_slices
  from superset.queries.saved_queries.schemas import ImportV1SavedQuerySchema
label_desc: Use image node_id 2 for calling the ImportAssetsCommand obj's underlying member method code with example usage: obj._import(session, configs) without return types