-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
332 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
(ns rango-graalvm.db.postgresql.reservation | ||
(:require [pg.core :as pg] | ||
[pg.pool :as pool] | ||
[rango-graalvm.adapters.reservation :as adapters.reservation] | ||
[rango-graalvm.models.reservation :as models.reservation] | ||
[schema.core :as s])) | ||
|
||
(s/defn insert! :- models.reservation/Reservation | ||
[{:reservation/keys [id student-id menu-id created-at]} :- models.reservation/Reservation | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(-> (pg/execute database-conn | ||
"INSERT INTO reservations (id, student_id, menu_id, created_at) VALUES ($1, $2, $3, $4) | ||
returning *" | ||
{:params [id student-id menu-id created-at]}) | ||
first | ||
adapters.reservation/postgresql->internal))) | ||
|
||
(s/defn by-menu :- [models.reservation/Reservation] | ||
[menu-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT * FROM reservations WHERE menu_id = $1" | ||
{:params [menu-id]}) | ||
(->> (map adapters.reservation/postgresql->internal))))) | ||
|
||
(s/defn lookup :- (s/maybe models.reservation/Reservation) | ||
[reservation-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT * FROM reservations WHERE id = $1" | ||
{:params [reservation-id]}) | ||
first | ||
adapters.reservation/postgresql->internal))) | ||
|
||
(s/defn lookup-by-student-and-menu :- (s/maybe models.reservation/Reservation) | ||
[student-id :- s/Uuid | ||
menu-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT * FROM reservations WHERE menu_id = $1 AND student_id = $2" | ||
{:params [menu-id student-id]}) | ||
first | ||
adapters.reservation/postgresql->internal))) | ||
|
||
(s/defn retract! | ||
[reservation-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(pg/execute database-conn | ||
"DELETE FROM reservations WHERE id = $1" | ||
{:params [reservation-id]}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
(ns rango-graalvm.db.postgresql.student | ||
(:require [camel-snake-kebab.core :as csk] | ||
[pg.core :as pg] | ||
[pg.pool :as pool] | ||
[rango-graalvm.adapters.student :as adapters.student] | ||
[rango-graalvm.models.sudent :as models.student] | ||
[schema.core :as s])) | ||
|
||
(s/defn insert! :- models.student/Student | ||
[{:student/keys [id code name class created-at]} :- models.student/Student | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(-> (pg/execute database-conn | ||
"INSERT INTO students (id, code, name, class, created_at) VALUES ($1, $2, $3, $4, $5) | ||
returning *" | ||
{:params [id code name (csk/->snake_case_string class) created-at]}) | ||
first | ||
adapters.student/postgresql->internal))) | ||
|
||
(s/defn lookup-by-code :- (s/maybe models.student/Student) | ||
[code :- s/Str | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT * FROM students WHERE code = $1" | ||
{:params [code]}) | ||
first | ||
adapters.student/postgresql->internal))) | ||
|
||
(s/defn all :- [models.student/Student] | ||
[postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT * FROM students") | ||
(->> (map adapters.student/postgresql->internal))))) | ||
|
||
(s/defn by-menu-reservation :- [models.student/Student] | ||
[menu-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(some-> (pg/execute database-conn | ||
"SELECT students.* | ||
FROM students | ||
JOIN reservations ON students.id = reservations.student_id | ||
WHERE | ||
reservations.menu_id = $1 | ||
ORDER BY students.class" | ||
{:params [menu-id]}) | ||
(->> (map adapters.student/postgresql->internal))))) | ||
|
||
(s/defn retract! | ||
[student-id :- s/Uuid | ||
postgresql-pool] | ||
(pool/with-connection [database-conn postgresql-pool] | ||
(pg/execute database-conn | ||
"DELETE FROM students WHERE id = $1" | ||
{:params [student-id]}))) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.