O'Reilly logo

Node Web Development - Second Edition by David Herron

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Storing notes in SQL – SQLite3

To get started with actual databases let's look at using SQL from Node. First we'll use SQLite3, a lightweight, simple-to-set-up, database engine eminently suitable for many applications. To learn about that database engine see http://www.sqlite.org/.

The primary advantage of SQLite3 is it doesn't require a server, but is a self-contained, no-setup-required SQL database.

Setting up a schema with SQLite3

The first step is to make sure our database is configured. We're using this SQL table definition for the schema:

CREATE TABLE IF NOT EXISTS notes (
    notekey VARCHAR(255),
    title   VARCHAR(255),
    author  VARCHAR(255),
    body    TEXT
);

To set this up we need to run the sqlite3 command. To do so we need to first install the sqlite3 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required