Skip to content
Organization for your to-read pile!
HTML JavaScript CSS TSQL
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
controllers
db
models
public/assets
views
.gitignore
README.md
package-lock.json
package.json
server.js

README.md

BookWorm

Are you a book lover? Is your To-Read pile unweildy? BookWorm is here to help! This app allows you to store book titles and links to more information so you can get organized and get reading. Once you've read a book, just click "I Read It!", and it will move to your "Done" list where you can watch your finished books pile up! It doesn't end there-- If you loved the book you can always click "Read Again" to move it back to your To-Read Pile; if you hated it, click "Delete" as your first step to forgetting it forever!

Screenshots

No Finished Books With Finished Books

Try it Out!

Click here to try the demo!

Installation Your Own Instance

Prerequisites

Instructions

Run the following commands in your preferred CLI to install the Node package and all dependencies:

git clone https://github.com/amandalatkins/bookworm.git
cd bookworm
npm i

Create a new file called .env that will store your MySQL server information:

touch .env

Format the contents of .env as follows, substituting your MySQL server information where applicable:

DB_HOST=localhost
DB_PORT=3306
DB_USER=username
DB_PASS=password
DB_NAME=bookworm

Import the database schema and optional demo data:

#login to mysql
mysql -u username -p

#import the required schema
source db/schema.sql

#import the optional demo data
source db/seeds.sql

Start the application by using the following command:

npm start

Open the application in your preferred web browser by visiting http://localhost:3000. Enjoy!

Technical Information

Code Snippets

The following code snippet shows the custom Object Relational Mapper (ORM) built for BookWorm:

const db = require('./connection.js');

module.exports = {
    selectAll: (tableName,callback) => {
        db.query("SELECT * FROM ??",[tableName],(err, res) => {
            if (err) throw err;
            callback(res);
        });
    },
    insertOne: (tableName,newData,callback) => {
        db.query("INSERT INTO ?? SET ?",[tableName,newData], (err, res) => {
            if (err) throw err;
            callback(res);
        });
    },
    updateOne: (tableName,newData,condition,callback) => {
        db.query("UPDATE ?? SET ? WHERE ?",[tableName,newData,condition], function(err,res) {
            if (err) throw err;
            callback(res);
        });
    },
    deleteOne: (tableName,condition,callback) => {
        db.query("DELETE FROM ?? WHERE ?",[tableName,condition],(err,res) => {
            if (err) throw err;
            callback(res);
        });
    }
}

And the Book model built using the custom ORM:

const orm = require('../config/orm.js');

module.exports = {
    all: cb => orm.selectAll("books",res => cb(res)),
    create: (data, cb) => orm.insertOne("books",data,res => cb(res)),
    update: (data,condition,cb) => orm.updateOne("books",data,condition,res => cb(res)),
    delete: (condition, cb) => orm.deleteOne("books",condition,res => cb(res))
};

Learning Points:

  • The practice of creating my own ORM helped me understand how ORM packages work in their simplest form, as well as helped me learn best practices for implementing them.
  • Great practice working with a Model-View-Controller design pattern and architecting my application with those principles in mind.

Built With

Authors

Amanda Atkins

License

This project is licensed under the ISC License.

You can’t perform that action at this time.