Learn Node SQLite

Creating A New Table

So 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 information.

That's pretty significant! Now it's time to take that useful information and add it to a table of our own. Since creating a table is another operation that does not return a row, we can use the same db.run() we used to INSERT rows. Let's see what happens when we CREATE a TABLE and INSERT our data into it.

Notice there's a statement declaring "DROP TABLE IF EXISTS" — this is because we want to make sure when we create our new table that we won't run into an error telling us the table already exists (from previous times running our code).

Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.