feat(POST): add POST function to insert new data on the DB
This commit is contained in:
parent
daa1061dce
commit
be1d1ff9a6
10
main.py
10
main.py
@ -70,9 +70,9 @@ async def read_item(test_id: int):
|
||||
return {"test_string": result}
|
||||
|
||||
|
||||
@app.put("/test/add")
|
||||
async def add_item(test_string: str):
|
||||
if test_string != "":
|
||||
@app.post("/test/add")
|
||||
async def add_item(test_string: Union[str, None] = None):
|
||||
if test_string:
|
||||
with engine.connect() as conn:
|
||||
trans = conn.begin()
|
||||
insert = test.insert().values(testString=test_string)
|
||||
@ -81,9 +81,11 @@ async def add_item(test_string: str):
|
||||
rows = conn.execute(select(test))
|
||||
for row in rows:
|
||||
print(row)
|
||||
msg = {"message": "Item added"}
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Item not found")
|
||||
return None
|
||||
msg = {"message": "err"}
|
||||
return msg
|
||||
|
||||
|
||||
with engine.connect() as conn:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user