-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrud.py
More file actions
44 lines (38 loc) · 1.09 KB
/
Copy pathcrud.py
File metadata and controls
44 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from sqlalchemy.orm import Session
from schemas import Motorbike
import models
def get_motorbikes(db: Session):
return db.query(models.DBMotorbike).all()
def create_motorbike(db: Session, motorbike: Motorbike):
db_motorbike = models.DBMotorbike(
brand=motorbike.brand,
model=motorbike.model,
engine_capacity=motorbike.engine_capacity,
)
db.add(db_motorbike)
db.commit()
db.refresh(db_motorbike)
return db_motorbike
def get_motorbike(
db: Session,
motorbike_id: int
):
return db.query(models.DBMotorbike).filter(models.DBMotorbike.id == motorbike_id).first()
def update_motorbike(
db: Session,
db_motorbike: models.DBMotorbike,
motorbike: Motorbike
):
db_motorbike.brand = motorbike.brand
db_motorbike.model = motorbike.model
db_motorbike.engine_capacity = motorbike.engine_capacity
db.commit()
db.refresh(db_motorbike)
return db_motorbike
def delete_motorbike(
db: Session,
db_motorbike: models.DBMotorbike
):
db.delete(db_motorbike)
db.commit()
return db_motorbike