sqlalchemy_utils.identity

Here are the examples of the python api sqlalchemy_utils.identity taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: sqlalchemy-continuum Source File: operation.py
Function: format_key
    def format_key(self, target):
        # We cannot use target._sa_instance_state.identity here since object's
        # identity is not yet updated at this phase
        return (target.__class__, identity(target))

Example 2

Project: sqlalchemy-continuum Source File: unit_of_work.py
    def get_or_create_version_object(self, target):
        """
        Return version object for given parent object. If no version object
        exists for given parent object, create one.

        :param target: Parent object to create the version object for
        """
        version_cls = version_class(target.__class__)
        version_id = identity(target) + (self.current_transaction.id, )
        version_key = (version_cls, version_id)

        if version_key not in self.version_objs:
            version_obj = version_cls()
            self.version_objs[version_key] = version_obj
            self.version_session.add(version_obj)
            tx_column = self.manager.option(
                target,
                'transaction_column_name'
            )
            setattr(
                version_obj,
                tx_column,
                self.current_transaction.id
            )
            return version_obj
        else:
            return self.version_objs[version_key]