mirror of https://gitlab.com/akasroua/covot
28 lines
585 B
Python
28 lines
585 B
Python
|
from sqlalchemy import or_
|
||
|
|
||
|
from database import SessionLocal, engine, models
|
||
|
from database.models import Users
|
||
|
|
||
|
db = SessionLocal()
|
||
|
|
||
|
|
||
|
def search_database(id):
|
||
|
return db.query(Users).filter(
|
||
|
or_(Users.correo_institucional == id, Users.numero_de_documento == id)
|
||
|
)
|
||
|
|
||
|
|
||
|
def insert_data(data):
|
||
|
item = Users(**data)
|
||
|
db.add(item)
|
||
|
db.commit()
|
||
|
db.refresh(item)
|
||
|
|
||
|
|
||
|
def create_database(data):
|
||
|
models.Base.metadata.create_all(bind=engine)
|
||
|
existing_row = search_database(data["correo_institucional"])
|
||
|
if existing_row:
|
||
|
return
|
||
|
insert_data(data)
|