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.

Rendering data in next app

Rendering data in next app

Now that you know how we execute queries programmatically using the Better SQLite 3 driver, let's try to fetch the data from the database and render it in the products page of the next app. So let me open the page js of the products folder. Now to make a query, we need to have the database reference. So let's import the driver by saying const sqlite is equal to require better sqlite3. And take an instance that points to the products database, I'll say const db is equal to sqlite products.sqlite. All right, now let's configure the select star from query. So first I'll take a constant, which will store the received data. First products is equal to db.prepare select star from products. And since we are fetching the data, we'll use the dot all method. And finally, let's display the products in the console. Let's save and check. I'll go back to code window and open the terminal. And there we have the product data displayed. Now let's display the same data in place of the users data that we…

Contents