Rename users table to user

This commit is contained in:
coolneng 2020-11-25 18:21:22 +01:00
parent 2d6597988c
commit 5ff70715c8
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 9 additions and 9 deletions

View File

@ -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})

View File

@ -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)