项目作者: amandalatkins

项目描述 :
Organization for your to-read pile!
高级语言: JavaScript
项目地址: git://github.com/amandalatkins/bookworm.git
创建时间: 2020-01-20T00:55:14Z
项目社区:https://github.com/amandalatkins/bookworm

开源协议:

下载


BookWorm

Are you a book lover? Is your To-Read pile unweildy? BookWorm is here to help! This app allows you to search books via IndieBound.org (support your local bookstore!) and then add them to your “To Read” list 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:

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

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

  1. touch .env

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

  1. DB_HOST=localhost
  2. DB_PORT=3306
  3. DB_USER=username
  4. DB_PASS=password
  5. DB_NAME=bookworm

Import the database schema and optional demo data:

  1. #login to mysql
  2. mysql -u username -p
  3. #import the required schema
  4. source db/schema.sql
  5. #import the optional demo data
  6. source db/seeds.sql

Start the application by using the following command:

  1. 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:

  1. const db = require('./connection.js');
  2. module.exports = {
  3. selectAll: (tableName,callback) => {
  4. db.query("SELECT * FROM ??",[tableName],(err, res) => {
  5. if (err) throw err;
  6. callback(res);
  7. });
  8. },
  9. insertOne: (tableName,newData,callback) => {
  10. db.query("INSERT INTO ?? SET ?",[tableName,newData], (err, res) => {
  11. if (err) throw err;
  12. callback(res);
  13. });
  14. },
  15. updateOne: (tableName,newData,condition,callback) => {
  16. db.query("UPDATE ?? SET ? WHERE ?",[tableName,newData,condition], function(err,res) {
  17. if (err) throw err;
  18. callback(res);
  19. });
  20. },
  21. deleteOne: (tableName,condition,callback) => {
  22. db.query("DELETE FROM ?? WHERE ?",[tableName,condition],(err,res) => {
  23. if (err) throw err;
  24. callback(res);
  25. });
  26. }
  27. }

And the Book model built using the custom ORM:

  1. const orm = require('../config/orm.js');
  2. module.exports = {
  3. all: cb => orm.selectAll("books",res => cb(res)),
  4. create: (data, cb) => orm.insertOne("books",data,res => cb(res)),
  5. update: (data,condition,cb) => orm.updateOne("books",data,condition,res => cb(res)),
  6. delete: (condition, cb) => orm.deleteOne("books",condition,res => cb(res))
  7. };

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.
  • Learned how to scrape data from sites and use Cheerio to run jQuery commands to manipulate DOM elements in Node

Built With

Authors

Amanda Atkins

License

This project is licensed under the ISC License.