CRUD app. Tech stack: java spring, thymeleaf, HTML, CSS, postgres, JDBC Template
CREATE TABLE people(
id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar(50) NOT NULL,
patronymic varchar(50) NOT NULL,
surname varchar(50) NOT NULL,
birthday date NOT NULL,
email varchar(50) NOT NULL UNIQUE,
);
CREATE TABLE books(
id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
"name" varchar(100) NOT NULL,
author varchar(100) NOT NULL,
date date NOT NULL,
person_id int DEFAULT NULL REFERENCES people(id) ON DELETE Set null ON UPDATE Cascade
);
INSERT INTO public.people(
name, patronymic, surname, birthday)
VALUES ('Виктор', 'Максимович', 'Шульпов', '14.07.2001'),
('Илья', 'Игоревич', 'Шинтяпин', '15.05.2001'),
('Максим', 'Владимирович', 'Иванов', '16.10.2000');
INSERT INTO public.books(
name, author, date)
VALUES ('Война и мир', 'Лев Толстой', '01.01.1862'),
('Отцы и дети', 'Иван Тургенев', '01.01.1868'),
('Старик и море', 'Эрнест Хемингуэй', '01.01.1952');
SELECT * FROM People;
SELECT * FROM Books;
SELECT * FROM People WHERE id=?;
SELECT * FROM Books WHERE id=?;
select p.id, p.name, p.patronymic, p.surname, p.birthday from people as p
join books as b
on p.id = b.person_id
where b.id = 4;
update people set name = ?, patronymic = ?, surname = ?, birthday = ?, email = ? where id = ?;
update books set name = ?, author = ?, date = ? where id = ?;
DELETE FROM People WHERE id = ?;
UPDATE Books SET person_id = NULL WHERE id = ?;
UPDATE Books SET person_id = ? WHERE id = ?;