Add instance to database.

    :param model: a string, model name in rio.models
    :param _commit: control whether commit data to database or not. Default True.
    :param \*\*kwargs: persisted data.
    :return: instance id.
331789
def add_instance(model, _commit=True, **kwargs):
    
    try:
        model = get_model(model)
    except ImportError:
        return None

    instance = model(**kwargs)
    db.session.add(instance)

    try:
        if _commit:
            db.session.commit()
        else:
            db.session.flush()
        return instance.id
    except IntegrityError:
        db.session.rollback()
        return
348419
def save_new(self, form, commit=True):
        
        kwargs = {self.fk.get_attname(): self.instance.pk}
        new_obj = self.model(**kwargs)
        self._prepare_multilingual_object(new_obj, form)
        return forms.save_instance(form, new_obj, exclude=[self._pk_field.name], commit=commit)
18587
def register_model(self, model):
        

        assert isinstance(model, str)
        if model not in self.all_models:
            self.all_models.append(model)
32583
def update(self, model_obj):
        
        identifier = model_obj[self.entity_cls.meta_.id_field.field_name]
        with self.conn['lock']:
            # Check if object is present
            if identifier not in self.conn['data'][self.schema_name]:
                raise ObjectNotFoundError(
                    f'`{self.__class__.__name__}` object with identifier {identifier} '
                    f'does not exist.')

            self.conn['data'][self.schema_name][identifier] = model_obj
        return model_obj
794251
def created(self, instance, commit=True):
        
        if commit:
            self.session_manager.save(instance, commit=True)
        return instance, HTTPStatus.CREATED
995119
def add(self, **args):
        
        kwargs = self.getKwargs(args)
        if kwargs:
            self.model.add(**kwargs)
1140295
def get_and_update(cls, id, **kwargs):
        
        model = cls.get(id)
        for k, v in cls._preprocess_params(kwargs).items():
            setattr(model, k, v)
        cls.session.commit()
        return model
160900
def create_table(self, model):
        
        self.orm[model._meta.table_name] = model
        model._meta.database = self.database
        self.ops.append(model.create_table)
        return model
674507
def updated(self, instance):
        
        self.session_manager.save(instance, commit=True)
        return instance
535567
def commit_when_no_transaction(f):
    ''''''
    def _(self, *args, **kwargs):
        r = f(self, *args, **kwargs)
        return self.session.add(self) if self.session is not None else r
    _.__name__ = f.__name__
    _.__doc__ = f.__doc__
    return _
1322144
def get_or_create(self, commit=False, **kwargs) -> Tuple[model, bool]:
        
        instance = self.get_by(**kwargs)
        if not instance:
            return self.create(commit=commit, **kwargs), True
        return instance, False
771460
def commit(self, commit):
		
		req_message = 'https://api.bitbucket.org/2.0/repositories/atlassian/aui/commit/' + commit
		response_data = self._bitbucketAPIRequest(req_message)
		try:
			return self._commitData(response_data)
		except (ValueError, KeyError):
			raise KeyError("Commit %s not found" % commit)
1030254
def refresh_model(self, model, *, overwrite=False):
    
    new_model = self.find_model_by_id(model.__class__, model.primary_key)
    if overwrite:
      model.update(new_model.to_dict(use_default_excludes=False))
      return model
    else:
      return new_model
1223711
def create_model_table(self, model):
        
        try:
            return db_model_factory(self.Base, model, self.models)
        except Exception as exc:
            raise ModelError(
                model.name,
                message="failed to create in-memory table.",
                orig_exc=exc,
                context=self.error_context
            )
1180483
def commit(self, commit):
		
		try:
			return self._commitData(self.repo.commit(commit))
		except (ValueError, KeyError, BadObject):
			if self._repo_info:
				raise KeyError("Commit %s not found for %s" % (commit, str(self._repo_info)))
			else:
				raise KeyError("Commit %s not found" % commit)
1357644
def _connect_model(self, model):
        

        parts = self._prop_name.split(".")
        if len(parts) > 1:
            # identifies the model
            models = parts[:-1]
            Intermediate(model, models, self)
            for name in models:
                model = getattr(model, name)
                if not isinstance(model, Model):
                    raise TypeError("Attribute '" + name +
                                    "' was expected to be a Model, but found: " +
                                    str(model))
            prop = parts[-1]
        else: prop = parts[0]

        # prop is inside model?
        if not hasattr(model, prop):
            raise ValueError("Attribute '" + prop +
                             "' not found in model " + str(model))

        # is it observable?
        if model.has_property(prop):
            # we need to create an observing method before registering
            meth = types.MethodType(self._get_observer_fun(prop), self)
            setattr(self, meth.__name__, meth)

        self._prop = getattr(model, prop)
        self._prop_name = prop

        # registration of model:
        self._model = model
        self.observe_model(model)
1219892
def addModel(self, moduleName, modelName, model):
        
        modelIdentifier = "{}.{}".format(moduleName, modelName)
        if modelIdentifier not in self._models:
            self._models[modelIdentifier] = model
        else:
            message = "Application - addModel() - " \
                      "A model with the identifier {} already exists." \
                      .format(modelIdentifier)
            raise Exception(message)