Skip to content

Plain T SQL for coffeeshop domain

Thang Chung edited this page May 31, 2023 · 1 revision

get order by id

SELECT o.id, o.created, o.location, o.loyalty_member_id, o.order_source, o.order_status, o.updated
FROM "order".orders AS o
WHERE o.order_status = 2
ORDER BY o.id

create order in counter

counter

INSERT INTO "order".orders (id, created, location, loyalty_member_id, order_source, order_status, updated)
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6);
INSERT INTO "order".line_items (id, created, is_barista_order, item_status, item_type, name, order_id, price, updated)
VALUES (@p7, @p8, @p9, @p10, @p11, @p12, @p13, @p14, @p15);
INSERT INTO "order".line_items (id, created, is_barista_order, item_status, item_type, name, order_id, price, updated)
VALUES (@p16, @p17, @p18, @p19, @p20, @p21, @p22, @p23, @p24);
INSERT INTO "order".line_items (id, created, is_barista_order, item_status, item_type, name, order_id, price, updated)
VALUES (@p25, @p26, @p27, @p28, @p29, @p30, @p31, @p32, @p33);

kitchen

INSERT INTO kitchen.kitchen_orders (id, created, item_name, item_type, order_id, time_up, updated)
VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6);

barista

INSERT INTO barista.barista_orders (id, created, item_name, item_type, time_up, updated)
VALUES (@p0, @p1, @p2, @p3, @p4, @p5);

get order by id

counter

SELECT o.id, o.created, o.location, o.loyalty_member_id, o.order_source, o.order_status, o.updated
FROM "order".orders AS o
WHERE o.id = @___id_0
ORDER BY o.id
LIMIT 1

get order line item by order id

counter

SELECT l.id, l.created, l.is_barista_order, l.item_status, l.item_type, l.name, l.order_id, l.price, l.updated, t.id
FROM (
    SELECT o.id
    FROM "order".orders AS o
    WHERE o.id = @___id_0
    LIMIT 1
) AS t
INNER JOIN "order".line_items AS l ON t.id = l.order_id
ORDER BY t.id

update status for order line id

counter

UPDATE "order".line_items SET item_status = @p0
WHERE id = @p1;
UPDATE "order".orders SET created = @p2, location = @p3, loyalty_member_id = @p4, order_source = @p5, order_status = @p6, updated = @p7
WHERE id = @p8;