create schema hw4;
create table hw4.cars (
id serial primary key,
model varchar(255) not null,
price int not null,
count int default 0
);
--
--
insert into hw4.cars(model,price,count) values
('BMW',10000,50),
('ROLLS ROYCE',20000,10),
('TOYOTA',8000,1000),
('MERCEDEZ',1000,40),
('SUPRA',12000,15);
select * from hw4.cars;
--user create
create table hw4.users(
id serial primary key,
fullname varchar(255),
balance int not null
);
insert into hw4.users(fullname,balance) values
('user1',100000),
('user2',200000),
('user3',80000),
('user4',10000),
('user5',120000);
-- first function...
create or replace function get_price_car(min_price int)
returns table(id int, model varchar(255), price int, count int)
language plpgsql
as
$$
begin
return query
select
c.id,
c.model,
c.price,
c.count from hw4.cars as c
where c.price > min_price order by price ASC;
end;
$$;
select * from get_price_car(8000);
-- second function...
create or replace function get_car_id(car_id int)
returns text
language plpgsql
as
$$
declare car_list text;
begin
select concat(
'id: ', c.id,
', model: ', c.model,
', price: ', c.price,
'. count: ', c.count)
into car_list
from hw4.cars as c
where c.id = car_id;
return car_list;
end;
$$;
select * from get_car_id(1);
--procedure
create or replace procedure buy_car(car_id int, car_count int, user_id int)
language plpgsql
as
$$
declare
car_price int;
car_count_available int;
user_balance int;
begin
select price, count into car_price, car_count_available
from hw4.cars
where id = car_id;
if car_price is null or car_count_available is null then
raise notice 'mashina topilmadi';
rollback;
return;
end if;
select balance into user_balance
from hw4.users
where id = user_id;
if user_balance is null then
raise notice 'foydalanuvchi topilmadi';
rollback;
return;
end if;
if user_balance < car_count * car_price then
raise notice 'foydalanuvchining balansida yetarli pul topilmadi';
rollback;
return;
end if;
if car_count_available < car_count then
raise notice 'mashinadan buncha emas';
rollback;
return;
end if;
update hw4.cars
set count = count - car_count
where id = car_id;
update hw4.users
set balance = balance - car_count * car_price
where id = user_id;
select balance into user_balance
from hw4.users
where id = user_id;
if user_balance < 5 then
raise notice 'foydalanuvchining balansida minimal summa 5 som dan kam';
rollback;
return;
end if;
commit;
raise notice 'buyurtma muvaffaqiyatli amalga oshirildi. % ta mashina sotib olindi', car_count;
end;
$$;
call buy_car(1,2,1);
π₯6π2π1π1π1π1
Kodingda try bor-u, lekin hayotingda catch ishlamayapti. Xatolarni toβgβrilash oβrniga, ularni "feature" deb nomlab qoβyayotgan backendchisan. Katta loyihalar qilishni orzu qilasan, lekin hozircha faqat res.send("Hello World") bilan yuribsan.
Sen oβzingni zoβr deb bilasan, lekin MongoDB'dagi dokumentlar sendan mustahkamroq qaror qabul qiladi. Frontendni yomon koβrasan, chunki sen qilgan API-larga hech kim request yubormaydi. Aslida esa backendchilar ham frontendchilar kabi "loading..." holatida yashaydi.
Xoβjayin, sen senior boβlishni orzu qilasan, lekin GitHub commitlaring "Initial commit" bilan tugagan. Agar sening dasturlash yoβlingni "ping" qilib tekshirsak, request timeout berib ketadi.
Lekin sendan yaxshi backendchi chiqadi!"π€£2π€·ββ1π1π₯1π1π1
Bu so'rovga nisbatan chatgpt javobi
Please open Telegram to view this post
VIEW IN TELEGRAM
π₯3π¨βπ»2β€βπ₯1π1
I'M_DEVELOPERπ¨βπ»
https://youtu.be/itkUJSYrg1U?si=Mdc0tFlSjPGui1jt
Assalomu alaykum ancha manfaatli boβldi hammaga ko'rishni tavsiya qilaman
π₯3π2π1π1
This media is not supported in your browser
VIEW IN TELEGRAM
π5π₯1π₯°1π1π1
Ramazon oyi barchamizga barokatli boβlsin.
Ramazon muborak yaqinlarimπ
Ramazon muborak yaqinlarim
Please open Telegram to view this post
VIEW IN TELEGRAM
π4π2β€1β€βπ₯1β‘1π₯°1π€©1π1π1π1
Qizig'i shu oy yaqinda yangi chiqgandida bugun to'lishga yaqin (#umr oβtyapti...) !
β‘4π₯1π1π1
Og'ir damlar koβpga bormaydi
Ammo og'ir damlar ichida qolgan bardoshli insonlar koβpga boradi
...)
Ammo og'ir damlar ichida qolgan bardoshli insonlar koβpga boradi
...)
π4π₯3β‘1π1
Media is too big
VIEW IN TELEGRAM
π₯3π1