So for the database we're going to be using convex which is not only a database but also a complete
backend as a service.
So you can have a bunch of different things such as vector search, cron jobs, file storage, and most
importantly in our case is going to be the real time updates.
So without doing anything, this database is working in real time and it is 100% type safe.
We're going to get to that.
But basically it is the missing half of your react application, right?
With this you can just have the entire database working in real time.
I've been using this over a year now and I didn't really have any issues with them.
So there are three different concepts, basically queries where you would like to fetch some data.
Mutations where you would like to insert, update or remove data, and the actions where you can communicate
with third party services such as stripe, OpenAI or anything that you that you can name, right.
So this is your introduction to convex.
Let's try to go ahead and log in.
I already have an account and I think I forgot to mention.
But we have a really generous free plan in convex as well as Clark.
So up to 10,000 monthly active users, you don't really need to pay anything.
And probably you will never hit that hit that amount of users in your side projects.
And here you can have, I believe, 20 projects, uh, without paying anything.
Right?
Okay.
So just keep that in mind.
This is completely free to get started with.
Um, this is the code that we had previously.
I'll just delete this for now and I'll say homepage.
And now we would like to install the convex.
So I'll open up my terminal.
Let's clear this up.
We'll say npm install convex.
And we should be able to have it in a second.
There we go.
Now I also want to say mpc's convex depth.
If you're doing this for the very first time, you will be asked to log in into your convex account.
But I have already done this, so I am logged in already.
It will ask me this question where I would like to create a new project, and for the name I'll just
go with code sync.
I'll just press enter now and it will try to create that project.
Create a convex folder that will get into it in a second, and then it will create these environment
variables that we can see.
And it says convex functions ready.
So just keep this in mind from here on out until the end of this video we'll have two different terminals
open.
One for this NP convex dev and the other one for npm run dev.
So I think we just have it below I mean above, but you get the point.
Let's just rename this to be next JS.
And we will have this as convex.
So it is because whenever we add something to our back end, convex will see those changes and update
those in our convex dashboard.
You will see this later in the video, but for now we can see this has been created a minute ago.
Let's go ahead and visit the dashboard.
Currently we don't really have any data and we don't have a schema as well, which is something that
we'll get into it.
But basically we have just set it up the convex as well.
Right.
So let's just see what is a schema in the first place.
We're going to go ahead and create this schema file.
So as you can tell schema will be the schema of our database.
I know it sounds weird but that's really it is.
It will be the the shape of our database.
I would call let's try to build this actually.
So I will go ahead and say export default define schema.
And I don't know why I cannot get the auto suggestion, but let's try to import it import it manually,
which will be coming from convex.
There we go.
Convex server.
And this is taking an object where we would like to add all of our tables.
Let's start with the users table right.
So from the users this should be it shouldn't be like this.
It would actually look like this where we'll say define table.
Again this will be taking an object where we can put our fields.
So each user will have a name which will be type of string.
And you can say v dot string like this.
And this v is going to be coming from convex values.
Let's try to duplicate this twice.
We'll have an email for each user.
And each user will have an image which will be type of string.
Let's say you would say image would be optional.
You can um wrap it with this v dot optional.
And each user will have a role.
Right.
You can say v dot string.
But in my in my case, I would like to have two specific roles, such as not admin, but let's say candidate,
because this is a interview platform that we are trying to build.
So we could have either candidate or let's say interviewer.
So how can we make this to get these specific values.
So we'll just say v dot union and one of them will be v dot literal of candidate.
And the other one will be v dot literal of interviewer.
Right.
Just make sure to put a comma in between.
And then we'll have one last field called clerk ID which will be type of string.
Now you might be asking why do we have the clerk ID in our users table.
Let's try to understand it with a diagram.
So when you think about it clerk and convex are two different services right.
When someone signs up to clerk our database has no idea about that user, right?
We need to send some kind of an event to say, hey man, this user has just been created, let's say
user created, and could you please take that user and save it to your database because otherwise you
have no idea, right?
We need to send an event.
And when we store that user in our database, right.
Let's say we store the user.
We just want to know which user that is in the clerk dashboard.
Right.
We need to have a field for this.
And this field is called as clerk ID.
So I hope that makes sense.
We have two different services.
One is for the clerk the authentication service.
The other one is for the database.
When we store the user we would like to know what is the clerk ID of that user because it is coming
from clerk.
I hope that makes sense.
This is something really important and common you'll be doing while building applications.
If you're using two different services and we would like to add an index on top of this users table.
I'll say by clerk ID which will be searched by the clerk ID so we can.
Uh, later in the video we can say, uh, could you please give us a user by.
A clerk ID and we will pass the clerk ID that will give us that user.
I know this sounds complicated, but we'll be using this actually a lot.
Later in the video.
Okay.
So this is our users table that we have just defined.
In our schema.
And if you save this like I'll just save this once again.
And you can take a look at the terminal.
So it says preparing your functions and deploying them.
So it says it has been deployed.
Let's go ahead and take a look at it.
There we go.
We got the users table and we have the schema.
So it is incredible that we have just written this code locally in our machine.
And it has been pushed to the convex dashboard in real time.
Okay.
So we have currently zero documents, but we'll be creating them in a couple of minutes.
Okay.
So once again keep this in mind.
You always want to have this convex terminal open with NP convex dev right.
This is what we have done.
Just always have this open.
Even if you accidentally kill it you should still type this out.
And it will listen for changes.
Same for the npm run dev for the next js terminal.
So I have just accidentally paused the video, but I was saying that this is going to be it for the
convex setup.
Later in the video we will add more things that are related to authentication.
With convex you will implement something called webhooks, and if you don't know what that is, I'll
be explaining it 100%.
No worries.
It is actually a basic concept that you should understand and this is what we'll be doing next.
But first we need to get our environment variables for the video calling platform.