Book Image

CoffeeScript Application Development Cookbook

By : Mike Hatfield
Book Image

CoffeeScript Application Development Cookbook

By: Mike Hatfield

Overview of this book

Table of Contents (18 chapters)
CoffeeScript Application Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Working with SQLite


SQLite is a lightweight, schema-based relational database engine that executes within the memory context of our application. This proves to be very convenient when developing your application, as SQLite does not require a database server.

Getting started

We will be using the sqlite3 Node module. You can install this module using NPM as follows:

$ npm install sqlite3

Once installed, you can require it in your application using the following:

sqlite = require 'sqlite3'

Once required, you can create a connection to an existing database by filename:

db = new sqlite3.Database('sample.db')

If the database does not exist, an empty database will be created for you.

We will be using a sample database for our examples, which contains a simple Employees and Departments table. We can see these tables in the following diagram:

Inserting and updating records, and executing commands

Now that we have an empty database, we will create our tables and insert some records.

We will use the Node sqlite3...