You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1017 B
35 lines
1017 B
from sqlalchemy.orm import Session |
|
|
|
import models, schemas |
|
|
|
|
|
def get_equipment(db: Session, equipment_id: int): |
|
return db.query(models.Equipment).filter(models.Equipment.id == equipment_id).first() |
|
|
|
|
|
def get_equipments(db: Session, skip: int = 0, limit: int = 10): |
|
return db.query(models.Equipment).offset(skip).limit(limit).all() |
|
|
|
|
|
def create_equipment(db: Session, equipment: schemas.EquipmentCreate): |
|
db_equipment = models.Equipment(**equipment.dict()) |
|
db.add(db_equipment) |
|
db.commit() |
|
db.refresh(db_equipment) |
|
return db_equipment |
|
|
|
|
|
def get_device(db: Session, device_id: int): |
|
return db.query(models.Device).filter(models.Device.id == device_id).first() |
|
|
|
|
|
def get_devices(db: Session, skip: int = 0, limit: int = 10): |
|
return db.query(models.Device).offset(skip).limit(limit).all() |
|
|
|
|
|
def create_device(db: Session, device: schemas.DeviceCreate): |
|
db_device = models.Device(**device.dict()) |
|
db.add(db_device) |
|
db.commit() |
|
db.refresh(db_device) |
|
return db_device
|
|
|