'Return the internal identifier for a given nick.
This identifier is unique to a user, and shared across all of that
user\'s aliases. If create is True, a new ID will be created if one does
not already exist'

def get_nick_id(self, nick, create=True):

    slug = nick.lower()
    nick_id = self.execute(u'SELECT    nick_id    from    nicknames    where    slug    =    ?', [slug]).fetchone()
    if (nick_id is None):
        if (not create):
            raise ValueError(u'No    ID    exists    for    the    given    nick')
        with self.connect() as conn:
            cur = conn.cursor()
            cur.execute(u'INSERT    INTO    nick_ids    VALUES    (NULL)')
            nick_id = cur.execute(u'SELECT    last_insert_rowid()').fetchone()[0]
            cur.execute(u'INSERT    INTO    nicknames    (nick_id,    slug,    canonical)    VALUES    (?,    ?,    ?)', [nick_id, slug, nick])
        nick_id = self.execute(u'SELECT    nick_id    from    nicknames    where    slug    =    ?', [slug]).fetchone()
    return nick_id[0]
