code: def __get_tag_ids(self, tags):
          
  
          db_tags = self.fetchall("select * from tags where name in (%s)"
                                              % ",".join(["?"] * len(tags)), tags) # bit of magic here - using sqlites bind variables
  
          changes = False
  
          # check if any of tags needs resurrection
          set_complete = [str(tag["id"]) for tag in db_tags if tag["autocomplete"] == "false"]
          if set_complete:
              changes = True
              self.execute("update tags set autocomplete='true' where id in (%s)" % ", ".join(set_complete))
  
  
          found_tags = [tag["name"] for tag in db_tags]
  
          add = set(tags) - set(found_tags)
          if add:
              statement = "insert into tags(name) values(?)"
  
              self.execute([statement] * len(add), [(tag,) for tag in add])
  
              return self.__get_tag_ids(tags)[0], True # all done, recurse
          else:
              return db_tags, changes
docs: look up tags by their name. create if not found