From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Setting up database with better-sqlite3

Setting up database with better-sqlite3

In the previous section, we learned the basics of SQLite database and also performed CRUD operations using the queries. In this section, we will connect the Next.js application with SQLite database and perform the CRUD operations. I am using SQLite because it is very light and fast. And at the same time, since it is serverless technology, we won't have to do any configurations as well. All right, so to operate a SQLite database from Next.js application, we need to have a database driver. Right now we will use the better SQLite 3 database driver to run the SQLite commands in the Next.js application. So let's install it, for which I'll open the terminal and write the command npm i better sqlite3. All right, now let's create the database and table using the driver. So first of all, we will have a file where we have the queries to initiate the database and create the tables for which I will create the initdb.js file in the root folder. Now inside it, to execute the queries, we need to…

Contents