def mutate(self, info, **kwargs): card = db_session.query(ModelCard).filter_by( id=kwargs.get('id')).first() db_session.delete(card) db_session.commit() return DeleteCard(status="OK")
def upsert(name, triangle): """ Handles upsert funtionality of mutations Parameters ---------- name : The name of the Triangle triangle: The triangle instance """ bytes_container = pickle.dumps(triangle) try: # If table exists exists = db_session.query(ModelTriangle).filter_by(name=name) if exists.first(): exists.update({'edited': datetime.utcnow(), 'data': bytes_container}) else: data = {'name': name, 'data': bytes_container, 'created': datetime.utcnow(), 'edited': datetime.utcnow()} db_session.add(ModelTriangle(**data)) except: data = {'name': name, 'data': bytes_container, 'created': datetime.utcnow(), 'edited': datetime.utcnow()} db_session.add(ModelTriangle(**data)) db_session.commit() return db_session.query(ModelTriangle).filter_by(name=name).first()
def mutate(self, info, input): data = utils.input_to_dictionary(input) #data['password'] = hash(data['password']) this is where I will return a JWT service = ModelService(**data) db_session.add(service) db_session.commit() return CreateService(service=service)
def mutate(self, info, input): """hjk""" data = utils.input_to_dictionary(input) user = UserModel(**data) db_session.add(user) db_session.commit() return CreateUser(user=user)
def mutate(self, info, input): data = utils.input_to_dictionary(input) task = ModelTask(**data) db_session.add(task) db_session.commit() return CreateTask(task=task)
def mutate(self, info, input): data = utils.input_to_dictionary(input) person = db_session.query(ModelPeople).filter_by(id=data['id']).first() print("mutation Delete") db_session.delete(person) db_session.commit() person = db_session.query(ModelPeople).filter_by(id=data['id']).first() return DeletePerson(person=person)
def mutate(self, info, input): data = utils.input_to_dictionary(input) match = ModelMatches(**data) db_session.query(ModelMatches).filter_by( match_id=data['match_id']).delete() db_session.commit() return DeleteMatch(match=match)
def mutate(self, info, input): data = utils.input_to_dictionary(input) user = db_session.query(UserModel).filter_by(netid=data["netid"]) user.update(data) db_session.commit() user = db_session.query(UserModel).filter_by( netid=data["netid"]).first() return UpdateUser(user=user)
def mutate(self, info, input): data = utils.input_to_dictionary(input) task = db_session.query(ModelTask).filter_by(id=data['id']) task.update(data) db_session.commit() task = db_session.query(ModelTask).filter_by(id=data['id']).first() return UpdateTask(task=task)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['created'] = datetime.utcnow() card = ModelCard(**data) db_session.add(card) db_session.commit() return CreateCard(card=card)
def mutate(self, info, input): data = utils.input_to_dictionary(input) question = db_session.query(QuestionModel).filter_by(id=data["id"]) question.update(data) db_session.commit() question = db_session.query(QuestionModel).filter_by( id=data["id"]).first() return UpdateQuestion(question=question)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['match_date'] = datetime.strptime(data['match_date'], '%Y-%m-%d') match = ModelMatches(**data) db_session.add(match) db_session.commit() return CreateMatch(match=match)
def mutate(self, info, input): data = utils.input_to_dictionary(input) card = db_session.query(ModelCard).filter_by(id=data['id']) card.update(data) db_session.commit() card = db_session.query(ModelCard).filter_by(id=data['id']).first() return UpdateCard(card=card)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['edited'] = datetime.utcnow() person = db_session.query(ModelPeople).filter_by(id=data['id']) people.update(data) db_session.commit() person = db_session.query(ModelPeople).filter_by(id=data['id']).first() return UpdatePerson(person=person)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['created'] = datetime.utcnow() data['edited'] = datetime.utcnow() person = ModelPeople(**data) db_session.add(person) db_session.commit() return CreatePerson(person=person)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data["edited"] = datetime.utcnow() agent = db_session.query(ModelAgent).filter_by(id=data["id"]) agent.update(data) db_session.commit() agent = db_session.query(ModelAgent).filter_by(id=data["id"]).first() return UpdateAgent(agent=agent)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data["created"] = datetime.utcnow() data["edited"] = datetime.utcnow() agent = ModelAgent(**data) db_session.add(agent) db_session.commit() return CreateAgent(agent=agent)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['edited'] = datetime.utcnow() planet = db_session.query(ModelPlanet).filter_by(id=data['id']) planet.update(data) db_session.commit() planet = db_session.query(ModelPlanet).filter_by(id=data['id']).first() return UpdatePlanet(planet=planet)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['edited'] = datetime.utcnow() person = db_session.query(ModelPeople).filter_by(id=data['id']) person.update(data) db_session.commit() person = db_session.query(ModelPeople).filter_by(id=data['id']).first() return UpdatePerson(person=person)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data["created"] = datetime.utcnow() data["edited"] = datetime.utcnow() customer = ModelCustomer(**data) db_session.add(customer) db_session.commit() return CreateCustomer(customer=customer)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data['created'] = datetime.utcnow() data['edited'] = datetime.utcnow() planet = ModelPlanet(**data) db_session.add(planet) db_session.commit() return CreatePlanet(planet=planet)
def mutate(self, info, input): data = utils.input_to_dictionary(input) service = db_session.query(ModelService).filter_by( service=data['service']) service.delete() db_session.commit() return RemoveService( service="Removed {} service".format(data['service'])) #return RemoveService(service=service)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data["edited"] = datetime.utcnow() customer = db_session.query(ModelCustomer).filter_by(id=data["id"]) customer.update(data) db_session.commit() customer = db_session.query(ModelCustomer).filter_by( id=data["id"]).first() return UpdaterCustomer(customer=customer)
def mutate(self, info, input): data = utils.input_to_dictionary(input) #filter_by refers to the columns or rows in the attributes service = db_session.query(ModelService).filter_by( service=data['service']) service.update(data) db_session.commit() service = db_session.query(ModelService).filter_by( service=data['service']).first() return UpdateService(service=service)
def mutate(self, info, input): data = utils.input_to_dictionary(input) data["time_posted"] = datetime.utcnow() data["queue_pos"] = len( db_session.query(QuestionModel).filter( QuestionModel.course_id == data["course_id"]).filter( QuestionModel.queue_pos > 0).all()) + 1 question = QuestionModel(**data) db_session.add(question) db_session.commit() return CreateQuestion(question=question)
def save_user_data(kwargs): email = kwargs['data']['email'] if db_session.query(kwargs['model']).filter_by(email=email).first( ): #checks to see if user already made an account with the given email return "Email already in use" kwargs['data']['passphrase'] = hash_passphrase( kwargs['data']['passphrase']) kwargs['data']['id'] = create_uid(kwargs['model']) new_model = kwargs['model'](**kwargs['data']) db_session.add(new_model) db_session.commit() return "Account Created"
def mutate(self, info, input): data = utils.input_to_dictionary(input) if "match_date" in data.keys(): data['match_date'] = datetime.strptime(data['match_date'], '%Y-%m-%d') match = db_session.query(ModelMatches).filter_by( match_id=data['match_id']) match.update(data) db_session.commit() match = db_session.query(ModelMatches).filter_by( match_id=data['match_id']).first() return UpdateMatch(match=match)
def save_services_data(kwargs): query_result = db_session.query( kwargs['model']).filter_by(user_id=kwargs['user_id']) if not query_result.first(): #.first() will return None if not found kwargs['data']['id'] = create_uid(kwargs['model']) kwargs['data']['user_id'] = kwargs['user_id'] new_model = kwargs['model'](**kwargs['data']) db_session.add(new_model) else: query_result.update( kwargs["data"] ) #if we use .first() here then the object will not have the update attribute db_session.commit() return "Data Added"
from database.base import engine, db_session, Base from models import Recipe, Ingredient Base.metadata.create_all(bind=engine) if __name__ == '__main__': ingredients = [ Ingredient(name=ing_name) for ing_name in [ 'chicken', 'beef', 'olive oil', 'salt', 'pepper', 'hot sauce', 'broccoli', 'green beans', 'spinach', 'carrots', 'soy sauce', ] ] db_session.add_all(ingredients) db_session.commit() recipes = (Recipe(name=f'recipe {number}', ingredients=random.sample(ingredients, 4)) for number in range(1000)) db_session.add_all(ingredients) db_session.commit()
def mutate(self, info, name): db_session.query(ModelTriangle).filter_by(name=name).delete() db_session.commit() return DeleteTriangle(ok='ok')