code: def add_layer(self, layer, layer_name, save_style=False):
          
          if self._use_index:
              layer_name = '%s-%s' % (self._index, layer_name)
              self._index += 1
  
          if self.layer_uri(layer_name):
              return False, tr('The layer already exists in the datastore.')
  
          if isinstance(layer, QgsRasterLayer):
              result = self._add_raster_layer(layer, layer_name, save_style)
          else:
              if layer.wkbType() == QgsWkbTypes.NoGeometry:
                  result = self._add_tabular_layer(layer, layer_name, save_style)
              else:
                  result = self._add_vector_layer(layer, layer_name, save_style)
  
          if result[0]:
              LOGGER.info(
                  'Layer saved {layer_name}'.format(layer_name=result[1]))
  
          try:
              layer.keywords
              real_layer = self.layer(result[1])
              if isinstance(real_layer, bool):
                  message = ('{name} was not found in the datastore or the '
                             'layer was not valid.'.format(name=result[1]))
                  LOGGER.debug(message)
                  return False, message
              KeywordIO().write_keywords(real_layer, layer.keywords)
          except AttributeError:
              pass
  
          return result
docs: Add a layer to the datastore.
  
          :param layer: The layer to add.
          :type layer: QgsMapLayer
  
          :param layer_name: The name of the layer in the datastore.
          :type layer_name: str
  
          :param save_style: If we have to save a QML too. Default to False.
          :type save_style: bool
  
          :returns: A two-tuple. The first element will be True if we could add
              the layer to the datastore. The second element will be the layer
              name which has been used or the error message.
          :rtype: (bool, str)
  
          .. versionadded:: 4.0