BunJS MVC Framework Demonstration

MySQL CRUD Demo

Book IdTitleAuthorPublication YearGenreTarget AgeIsbn
1Charlotte's WebE.B. White1952Fiction8-129780064400558
2The Cat in the HatDr. Seuss1957Fiction4-89780394800011
3Winnie-the-PoohA.A. Milne1926Fiction6-109780142404676
5Where the Wild Things AreMaurice Sendak1963Fiction4-89780064431781
41The Lion, the Witch and the WardrobeC.S. Lewis1950Fantasy8-128888888888888

Look in the controllers/mysql/crud-demo.js and models/mysql.js for how the SELECT, INSERT, UPDATE, and DELETE were done.

	
	
-- TO MAKE SAMPLE DATABASE AND TABLE

-- Create the database
CREATE DATABASE sample;

-- Use the sample database
USE sample;

-- Create the books table
CREATE TABLE books (
    book_id INT AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(100) NOT NULL,
    author VARCHAR(100) NOT NULL,
    publication_year INT NOT NULL,
    genre VARCHAR(50),
    target_age VARCHAR(20),
    isbn VARCHAR(13)
);

-- Insert 5 famous children's books published before 1968
INSERT INTO books (title, author, publication_year, genre, target_age, isbn) VALUES
('Charlotte''s Web', 'E.B. White', 1952, 'Fiction', '8-12', '9780064400558'),
('The Cat in the Hat', 'Dr. Seuss', 1957, 'Fiction', '4-8', '9780394800011'),
('Winnie-the-Pooh', 'A.A. Milne', 1926, 'Fiction', '6-10', '9780142404676'),
('The Lion, the Witch and the Wardrobe', 'C.S. Lewis', 1950, 'Fantasy', '8-12', '9780064404990'),
('Where the Wild Things Are', 'Maurice Sendak', 1963, 'Fiction', '4-8', '9780064431781');

-- Create authorized user
CREATE USER 'sample'@'localhost' IDENTIFIED BY 'dragonbone#R9';
GRANT SELECT, INSERT, UPDATE, DELETE ON sample.* TO 'sample'@'localhost';
FLUSH PRIVILEGES;