def store_alias(self, seq_id, namespace, alias):
        """associate a namespaced alias with a sequence

        Alias association with sequences is idempotent: duplicate
        associations are discarded silently.

        """

        if not self._writeable:
            raise RuntimeError("Cannot write -- opened read-only")

        log_pfx = "store({q},{n},{a})".format(n=namespace, a=alias, q=seq_id)
        try:
            c = self._db.execute("insert into seqalias (seq_id, namespace, alias) values (?, ?, ?)", (seq_id, namespace,
                                                                                                      alias))
            # success => new record
            return c.lastrowid
        except sqlite3.IntegrityError:
            pass

        # IntegrityError fall-through

        # existing record is guaranteed to exist uniquely; fetchone() should always succeed
        current_rec = self.find_aliases(namespace=namespace, alias=alias).fetchone()

        # if seq_id matches current record, it's a duplicate (seq_id, namespace, alias) tuple
        # and we return current record
        if current_rec["seq_id"] == seq_id:
            _logger.debug(log_pfx + ": duplicate record")
            return current_rec["seqalias_id"]

        # otherwise, we're reassigning; deprecate old record, then retry
        _logger.debug(log_pfx + ": collision; deprecating {s1}".format(s1=current_rec["seq_id"]))
        self._db.execute("update seqalias set is_current = 0 where seqalias_id = ?", [current_rec["seqalias_id"]])
        return self.store_alias(seq_id, namespace, alias)
def store_alias ( self , seq_id , namespace , alias ) : if not self . _writeable : raise RuntimeError ( "Cannot write -- opened read-only" ) log_pfx = "store({q},{n},{a})" . format ( n = namespace , a = alias , q = seq_id ) try : c = self . _db . execute ( "insert into seqalias (seq_id, namespace, alias) values (?, ?, ?)" , ( seq_id , namespace , alias ) ) return c . lastrowid except sqlite3 . IntegrityError : pass current_rec = self . find_aliases ( namespace = namespace , alias = alias ) . fetchone ( ) if current_rec [ "seq_id" ] == seq_id : _logger . debug ( log_pfx + ": duplicate record" ) return current_rec [ "seqalias_id" ] _logger . debug ( log_pfx + ": collision; deprecating {s1}" . format ( s1 = current_rec [ "seq_id" ] ) ) self . _db . execute ( "update seqalias set is_current = 0 where seqalias_id = ?" , [ current_rec [ "seqalias_id" ] ] ) return self . store_alias ( seq_id , namespace , alias )
associate a namespaced alias with a sequence

        Alias association with sequences is idempotent: duplicate
        associations are discarded silently.