1
00:00:00,600 --> 00:00:07,400
So for the database we're going to be using convex which is not only a database but also a complete

2
00:00:07,400 --> 00:00:09,480
backend as a service.

3
00:00:09,640 --> 00:00:16,560
So you can have a bunch of different things such as vector search, cron jobs, file storage, and most

4
00:00:16,560 --> 00:00:20,600
importantly in our case is going to be the real time updates.

5
00:00:20,640 --> 00:00:27,720
So without doing anything, this database is working in real time and it is 100% type safe.

6
00:00:28,080 --> 00:00:29,400
We're going to get to that.

7
00:00:29,400 --> 00:00:33,760
But basically it is the missing half of your react application, right?

8
00:00:34,080 --> 00:00:38,920
With this you can just have the entire database working in real time.

9
00:00:38,960 --> 00:00:43,760
I've been using this over a year now and I didn't really have any issues with them.

10
00:00:44,080 --> 00:00:50,360
So there are three different concepts, basically queries where you would like to fetch some data.

11
00:00:50,680 --> 00:00:58,760
Mutations where you would like to insert, update or remove data, and the actions where you can communicate

12
00:00:58,760 --> 00:01:05,930
with third party services such as stripe, OpenAI or anything that you that you can name, right.

13
00:01:06,490 --> 00:01:09,530
So this is your introduction to convex.

14
00:01:09,530 --> 00:01:11,810
Let's try to go ahead and log in.

15
00:01:13,090 --> 00:01:16,690
I already have an account and I think I forgot to mention.

16
00:01:16,690 --> 00:01:22,090
But we have a really generous free plan in convex as well as Clark.

17
00:01:22,290 --> 00:01:27,450
So up to 10,000 monthly active users, you don't really need to pay anything.

18
00:01:27,570 --> 00:01:33,090
And probably you will never hit that hit that amount of users in your side projects.

19
00:01:33,330 --> 00:01:39,250
And here you can have, I believe, 20 projects, uh, without paying anything.

20
00:01:39,570 --> 00:01:40,010
Right?

21
00:01:40,410 --> 00:01:40,690
Okay.

22
00:01:40,730 --> 00:01:41,890
So just keep that in mind.

23
00:01:41,930 --> 00:01:44,450
This is completely free to get started with.

24
00:01:46,090 --> 00:01:48,570
Um, this is the code that we had previously.

25
00:01:48,570 --> 00:01:51,210
I'll just delete this for now and I'll say homepage.

26
00:01:52,570 --> 00:01:55,530
And now we would like to install the convex.

27
00:01:55,570 --> 00:01:57,010
So I'll open up my terminal.

28
00:01:57,010 --> 00:01:58,090
Let's clear this up.

29
00:01:58,130 --> 00:02:00,370
We'll say npm install convex.

30
00:02:05,050 --> 00:02:07,690
And we should be able to have it in a second.

31
00:02:07,730 --> 00:02:08,330
There we go.

32
00:02:08,820 --> 00:02:12,580
Now I also want to say mpc's convex depth.

33
00:02:12,940 --> 00:02:19,180
If you're doing this for the very first time, you will be asked to log in into your convex account.

34
00:02:19,220 --> 00:02:22,780
But I have already done this, so I am logged in already.

35
00:02:23,500 --> 00:02:29,740
It will ask me this question where I would like to create a new project, and for the name I'll just

36
00:02:29,740 --> 00:02:31,100
go with code sync.

37
00:02:31,140 --> 00:02:35,220
I'll just press enter now and it will try to create that project.

38
00:02:35,260 --> 00:02:41,100
Create a convex folder that will get into it in a second, and then it will create these environment

39
00:02:41,100 --> 00:02:42,900
variables that we can see.

40
00:02:43,340 --> 00:02:45,940
And it says convex functions ready.

41
00:02:46,180 --> 00:02:52,860
So just keep this in mind from here on out until the end of this video we'll have two different terminals

42
00:02:52,860 --> 00:02:53,540
open.

43
00:02:53,620 --> 00:02:59,500
One for this NP convex dev and the other one for npm run dev.

44
00:03:00,140 --> 00:03:04,060
So I think we just have it below I mean above, but you get the point.

45
00:03:04,060 --> 00:03:06,580
Let's just rename this to be next JS.

46
00:03:07,140 --> 00:03:09,420
And we will have this as convex.

47
00:03:11,340 --> 00:03:19,260
So it is because whenever we add something to our back end, convex will see those changes and update

48
00:03:19,260 --> 00:03:21,220
those in our convex dashboard.

49
00:03:21,500 --> 00:03:27,700
You will see this later in the video, but for now we can see this has been created a minute ago.

50
00:03:28,220 --> 00:03:30,500
Let's go ahead and visit the dashboard.

51
00:03:30,940 --> 00:03:36,300
Currently we don't really have any data and we don't have a schema as well, which is something that

52
00:03:36,300 --> 00:03:37,340
we'll get into it.

53
00:03:37,700 --> 00:03:41,300
But basically we have just set it up the convex as well.

54
00:03:41,340 --> 00:03:41,820
Right.

55
00:03:42,060 --> 00:03:44,860
So let's just see what is a schema in the first place.

56
00:03:45,380 --> 00:03:48,860
We're going to go ahead and create this schema file.

57
00:03:49,620 --> 00:03:54,300
So as you can tell schema will be the schema of our database.

58
00:03:54,340 --> 00:03:57,940
I know it sounds weird but that's really it is.

59
00:03:58,100 --> 00:04:01,020
It will be the the shape of our database.

60
00:04:01,020 --> 00:04:04,140
I would call let's try to build this actually.

61
00:04:04,140 --> 00:04:09,940
So I will go ahead and say export default define schema.

62
00:04:10,220 --> 00:04:16,590
And I don't know why I cannot get the auto suggestion, but let's try to import it import it manually,

63
00:04:16,590 --> 00:04:18,470
which will be coming from convex.

64
00:04:18,470 --> 00:04:19,110
There we go.

65
00:04:19,150 --> 00:04:20,470
Convex server.

66
00:04:20,670 --> 00:04:24,990
And this is taking an object where we would like to add all of our tables.

67
00:04:25,230 --> 00:04:28,430
Let's start with the users table right.

68
00:04:28,470 --> 00:04:33,670
So from the users this should be it shouldn't be like this.

69
00:04:33,710 --> 00:04:38,630
It would actually look like this where we'll say define table.

70
00:04:40,550 --> 00:04:44,550
Again this will be taking an object where we can put our fields.

71
00:04:44,550 --> 00:04:48,790
So each user will have a name which will be type of string.

72
00:04:48,830 --> 00:04:53,510
And you can say v dot string like this.

73
00:04:53,550 --> 00:04:56,990
And this v is going to be coming from convex values.

74
00:04:57,190 --> 00:04:59,470
Let's try to duplicate this twice.

75
00:04:59,510 --> 00:05:02,470
We'll have an email for each user.

76
00:05:02,750 --> 00:05:06,790
And each user will have an image which will be type of string.

77
00:05:06,950 --> 00:05:09,470
Let's say you would say image would be optional.

78
00:05:09,510 --> 00:05:13,950
You can um wrap it with this v dot optional.

79
00:05:14,150 --> 00:05:16,270
And each user will have a role.

80
00:05:16,310 --> 00:05:16,870
Right.

81
00:05:16,910 --> 00:05:18,750
You can say v dot string.

82
00:05:18,910 --> 00:05:26,320
But in my in my case, I would like to have two specific roles, such as not admin, but let's say candidate,

83
00:05:26,760 --> 00:05:31,280
because this is a interview platform that we are trying to build.

84
00:05:31,280 --> 00:05:36,080
So we could have either candidate or let's say interviewer.

85
00:05:38,600 --> 00:05:43,120
So how can we make this to get these specific values.

86
00:05:43,120 --> 00:05:50,160
So we'll just say v dot union and one of them will be v dot literal of candidate.

87
00:05:50,160 --> 00:05:54,360
And the other one will be v dot literal of interviewer.

88
00:05:54,400 --> 00:05:54,880
Right.

89
00:05:54,920 --> 00:05:58,160
Just make sure to put a comma in between.

90
00:05:58,360 --> 00:06:04,480
And then we'll have one last field called clerk ID which will be type of string.

91
00:06:04,760 --> 00:06:09,800
Now you might be asking why do we have the clerk ID in our users table.

92
00:06:10,680 --> 00:06:13,280
Let's try to understand it with a diagram.

93
00:06:13,400 --> 00:06:18,840
So when you think about it clerk and convex are two different services right.

94
00:06:19,000 --> 00:06:25,250
When someone signs up to clerk our database has no idea about that user, right?

95
00:06:25,290 --> 00:06:31,930
We need to send some kind of an event to say, hey man, this user has just been created, let's say

96
00:06:31,930 --> 00:06:39,290
user created, and could you please take that user and save it to your database because otherwise you

97
00:06:39,290 --> 00:06:40,810
have no idea, right?

98
00:06:40,850 --> 00:06:42,210
We need to send an event.

99
00:06:42,330 --> 00:06:46,810
And when we store that user in our database, right.

100
00:06:46,850 --> 00:06:48,570
Let's say we store the user.

101
00:06:48,610 --> 00:06:54,010
We just want to know which user that is in the clerk dashboard.

102
00:06:54,050 --> 00:06:54,610
Right.

103
00:06:54,650 --> 00:06:56,690
We need to have a field for this.

104
00:06:56,730 --> 00:06:59,890
And this field is called as clerk ID.

105
00:07:00,650 --> 00:07:02,290
So I hope that makes sense.

106
00:07:02,330 --> 00:07:04,290
We have two different services.

107
00:07:04,450 --> 00:07:07,530
One is for the clerk the authentication service.

108
00:07:07,650 --> 00:07:09,930
The other one is for the database.

109
00:07:09,970 --> 00:07:15,490
When we store the user we would like to know what is the clerk ID of that user because it is coming

110
00:07:15,490 --> 00:07:16,410
from clerk.

111
00:07:17,170 --> 00:07:18,330
I hope that makes sense.

112
00:07:18,330 --> 00:07:23,850
This is something really important and common you'll be doing while building applications.

113
00:07:24,090 --> 00:07:30,890
If you're using two different services and we would like to add an index on top of this users table.

114
00:07:30,930 --> 00:07:37,930
I'll say by clerk ID which will be searched by the clerk ID so we can.

115
00:07:38,370 --> 00:07:43,850
Uh, later in the video we can say, uh, could you please give us a user by.

116
00:07:43,890 --> 00:07:48,570
A clerk ID and we will pass the clerk ID that will give us that user.

117
00:07:48,850 --> 00:07:52,570
I know this sounds complicated, but we'll be using this actually a lot.

118
00:07:52,610 --> 00:07:53,570
Later in the video.

119
00:07:54,090 --> 00:07:54,490
Okay.

120
00:07:54,530 --> 00:07:58,050
So this is our users table that we have just defined.

121
00:07:58,090 --> 00:07:59,210
In our schema.

122
00:07:59,450 --> 00:08:03,850
And if you save this like I'll just save this once again.

123
00:08:03,850 --> 00:08:05,690
And you can take a look at the terminal.

124
00:08:06,810 --> 00:08:10,410
So it says preparing your functions and deploying them.

125
00:08:10,410 --> 00:08:12,370
So it says it has been deployed.

126
00:08:12,410 --> 00:08:14,370
Let's go ahead and take a look at it.

127
00:08:14,530 --> 00:08:15,050
There we go.

128
00:08:15,090 --> 00:08:18,490
We got the users table and we have the schema.

129
00:08:18,650 --> 00:08:23,450
So it is incredible that we have just written this code locally in our machine.

130
00:08:23,450 --> 00:08:28,050
And it has been pushed to the convex dashboard in real time.

131
00:08:29,450 --> 00:08:29,850
Okay.

132
00:08:30,130 --> 00:08:35,860
So we have currently zero documents, but we'll be creating them in a couple of minutes.

133
00:08:36,980 --> 00:08:37,420
Okay.

134
00:08:37,460 --> 00:08:39,380
So once again keep this in mind.

135
00:08:39,500 --> 00:08:45,900
You always want to have this convex terminal open with NP convex dev right.

136
00:08:45,940 --> 00:08:47,140
This is what we have done.

137
00:08:47,500 --> 00:08:49,300
Just always have this open.

138
00:08:49,300 --> 00:08:54,340
Even if you accidentally kill it you should still type this out.

139
00:08:56,820 --> 00:08:58,940
And it will listen for changes.

140
00:08:59,220 --> 00:09:02,900
Same for the npm run dev for the next js terminal.

141
00:09:03,460 --> 00:09:08,940
So I have just accidentally paused the video, but I was saying that this is going to be it for the

142
00:09:08,940 --> 00:09:10,340
convex setup.

143
00:09:10,380 --> 00:09:14,860
Later in the video we will add more things that are related to authentication.

144
00:09:14,860 --> 00:09:20,500
With convex you will implement something called webhooks, and if you don't know what that is, I'll

145
00:09:20,500 --> 00:09:22,700
be explaining it 100%.

146
00:09:22,900 --> 00:09:23,660
No worries.

147
00:09:23,660 --> 00:09:29,900
It is actually a basic concept that you should understand and this is what we'll be doing next.

148
00:09:30,020 --> 00:09:35,060
But first we need to get our environment variables for the video calling platform.

