For this I will again be using the n(.) method in conjunction with new delete methods for both the ProjectRepository and TaskRepository classes.įor ProjectRepository this looks like this: // project_repository. The last mutational functionality to implement is to provide the ability to delete records from the database. This.db = new sqlite3.Database(dbFilePath, ( err) => = task dao.js const sqlite3 = require( 'sqlite3') After that I will scaffold out a data access class called AppDAO that will establish a connection to the database inside a constructor and assign it to a member field called db. Inside dao.js I will add a imports for sqlite3 and Bluebird's Promise objects. To start I will need to make a main.js file along with a dao.js (or Data Access Object) file in the same directory as the package.json file. Ok, now that I know what I need to create I can now translate that into code. For the rest I will just use a little intuition, some made up test data, and roll with it (a common work characteristic for most developers). It is clear that I will need a projects table as well as a tasks table. With the business rules stated I can take that info and start designing the necessary tables and their fields. Each project can have one or more tasks to complete.The basic business rules for this application's data access layer are as follows: This has multiple regions all over the world so you can get your data. For this article I am going with the assumption that I am building out the data access layer for a project and task tracking application. In this tutorial, well be deploying our Node.js app and our SQLite database on fly.io. Designing the DatabaseĪs with almost every one of my other articles I will be using a made up application to help describe some of the important aspects of database programming with Node.js and SQLite. I now will create an empty file right next to the package.json file called database.sqlite3 that SQLite will store data in. In addition to sqlite3 I am going to install Bluebird so that I can use the familiar promise functionality in my database programming. Next I will need to install sqlite3 package via npm like so: $ npm install -save sqlite3 "test": "echo \"Error: no test specified\"
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |