Giter Club home page Giter Club logo

sequelize-bookmarks's Introduction

Sequelize bookmarks application

A Javascript (Node.js) application with a MySQL database and Vue.js client application, bundled courtesy of npm and Webpack.

Vue tools

Models

There are two database models, Author and Book. Each is represented by a MySQL table.

Author

  • name:string

  • bio:text

Has Many Books

Book

  • name:string

  • isbn:integer

  • publication_date:date

  • description:text

  • author_id:integer

API Endpoints

All responses will be in JSON format.

The base url format for all endpoints is:

http://localhost:8000/api
Method URL Description
GET /authors get all the authors and all the books associated with all the authors
GET /authors/:id get an author by id and also get all the books associated with that author
POST /authors create a new author (name:string, bio:text)
PUT /authors update a new author (name:string, bio:text)
DELETE /authors delete author by passing given id field. Also deletes all books associated with that author
GET /books get all the books
GET /books/:id get a single book by passing id to params
POST /books create a new book (name:string, isbn:integer, publication_date:date, description:text, author_id:integer)
DELETE /books delete a book by passing id to params

Getting started

First clone the repo and change directories into it.

Workflow is run webpack to build out client side and node index or npm start to fire up the server. The app will run on localhost:8000

The webpack command will compile the javascripts and Vue templates into bundle.js that is in turn called by index.html. The next command will start the server and server index.html to the browser.

christianalfoni/webpack-express-boilerplate is a good example of a more advanced and integrated webpack-express build system #todo

Sequelize Notes

Below are some helper commands to get started and work around Sequelize and SQL databases with Javascript.

Define a model and migration in one command with Sequelize CLI:

$ sequelize model:create --name=Author --attributes name:string,bio:text --underscored

Run migrations (creates tables):

$ sequelize db:migrate

For seeding the initial database with Authors and Books, we use sequelize-fixtures.

MySQL helper commands

Log in to MySQL with password:

$ mysql -u root -p

Note to self: login creds are root/root for local machine

Reset the password if it needs updating:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'myNewPassword'

Create new user and give them all privileges:

mysql> CREATE USER 'admin'@'localhost';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Create a MySQL database:

CREATE DATABASE bookmarks;

Winning formula for database connection is:

new Sequelize('database_name', 'database_user', 'database_password', config);

sequelize-bookmarks's People

Contributors

connor11528 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.