def deleteAllChores(): try: num_rows_deleted = session.query(Chores).delete() session.commit() return "{} records deleted\n".format(num_rows_deleted) except: session.rollback()
def delete_all_chores(): """It deletes all the chores from the database.""" try: num_rows_deleted = session.query(Chores).delete() session.commit() return "{} records deleted\n".format(num_rows_deleted) except: session.rollback()
def deleteAChore(choreid): try: choreToDelete = session.query(Chores).filter_by( chore_title=choreid).one() except: return "No such chores exist\n" session.delete(choreToDelete) session.commit() return "Removed Chore with id %s\n" % choreid
def delete_a_chore(choreid): """It deletes a chore with the chore_title""" try: chore_to_delete = session.query(Chores).filter_by( chore_title=choreid).one() except: return "No such chores exist\n" session.delete(chore_to_delete) session.commit() return "Removed Chore with id %s\n" % choreid
def updateChore(title, task): try: tobeUpdatedChore = session.query(Chores).filter_by( chore_title=title).one() tobeUpdatedChore.chore = task session.merge(tobeUpdatedChore) except: tobeUpdatedChore = Chores(chore_title=title, chore=task) session.add(tobeUpdatedChore) session.commit() return "Updated the chore with id %s\n" % title
def update_a_chore(title, task): """This just update an existing chore with newer task""" try: tobe_updatedchore = session.query(Chores).filter_by( chore_title=title).one() tobe_updatedchore.chore = task session.merge(tobe_updatedchore) except: tobe_updatedchore = Chores(chore_title=title, chore=task) session.add(tobe_updatedchore) session.commit() return "Updated the chore with id %s\n" % title
def makeANewChore(chore): title, task = chore.items()[0] addedchore = Chores(chore_title=title, chore=task) existing_titles = [ elem.chore_title for elem in session.query(Chores).all() ] if addedchore.chore_title not in existing_titles: session.add(addedchore) session.commit() return jsonify(addedchore.serialize) else: return "Chore title already exist.\n"
def make_a_new_chore(chore): """This adds a new chore in the database and also returns the json format of the chores added""" title, task = chore.items()[0] addedchore = Chores(chore_title=title, chore=task) existing_titles = [ elem.chore_title for elem in session.query(Chores).all() ] if addedchore.chore_title not in existing_titles: session.add(addedchore) session.commit() return jsonify(addedchore.serialize) else: return "Chore title already exist.\n"
from models import Model, Tag, Post, User from populate_db import create_tag_or_user, fake, session user = create_tag_or_user(1, User, fake.name)[0] tags = [create_tag_or_user(1, Tag, fake.word)[0] for _ in range(2)] post = Post(user=user, title=fake.sentence(), body=fake.text()) post.tags.extend(tags) session.add(user) session.add(tags[0]) session.add(tags[1]) session.add(post) session.commit() posts = session.query(Post).join(User).filter(User.name == user.name).filter( Post.tags.any(Tag.id.in_([tag.id for tag in tags]))).all() print(posts)