WEBVTT

﻿1
00:00:01.459 --> 00:00:05.255
now, we need to use a database to store and retrieve data.  

2
00:00:06.631 --> 00:00:12.804
in fastapi, we use sqlalchemy to connect to the database and manage data.  

3
00:00:14.764 --> 00:00:18.309
instead of manually connecting every time,

4
00:00:18.309 --> 00:00:23.815
we will create a file to manage the database connection in advance.  

5
00:00:24.774 --> 00:00:28.194
this file will act as a "database client."  

6
00:00:28.778 --> 00:00:34.284
let’s install `sqlalchemy` inside our conda virtual environment.  

7
00:00:51.468 --> 00:00:58.808
then, check that the correct conda virtual environment is selected in select interpreter.  

8
00:01:01.644 --> 00:01:11.279
next, select reload window from the command palette, and you should see that `sqlalchemy` is installed successfully. 

9
00:01:22.999 --> 00:01:29.005
now, let’s define each model, which means defining the table structure.  

10
00:01:29.839 --> 00:01:35.178
we will define the `user`, `session`, and `detection_log` tables.  

11
00:01:36.429 --> 00:01:38.181
we are not certain yet, 

12
00:01:38.515 --> 00:01:44.395
but we will define, the `user` table to store user information,  

13
00:01:47.357 --> 00:01:51.194
 the `session` table to store session details,  

14
00:01:58.952 --> 00:02:03.665
and the `detection_log` table to store fire detection data.  

15
00:02:16.052 --> 00:02:20.807
now, we will initialize the database in the `main.py` file. 

16
00:02:21.474 --> 00:02:25.895
we will add configurations to resolve any path issues.  

17
00:02:28.857 --> 00:02:33.611
let’s configure the settings to initialize the database.  

18
00:03:11.399 --> 00:03:16.654
once the configuration is complete and the server is restarted, 

19
00:03:16.654 --> 00:03:21.701
you should see that the `sql_app.db` file has been created.  

20
00:03:23.703 --> 00:03:26.080
install the `sqlite` extension. 

21
00:03:30.168 --> 00:03:36.758
next, open the command palette, go to the `sqlite` menu, and select open database.  

22
00:03:37.133 --> 00:03:39.677
select the `sql_app.db` file.  

23
00:03:42.805 --> 00:03:47.644
you will see a sqlite explorer tab appear in the left menu.  

24
00:03:48.186 --> 00:03:55.443
in this tab, you can view the created tables, their structures, and run various queries.  

25
00:03:56.653 --> 00:04:00.406
now, we have successfully integrated `sqlite`. 
