def _auth_by_email(self, email): stmt = select([authors]).where(authors.c.email == email) result = self.sqldo(stmt).first() if email and not result: pkey = self.sqldo(insert(authors).values(email=email)).inserted_primary_key[0] return {'email':email, 'author_id':pkey} else: return dict(result)
def _tag(self, tag): """A method to get the id of a tag.""" stmt = select([tags]).where(tags.c.tag == tag) result = self.sqldo(stmt).first() if not result: pkey = self.sqldo(insert(tags).values(tag=tag)).inserted_primary_key[0] return {'tag':tag, 'tag_id':pkey} else: return dict(result)
def search(self, subject_text, strict=False): """ Takes a subject_text and optionally strict True/False. Returns a list of article subjects which contain subject_text. Strict flag makes searches require an exact match instead of contains. """ if not strict: subject_text = '%' + subject_text.lower() + '%' search_query = select([authorship.c.subject]).\ where(authorship.c.subject.like(subject_text)).\ distinct() result = self.sqldo(search_query) result_list = [dict(a) for a in result] result.close() return result_list
def _auth_by_id(self, author_id): stmt = select([authors]).where(authors.c.author_id == author_id) return dict(self.sqldo(stmt).first())
def taglist(self, subject): result = self.sqldo(select([tags.c.tag]).\ select_from(tagmap.join(tags, tagmap.c.tag_id == tags.c.tag_id)).\ where(tagmap.c.subject == subject)) return [tag[0] for tag in result]