WEBVTT

﻿1
00:00:01.418 --> 00:00:07.674
In this session. we will implement a feature to log fire detection data into the database.  

00:00:08.174 --> 00:00:11.803
Since this functionality involves handling the database. 

00:00:12.178 --> 00:00:19.394
we will add it to the `crud` file within the `predict_fire` domain that we previously created. 

00:00:20.020 --> 00:00:26.317
The feature itself is simple—process the detected data and store it in the database.  

00:00:26.901 --> 00:00:31.489
The official documentation covers how to use SQLAlchemy.  

00:00:31.823 --> 00:00:35.618
But since the content is extensive and not always intuitive. 

00:00:35.785 --> 00:00:39.706
it is convenient to ask an LLM first when needed.  

00:00:54.512 --> 00:00:58.933
Here. `add()`. `commit()`. and `refresh()` serve the following functions.

00:00:59.559 --> 00:01:05.774
`add()` adds an object to the session. The changes are only applied after calling `commit()`.  

00:01:06.274 --> 00:01:09.319
`commit()` saves the changes to the database.  

00:01:09.986 --> 00:01:14.908
`refresh()` fetches the latest data from the database and updates the object.  

00:01:15.658 --> 00:01:22.373
To modify the database structure. we will delete the existing database file and recreate it. 

00:01:23.708 --> 00:01:27.378
We considered adding a login feature.  

00:01:27.378 --> 00:01:32.425
But including it in this lecture would unnecessarily increase the complexity. 

00:01:32.425 --> 00:01:34.219
so we will not add it this time.  

00:01:34.969 --> 00:01:41.851
Therefore. we will remove the relationship between the user table and the detection log table.  

00:01:47.774 --> 00:01:55.615
We will change the result file key used for logging to the UUID-generated filename we created earlier.  

00:01:56.199 --> 00:02:02.122
By storing this key. we can later access the image files saved in the log folder.  

00:02:03.957 --> 00:02:12.882
We will call the `create_detection_log` function implemented in the `crud` file.
To log data whenever a fire is detected.  

00:02:16.886 --> 00:02:19.055
We will update the file path.  

00:02:19.055 --> 00:02:24.435
And use FastAPI's `Depends` to inject a new DB session for each request.  

00:02:26.855 --> 00:02:32.402
Once the request is completed. the session will be automatically cleaned up.  

00:02:36.698 --> 00:02:42.787
We will run the server and check the database file using the SQLite extension.  

00:02:58.595 --> 00:03:05.685
Using Postman. we will send a request to the `predict_fire` endpoint  

00:03:11.482 --> 00:03:15.653
We can verify that the data has been successfully logged.  
