Video Pending

Created by Zed A. Shaw Updated 2024-02-15 03:22:43

07: Access a SQLite3 Database

You'll now learn the basics of a project named knex.js to access a SQLite3. You'll need to create a database for the next exercise that stores TODO lists, so you might want to check out the next exercise to get an idea of where this database is going.

Step 1: Migrations

To do this you'll first need to learn how to create a migration that creates your database. The documentation for migrations is in the knex.js migrations documentation. You're specifically looking at how to use createTable and dropTable in a migration.

Your TODO list table should have the following fields:

  1. id - the primary id for the row. Use table.increments('id') to do this.
  2. updated_at and created_at -- you can use table.timestamps(true, true) to automatically generate these.
  3. completed -- This is a boolean value, but you'll find that booleans are weird in SQLite3 and are treated as integers.
  4. description -- The actual text for the TODO item.

Once you have these think about other things you want in a TODO list and add them too. You don't need to keep making migrations for every change, just rollback this one, update it, and add more.

Previous Lesson Next Lesson

Register for Learn JavaScript the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.