BunJS MVC Framework Demonstration

PostgreSQL CRUD Demo

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

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

    
    
-- TO MAKE SAMPLE DATABASE AND TABLE

-- Create the database
CREATE DATABASE sample;

-- Create the books table
CREATE TABLE books (
    book_id SERIAL PRIMARY KEY,
    title VARCHAR(100) NOT NULL,
    author VARCHAR(100) NOT NULL,
    publication_year INTEGER 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 WITH PASSWORD 'dragonbone#R9';
GRANT CONNECT ON DATABASE sample TO sample;
GRANT SELECT, INSERT, UPDATE, DELETE ON books TO sample;
GRANT USAGE ON SEQUENCE books_book_id_seq TO sample;