From 5ff70715c8b8541d32d6f8522a31cd521dd6ecba Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 25 Nov 2020 18:21:22 +0100 Subject: [PATCH] Rename users table to user --- database/crud.py | 14 +++++++------- database/models.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/database/crud.py b/database/crud.py index 3b9e9e1..f3dc9fe 100644 --- a/database/crud.py +++ b/database/crud.py @@ -2,7 +2,7 @@ from sqlalchemy import or_ from sqlalchemy.orm import Query from database import SessionLocal, engine, models -from database.models import Users +from database.models import User db = SessionLocal() @@ -11,8 +11,8 @@ def search_database(id) -> Query: """ Returns the user associated with the id argument """ - return db.query(Users).filter( - or_(Users.correo_institucional == id, Users.numero_de_documento == id) + return db.query(User).filter( + or_(User.correo_institucional == id, User.numero_de_documento == id) ) @@ -20,7 +20,7 @@ def insert_data(data) -> None: """ Inserts a new user into the database """ - item = Users(**data) + item = User(**data) db.add(item) db.commit() db.refresh(item) @@ -41,9 +41,9 @@ def save_attribute(attribute, data) -> None: """ Updates the attribute value with the content of data """ - key = eval("Users." + attribute) - db.query(Users).filter( - or_(Users.correo_institucional == id, Users.numero_de_documento == id) + key = eval("User." + attribute) + db.query(User).filter( + or_(User.correo_institucional == id, User.numero_de_documento == id) ).update({key: data}) diff --git a/database/models.py b/database/models.py index 928c4bd..27a2ea5 100644 --- a/database/models.py +++ b/database/models.py @@ -4,8 +4,8 @@ from sqlalchemy.types import Date, Integer, String, Text from database import Base -class Users(Base): - __tablename__ = "users" +class User(Base): + __tablename__ = "user" id = Column(Integer, primary_key=True, autoincrement=True) primer_apellido = Column(String, nullable=False)