A Javascript (Node.js) application with a MySQL database and Vue.js client application, bundled courtesy of npm and Webpack.
- Bootstrap type tools: http://yuche.github.io/vue-strap/
- Multiselect: https://github.com/monterail/vue-multiselect
There are two database models, Author and Book. Each is represented by a MySQL table.
-
name:string
-
bio:text
Has Many Books
-
name:string
-
isbn:integer
-
publication_date:date
-
description:text
-
author_id:integer
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 |
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
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.
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);