Commit bd12ad62 authored by Johannes Knödtel's avatar Johannes Knödtel 🎶
Browse files

split up sql queries into different files

parent 66e08da2
-- :name delete-order! :!
-- :doc deletes an order
DELETE FROM
food
WHERE
session = :session
AND
food_name = :food_name
AND
comment = :comment
AND
customer = :customer;
-- :name truncate-food! :!
-- :doc cleans the food table
DELETE FROM TABLE
food
WHERE
session = :session;
-- :name truncate-prices! :!
-- :doc cleans the prices table
DELETE FROM TABLE
prices
WHERE
session = :session;
-- :name create-session<! :i!
-- :doc generate new session
INSERT INTO
sessions
(name)
VALUES
(:name);
-- :name add-food! :!
-- :doc add food-request
INSERT INTO
food
(session,
food_name,
comment,
customer,
quantity)
VALUES
(:session,
:food_name,
:comment,
:customer,
:quantity)
ON DUPLICATE KEY UPDATE
quantity = :quantity;
-- :name add-price! :!
-- :doc add prices
INSERT INTO
prices
(session,
food_name,
comment,
ammount_per_package,
number_of_packages,
package_price)
VALUES
(:session,
:food_name,
:comment,
:ammount_per_package,
:number_of_packages,
:package_price);
-- :name pay! :!
-- :doc gets the names of all customers that already paid their bill
INSERT INTO payments
(session,
customer)
VALUES
(:session,
:customer)
-- H2 doesn't know IGNORE, so we will work around that like this.
ON DUPLICATE KEY UPDATE
customer = :customer;
-- :name add-food! :!
-- :doc add food-request
INSERT INTO food
(session, food_name, comment, customer, quantity)
VALUES (:session, :food_name, :comment, :customer, :quantity)
ON DUPLICATE KEY UPDATE quantity = :quantity;
-- :name add-price! :!
-- :doc add prices
INSERT INTO prices
(session, food_name, comment, ammount_per_package, number_of_packages, package_price)
VALUES (:session, :food_name, :comment, :ammount_per_package, :number_of_packages, :package_price);
-- :name delete-order! :!
-- :doc deletes an order
DELETE FROM food
WHERE
session = :session
AND
food_name = :food_name
AND
comment = :comment
AND
customer = :customer;
-- :name edit-order! :!
-- :doc edits an order
UPDATE food
SET
food_name = :food_name,
comment = :comment,
customer = :customer,
quantity = :quantity
WHERE
food_name = :old_food_name
AND
comment = :old_comment
AND
customer = :old_customer;
-- :name get-food :? :*
-- :doc retrive all food orders
SELECT
food_name, comment, customer, quantity
FROM
food
WHERE
session = :session
ORDER BY
food_name ASC,
comment ASC;
-- :name get-sessions :? :*
-- :doc retrives all sessions with names and ids
SELECT
id, name, locked
id,
name,
locked
FROM
sessions
ORDER BY
......@@ -68,56 +18,20 @@ FROM
WHERE
id = :session;
-- :name lock-session! :!
-- :doc locks the session
UPDATE
sessions
SET
locked = true
WHERE
id = :session;
-- :name unlock-session! :!
-- :doc unlocks the session
UPDATE
sessions
SET
locked = false
WHERE
id = :session;
-- :name create-session<! :i!
-- :doc generate new session
INSERT INTO sessions
(name)
VALUES (:name);
-- :name truncate-food! :!
-- :doc cleans the food table
DELETE FROM TABLE food
WHERE session = :session;
-- :name truncate-prices! :!
-- :doc cleans the prices table
DELETE FROM TABLE prices
WHERE session = :session;
-- :name get-already-paid :? :*
-- :doc gets the names of all customers that already paid their bill
-- :name get-food :? :*
-- :doc retrive all food orders
SELECT
customer
food_name,
comment,
customer,
quantity
FROM
payments
food
WHERE
session = :session;
-- :name pay! :!
-- :doc gets the names of all customers that already paid their bill
INSERT INTO payments
(session, customer)
VALUES (:session, :customer)
-- H2 doesn't know IGNORE, so we will work around that like this.
ON DUPLICATE KEY UPDATE customer = :customer;
session = :session
ORDER BY
food_name ASC,
comment ASC;
-- :name get-summed-food-numbers :? :*
-- :doc cleans the list
......@@ -198,3 +112,12 @@ WHERE
food.session = :session
GROUP BY
food.food_name, food.comment, food.customer;
-- :name get-already-paid :? :*
-- :doc gets the names of all customers that already paid their bill
SELECT
customer
FROM
payments
WHERE
session = :session;
-- :name lock-session! :!
-- :doc locks the session
UPDATE
sessions
SET
locked = true
WHERE
id = :session;
-- :name unlock-session! :!
-- :doc unlocks the session
UPDATE
sessions
SET
locked = false
WHERE
id = :session;
-- :name edit-order! :!
-- :doc edits an order
UPDATE
food
SET
food_name = :food_name,
comment = :comment,
customer = :customer,
quantity = :quantity
WHERE
food_name = :old_food_name
AND
comment = :old_comment
AND
customer = :old_customer;
......@@ -7,7 +7,10 @@
(defonce conn (atom nil))
(conman/bind-connection conn "sql/queries.sql")
(conman/bind-connection conn "sql/inserting.sql")
(conman/bind-connection conn "sql/updating.sql")
(conman/bind-connection conn "sql/reading.sql")
(conman/bind-connection conn "sql/deleting.sql")
(defn connect! []
(reset! conn (conman/connect! {:jdbc-url (:database-url env)})))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment