Learn Node-SQLite
Learn how to interact with a SQL database from within your JavaScript programs in this course on the 'node-sqlite3' package.
StartKey Concepts
Review core concepts you need to learn to master this subject
sqlite3 Module
Creating/Connecting To A Database
db.get() Method
db.all() Method
db.each() Method
db.run() Method
db.serialize() Method
Handling Errors
sqlite3 Module
sqlite3 Module
//requiring the sqlite3 module
const sqlite3 = require('sqlite3');
Node.js and SQLite are separate entities, but both can be used together to create powerful applications. First, we need to link them together by requiring the sqlite3 module. Once we have required this module in our JavaScript, it will give us access to methods to perform various actions with the database.
Learn Node SQLite
Lesson 1 of 2
- 1One of the most essential skills as a programmer is being able to identify and utilize the appropriate tool for a specified task. In the context of database management, this will mean using SQL to …
- 2Throughout this lesson, we’re going to access an SQLite database with temperature data for countries over the last 150 years. We’re going to take this data, collect it per year in a JavaScript obje…
- 3In the previous exercise we were able to import the ‘sqlite3’ library and use that to open our SQLite database — so far so good! But we still haven’t retrieved any information from it. Since …
- 4db.all() is a useful tool to fetch all the data we have that meets certain criteria. But what if we only want to get a particular row? We could do something like this: db.all(“SELECT * FROM Dog”, …
- 5Now we know how to retrieve data from a database when we know exactly what we’re looking for. But we may not always know what values we will need to search for when writing our program. When we wri…
- 6Not all SQL commands return rows, and in fact, some essential SQL commands do not. If we INSERT a row or CREATE a TABLE we will not receive a row in response. To perform SQL commands that do not re…
- 7No one’s perfect. Code, like people, can make mistakes. This is OK! What’s important is that we learn how to handle our difficulties while keeping our composure. Handling errors is an important par…
- 8While learning JavaScript, you likely learned about the powerful method .forEach() that allows us to process every element in an array separately. Now we will use a similar method that will enable …
- 9So far we’ve managed to: 1. Query a database for weather records by location. 2. Reformat that data into a JavaScript object. 3. Manipulate that JavaScript object to find new, meaningful informati…
- 10By default, the commands we issue to our database run in parallel. Every request we make gets sent to the database — which processes them all as quickly as it can, regardless of the order i…
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory