Add crud views
This commit is contained in:
parent
4f508bb5bb
commit
2437c802fe
|
@ -6,7 +6,8 @@ from fastapi import FastAPI, Request, Body
|
|||
from collections import defaultdict
|
||||
|
||||
from . import utils
|
||||
from papi.sqlapp.database import Base
|
||||
|
||||
from papi.sqlapp.database import Base, SessionLocal, engine
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
from sqlalchemy.orm import Session
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
def get_sonde(db: Session, identifiant: str):
|
||||
return (
|
||||
db.query(models.Sonde).filter(models.Sonde.identifiant == identifiant).first()
|
||||
)
|
||||
|
||||
|
||||
def create_sonde(db: Session, identifiant: str, nom: str):
|
||||
db_sonde = models.Sonde(identifiant=identifiant, nom=nom)
|
||||
db.add(db_sonde)
|
||||
db.commit()
|
||||
db.refresh(db_sonde)
|
||||
return db_sonde
|
||||
|
||||
|
||||
def create_mesure(db: Session, sonde_id: int, content: dict):
|
||||
db_mesure = models.Mesure(sonde_id=sonde_id, content=content)
|
||||
db.add(db_mesure)
|
||||
db.commit()
|
||||
db.refesh(db_mesure)
|
||||
return db_mesure
|
||||
|
||||
|
||||
def get_mesure(db: Session, sonde_id: int):
|
||||
return db.query(models.Mesure).filter(models.Mesure.sonde_id == sonde_id).all()
|
|
@ -6,14 +6,14 @@ from .database import Base
|
|||
|
||||
class Sonde(Base):
|
||||
__tablename__ = "sonde"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
sonde_id = Column(Integer, primary_key=True, index=True)
|
||||
nom = Column(String, index=True)
|
||||
identifiant = Column(String, index=True, unique=True, nullable=False)
|
||||
# mesures = relationship("Mesure")
|
||||
mesures = relationship("Mesure")
|
||||
|
||||
|
||||
class Mesure(Base):
|
||||
__tablename__ == "mesure"
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
# sonde_id = Column(Integer, Foreignkey("sonde.id")
|
||||
mesure_id = Column(Integer, primary_key=True, index=True)
|
||||
sonde_id = Column(Integer, Foreignkey("sonde.id"))
|
||||
content = Column(JSON, nullable=False)
|
||||
|
|
Loading…
Reference in New Issue