CSCI 3342 Web Development
Spring 2024

Database and SQL

SQL Queries from JavaScript

Now back to the good part!
As mentioned, SQLite is not something that you install. There's no server to run like with bigger RDBMS. Instead, you install the driver for the language that you want to use, and that driver knows how to read/write from the SQLite database file. You then use the driver API in your code.
sqlite is a wrapper library that provides an async/await API on top of the sqlite3 driver for node.js. This is the interface that we will be using in this course, so bookmark the documentation for this library, not the underlying driver. Install it together with the driver in your project with:
npm install sqlite3 sqlite
Create a file dbtest.js in your repo working directory and follow the video below to connect to your db file and run the four types of SQL queries from code.

Running SQL Queries From JavaScript (19:05)

SELECT, INSERT, UPDATE, DELETE.
Additional resource: The module page for sqlite contains examples of various SQL queries, with their return values documented.

Assignment Checklist

Add sqlite to your project
Connect to the database file from code in your dbtest.js
Execute the four SQL queries and display the data in your dbtest.js (leave all the queries in the file! comment them out as needed.)