1
00:00:05,270 --> 00:00:11,970
Welcome to the section of the course on utilizing databases with Python and flask we now understand

2
00:00:11,970 --> 00:00:15,150
how to grab user information through forms with flask.

3
00:00:15,360 --> 00:00:20,100
Well we're going to do now is Bill on top of this understanding by linking our flask applications to

4
00:00:20,100 --> 00:00:24,340
a database so we can actually save user information.

5
00:00:24,350 --> 00:00:26,720
So let's talk about databases just in general.

6
00:00:26,750 --> 00:00:32,200
We're going to be using Escudo or sequel databases and they allow us to store data in a tabular format

7
00:00:32,390 --> 00:00:38,450
essentially a really large Excel spreadsheet where there's an index columns 0 0 0 1 2 and that's a numeric

8
00:00:38,450 --> 00:00:39,990
column for every row.

9
00:00:40,160 --> 00:00:42,770
And then we have values for each column.

10
00:00:42,770 --> 00:00:48,300
So for example we can have a name column for name of a puppy the breed of the puppy and then the eye

11
00:00:48,320 --> 00:00:56,050
color of the puppy and each individual row represents a user or a single data point that typically when

12
00:00:56,050 --> 00:01:00,580
you're working with any Escudo or sequel database you're actually going to need to learn sequence statements.

13
00:01:00,610 --> 00:01:03,400
So sequel stands for structured query language.

14
00:01:03,550 --> 00:01:09,460
And that's actually it's own syntax in order to query essentially ask the database for information back

15
00:01:09,790 --> 00:01:11,980
and that sort of syntax looks something like this.

16
00:01:11,980 --> 00:01:17,070
Select Asterix from puppies maybe puppies is the name of the table and so on.

17
00:01:17,080 --> 00:01:21,050
Now luckily with the aid of some useful libraries we're going to be able to use pure python.

18
00:01:21,070 --> 00:01:25,710
So you don't actually need to learn the structure to create language in order to have a database working

19
00:01:25,710 --> 00:01:30,580
if your flask application instead will be able to do very similar commands through python.

20
00:01:30,580 --> 00:01:36,070
So even though we're using as well with our database and our flask application we don't actually need

21
00:01:36,070 --> 00:01:41,460
to learn the structure language syntax that goes along for typical Escuela database.

22
00:01:41,470 --> 00:01:45,290
Instead we'll be doing that all through python making our lives a lot easier.

23
00:01:46,590 --> 00:01:50,400
Now Python and Flast can connect to a variety of sequel database engines.

24
00:01:50,580 --> 00:01:56,580
So sequel comes in many flavors so to speak including post sequel My sequel sequel light Microsoft sequel

25
00:01:56,580 --> 00:01:59,900
server and a lot more we're going to be using sequel lite.

26
00:01:59,940 --> 00:02:05,270
It's a really simple as cool database engine that comes a flask and can handle all our needs and as

27
00:02:05,280 --> 00:02:09,990
quick point you've probably heard me say both sequel and Eskew all it's really up to you how you prefer

28
00:02:09,990 --> 00:02:10,460
to say it.

29
00:02:10,470 --> 00:02:11,790
I sometimes switch back and forth.

30
00:02:11,820 --> 00:02:13,100
So just keep that in mind.

31
00:02:14,180 --> 00:02:18,810
So sequel lite despite its name it can actually scale quite well for basic applications.

32
00:02:18,950 --> 00:02:24,500
If you're running a web application that gets around 100000 hits per day sequela I can handle any issues

33
00:02:24,800 --> 00:02:27,850
and don't think of a hundred thousand as some sort of hard cap limit.

34
00:02:27,890 --> 00:02:32,810
It's just a kind of upper limit as far as what you should expect sequel like to be able to handle.

35
00:02:32,810 --> 00:02:36,700
It's not a hard cap at hundred thousand hits and over it's going to stop working.

36
00:02:36,770 --> 00:02:38,740
It's just a general range of what it can do.

37
00:02:38,780 --> 00:02:40,420
So that's pretty good scale.

38
00:02:40,580 --> 00:02:45,890
Now to get a python flask and a skill together we're going to need what's known as an o r.m and that's

39
00:02:45,890 --> 00:02:47,790
an object relational mapper.

40
00:02:47,870 --> 00:02:52,010
Essentially something that allows us to convert Python code to those sequel commands that we talked

41
00:02:52,010 --> 00:02:54,080
about earlier.

42
00:02:54,120 --> 00:02:59,070
So as I just mention mentioned or M is going to allow us to directly as Python instead of a sequel syntax

43
00:02:59,070 --> 00:03:02,130
to create edit update and delete from our database.

44
00:03:02,370 --> 00:03:08,670
And the most common or M for Python is called sequel alchemy flask sequel.

45
00:03:08,670 --> 00:03:13,500
Alchemy is an extension off of that that actually allows for an easy connection of flask with sequel

46
00:03:13,530 --> 00:03:14,340
alchemy.

47
00:03:14,400 --> 00:03:17,790
So at the end of the day you can see that we simply have layers of abstraction.

48
00:03:17,880 --> 00:03:23,010
We have the CULE database and then on top of that we're going to abstract further with Python's sequel

49
00:03:23,040 --> 00:03:27,630
alchemy and then on top of that we have a higher level abstraction called flask sequel alchemy.

50
00:03:27,840 --> 00:03:32,100
So we're really going to be working on a flat sequel alchemy which is going to allow us to very easily

51
00:03:32,100 --> 00:03:38,250
connect Python code inside of a flask application to create a sequel database and then we can create

52
00:03:38,250 --> 00:03:42,990
new rows in that database update the zeros delete those rows and so on.

53
00:03:42,990 --> 00:03:46,620
So in order to do that you need to actually install flask sequel alchemy.

54
00:03:46,620 --> 00:03:50,300
It's already in the requirements of text files if you using that you're good to go.

55
00:03:50,400 --> 00:03:54,700
But in case you haven't used that you can just say Pipp install flask sequel alchemy.

56
00:03:54,920 --> 00:03:59,510
And you can just do a google search for a flask of alchemy to check out their documentation.

57
00:03:59,510 --> 00:04:03,960
All right so that's a very brief introduction to just databases and Python in general.

58
00:04:03,990 --> 00:04:08,340
Coming up next we're going to have a further discussion on how we actually work with flask in particular

59
00:04:08,560 --> 00:04:09,790
with sequel alchemy.

60
00:04:09,990 --> 00:04:10,950
We'll see at the next lecture.
