In this video, we're working on our URL Shortener project built with Node.js, MySQL, and Drizzle ORM. To demonstrate pagination, we need lots of URL data — but manually adding it is slow. So, we’ll use Drizzle ORM’s seeding functionality to generate 100 fake short links, all linked to a single user in our database.
🌱 This is called database seeding — it helps create dummy data for testing and development.
Hello what's up guys today in this video we will
see seeding in database. Yes guys
this term which is in seed is very common in
terms of database. So you must know this.
Ok? I will
tell you what happens. Here you can see we have
these short links. Ok? And
here you can see that total we have 100
values. Believe me what are these short links
? This is our project. We have a project of note in which
we
started initially through short links. But
later in that we log in with Google GH,
complete registration login, ah two
step verification, ah basically authentication,
that too refresh token, access token, all that.
Isn't it? But we started from here
where we were adding a URL
and creating a shortcut code for it. So
tell me one thing, we will make maximum 510.
No one will make 100. But yes,
I want to show you guys the pagination which
we will see in tomorrow's video that obviously we need
a pagination also. So
without pagination, then whatever Google search you do, at
the end there is pagination only, page number
one, page number two, this is very important which
you should know. So I don't want to
do my manual work 100 times.
That's why in database we have term called
seed where you can generate fake data.
And that fake data will
look completely realistic to you. Because
he is not creating fake data on his own will.
This is how we create our table.
Look carefully at what I am saying.
This means that we have an ID, so
whatever date you are seeing. Ok? 1 2 3 4
5 This is equally correct. Then we have a
URL. You can see that whatever URL
is there here, it is all a valid URL. And
then you can see this is this short code.
Short code means any small code which
we can use instead of such a long code. This
is also valid. And here you can see when it was
created. Yes, there is one thing that I
found very weird here. I don't know why, I
mean he might have felt a bit [ __ ] up but you
can see that it doesn't
matter because it's fake data, by the way, but
this was created in 2026 and as
far as I remember, as much as I understand, the year
2025 is going on, so I mean
when did I add that by going to the future, I do
n't know brother, either a year ago, or I am
time travelling, but it is 2026 here, so this makes it
clear that it is
completely fake, but everything is absolutely equal,
see, the user ID is completely equal and
everything is equal. So, all these data,
there are total 100 data, we have created them
with the help of Seed in Drizzle. Yes
guys, this is very important. And
its useful I mean you get to know its use case
because I have to
show you the pagination. Where this
pagination is, this is a very important
pagination. Where there is not just previous and
next. A lot of logic is going to be
used in this which you will
know in tomorrow's video. But today in this video
we will learn how to generate fake data
based on your schema based on the
schema of your table, which is very important.
You will not even feel that it is fake but in
reality it is fake. Ok? Which is very
important. Alright guys so let's
start the video without any delay. But
before that, if you have
n’t checked out our Awesome Notices series yet, then
do check it out. You won't get anything better than this.
We have gone into depth, we have covered the complete
registration, login authentication,
everything. Forgot password,
email, verification link coming to your Gmail.
Brother, you will not get this much anywhere else. You
try it once, if you don't like it then change my name.
And yes guys if you haven't subscribed to the channel then do subscribe
because more
awesome videos are coming in future. And I don't
want you to miss it. Ok? So
look carefully. So by default
an awesome part of Drizzle is that it has
already seeded Drizzle for us. You
can see we have something called Drizzle
Seed over here which you can see post
grace sequel lite my sequel and it
works on single straw and one
important thing I told you is that this Drizzle Seed can only be
used with the Drizzled ORM
whose version should be this or above.
Ok? Keep this in mind. And one more
thing, what did he say? Drizzle Seed is
a TypeScript library. That
helps you generate
realistic fake data to populate your
database. You saw that this is
a library of type scripts and this is very important.
I hope now you have understood what seed means
sowing seeds. You sow any mango seed,
if you want to do any farming, you throw the seed, it
grows big, so it is kind of like that.
So pay attention to this. And
believe me it is very simple. Ok
? How to do it? I tell you.
First of all we need to install this particular
package. So, I will copy this.
This is what Huffon Seed should be like. Let's see or we
have this diesel seed over here. So
this perfect CV we have this result sheet and
recently it is slowly growing,
see it is slowly becoming popular, I
guess it is okay but whatever it is,
we already have it here, so let me go, there is
nothing to do here, just set npm install
result, once you get it done from there,
you have to come to the package file, okay, alright
guys, so you can see that ours has been
installed, now if I
come here, then somewhere or see, this is it,
now you can see that this is the current version which has been
installed here. You
can see the result that the CD has been installed.
Now you have to come to this ship package.json file.
We need to add one more script
and this is this one, brother you will have to write this
db hf colon seed and this is basically
whatever data is there in our NB file, then it is
taking that and doing the work. And then the
result is half seed dots okay? Basically
we have to run it. So that we can
generate that particular fake data, whatever we
say whether we need 100 or 10. Ok
? So you have to write this, it is simple.
Nothing I have to run the drizzle huffing sheet.
And here is the data on my NB file. I want
him to also read this and nothing else.
Nod so obviously we need to write. Ok
? My work is done. What do you
do now? Now let me tell you.
Look carefully. You have to come to your schema sorry not
schema first rzl. Then inside Drizzle
we need to create one file named
c dot jess. Look carefully at what I have
done. In the results folder, I have just
created one file named sheet.js.
Ok? So in this sheet.js, I am
copying and pasting a file.
Ok? So first of all, I will remove this. Let
me close this. And
this upper part of mine, I run it.
Ok? It is very basic.
And by the way you can copy paste this ditto.
What should we do about that? I
tell you. First of all, we are saying that
we need to reset
all the schemas in our database. Ok? That means,
we are resetting all the schema and all the tables that I have. They are
absolutely making it empty.
Ok? We are doing that.
After that, now I don't have to seed it on my database. It
means sowing the seeds. Where
you can see that it has been explained in this way that in
my database, the
schema of these two tables is this. schemas.users.table
schemas.shortlinks.table.
We are denoting these. And
where is this coming from? Look,
I have already imported it from my schema.js.
And I have also got my
database with actual configuration
from here. If you are
still confused, then this is what is being talked about.
And look what is this yours? There
is an NB data. ENb That's why in the
script that we created in our packs json,
we
wrote something by hovering over ENb, this is necessary so that I
can read the data of our dot ENb file. Ok? So that's why
I am importing database reset and seed from drizzle sheet.
And this
is our actual schema. You can see this
here. Look at all the tables we have.
So I
am resetting all the schemas. And by the way I do
n't need it. If I tell you the truth right now,
I don't need it. Just do this, I will
reset everything and finish my process.
Ok? Now look carefully at
what this means. So look carefully
guys. what do I do. Now here I
run my studio.
Ok? So my studio is run.
Here we have our studio. If I
refresh now, this data of mine will be gone
because what I just showed you was the
project that we are going to do.
Ok? You can see there
are five sessions here. There are 5 users. You are able to see this much data, right?
Look here, right 5 0 1
0515, like this, but at the moment, now I will
run this code which has my seed.
npm run
db colon seed now see what happens. The
moment I run it. You will see the magic,
guys, let me refresh this and boom, guys,
see this, obviously the migration
file will remain but everything else will become zero. So is
n't it so awesome that now you
can delete all your tables in a snap.
You deleted them all. There is no issue.
Ok? I will refresh this as well. He has gone.
Now let me tell you just what I want.
Here is that part.
What do I need now? So what do we do now
guys? Let me tell you one thing. So first of all let
me quickly log out of this.
So guys, you can see that I have
started our project.
I'll refresh back now. Ok
? So let me log in with Google.
I'll go with this one. Ok? I am
Thapa on technical side. So you can see this is
our profile. Ok? For some reason, I do
n't know why the image is not visible even though I
did it just yesterday. The butt will come. Don't worry.
I don't have anything here right now.
Right? But one thing is certain that
I have to refresh it now. So now we have
one user whose ID is this, please look carefully.
It's one. id is my one. And currently there are no
short links on Short Links.
So what am I saying now? I have an ID
whose id value is one.
Because I only have one user right now.
Ok? Please reset this
particular table of mine. In case if there was
any data in my shortlinks table then
please reset it. I hope
you got to know this. Now, I have to sow the seeds.
I want realistic fake data now. So
I said this is the database. You will
get access to the database. There is
a table called shortlinks, the reference of which is
schemas.shortlinkstable. And there
I need total 100 fake data. And that is
the count this particular. And then we need to
go with the refined method. Inside that method
we are passing a callback function useImean. You
can see one of us in that also.
Inside the parenthesis we have an
object inside which there is a short links table, this is
basically what we are talking about. Now,
you gave the reference of this table to it, short
links table, we passed it here,
you are passing the extra information inside it.
Again we pass an object. Now we are saying
that there are nine columns in it, two columns which
you have to define. Ok? This is
done in diesel in the same manner.
So in columns I said that there
will be a column with user ID in the short links
table. You can see it in the short links
table by user ID or this is it.
This user ID
matches with my user ID.
So this user ID, that is one. So that means
it is connected to it. Ok? And basically
this is about foreign key. Then this
is my URL. Now you don't need fake data.
Right? And in fake data we are
not creating URL shortening. So whenever
anyone clicks on that short code,
to which URL do you want to redirect them?
So, I want to redirect this particular page to my own
website. So this
is the default value that I want
me to see. So values of 100 out of 100 I
mean 100 out of 100, when you
click on all my short codes, it will
take you to this particular URL. And I
am ending the process. This is it
guys. After doing this, I now have to
run this shade again so that just a while ago it was
completely zero there.
Look carefully. Look here it is still zero. The
Moment I'll refresh now. And a okay
still nothing has happened. Alright guys we made
a mistake. Look,
I have got equal data here, I have got
equal data. Oh my God, I made a
mistake. Let me tell you what
mistake I made. We did
n't have to write the reset code because it
reset it first. Now
as soon as I reset, the data was gone. Isn't it? So I
go back here.
And I guess I saw this, yes,
look at this. That is what I was saying. Actually
we reset it first. That means my user
with ID one is gone. Now,
coming to the database, I mean it had created the data.
It has created 100% fake data
but that person is not even a user. I mean it was
already deleted. So just this
small mistake happened. So let me quickly
go here now. I will log out. Go back to
Log in with Google. I will log back in.
Ok? So obviously there will
be no tension now. I have already got it here. I will
refresh it once.
So now we have ID one. Ok? So now I will
run this, okay actually I did not have to run it, I had to run
npm run and then I had to run the db seed
and or this is it my work is done,
no tension, let me do npm run dep,
okay so I have not done anything
now I will refresh this at the moment and
boom guys see this, so now what we have,
we have 100 data over here I will go,
this is it. So, I have shown you all how easily
you can now create
fake data that looks absolutely realistic and exactly like the real thing.
This fake data also
depends on the schema of your table.
And it creates and gives you similar data.
So, isn't this so
awesome? And look again, look again, he has
given it for 2026. And I guess it is
giving you the same data by repeating it again and again.
So we don’t have any problem with
that. It just
became so easy for me to show the pagination to you people
where for 100 data
I can create 10 different pages.
Right? So ya guys this is it.
That's it for this video today. And
I want to see it once, if I refresh it.
Or the entire 100% data came to me here.
Isn't it? By the way we have already done the code.
That's why it came. But tomorrow
I only have to show 10 here. Do
n't show 100 all 100 at once. So this is where
pagination comes into play. So this is
how guys, one of your works leads to another.
Isn't it? But I hope today
you got to know about a new term called seed.
And how awesome is this. Basically, I
mean, whenever you are doing development or testing,
it is very useful there. And
how much time does it take for you to make 100 likes fake. But it has been done here in a jiffy.
So never forget this term and seed. It
creates fake data for you
so that you can do testing and
see whether the project you are creating is
correct or not. So guys,
first of all I would say that you should
check the playlist. You won't get anything better than this.
I have told you all this, you will
not get it anywhere else. Ok? So definitely check it out
and if you like the video then please like it. If you do
n't like it, please dislike it. Please do
give some feedback so that
I know whether you like my content
or not. Let us know by commenting if
you have any opinion. If you like the video then you
can write to Awesome Thapa. If you have any suggestions, you
can write them down. If you have
n't subscribed to the channel then please do so.
And don't forget to press the bell icon on the right side
so that
you don't miss such awesome videos and more
awesome videos are going to come in the future. Alright guys, I will
meet you in tomorrow's video. Till then guys
thank you so much. Take care.
[music]