aleeusgr / hs-clojure

Other
0 stars 0 forks source link

API #14

Closed aleeusgr closed 3 months ago

aleeusgr commented 3 months ago

closes #5 closes #3 closes #8

aleeusgr commented 3 months ago

https://bowlofcode.com/building-a-clojure-web-app-backed-by-postgres/

aleeusgr commented 3 months ago

testing


lein repl 

user=> (require '[hs-clojure.db :as db]) 
nil 
user=> (require '[clojure.java.jdbc :as j]) 
nil 
user=> (j/db-do-commands db/spec "create table test (name varchar)") 
(0) 
user=> (j/insert! db/spec :test {:name "Testing database connection"}) 
({:name "Testing database connection"}) 
user=> (j/query db/spec "select * from test") 
({:name "Testing database connection"}) 
user=> (j/db-do-commands db/spec "drop table test") 
(0)
``
aleeusgr commented 3 months ago
user=> (require '[hs-clojure.db :as db] '[hs-clojure.db.patients :as db-patients])
nil
user=> (db-patients/create-patients-table db/spec)
[0]
(db-patients/insert-patient db/spec {:name "John Doe" :sex "Male" :date_of_birth (java.sql.Date/valueOf "1990-01-01") :address "123 Main St" :social_security_number "123456789"})
1
user=> (db-patients/get-patient-by-name-like db/spec {:name-like "John%"})
({:id 1, :name "John Doe", :sex "Male", :date_of_birth #inst "1990-01-01T00:00:00.000-00:00", :address "123 Main St", :social_security_number "123456789", :created_at #inst "2023-02-20T14:30:00.000-00:00"})
user=> (db-patients/drop-patients-table db/spec)
[0]
aleeusgr commented 3 months ago

tests:

user=> (require '[hs-clojure.patients :as patients])
nil
user=> (patients/add-patient "John Doe" "Male" "1990-01-01" "123 Main St" "123-45-6789")
{:id 1, :name "John Doe", ...}
user=> (patients/get-patient-by-id 1)
{:id 1, :name "John Doe", ...}
user=> (patients/get-patient "John Doe")
({:id 1, :name "John Doe", ...})
user=> (patients/get-all-patients)
({:id 1, :name "John Doe", ...})
user=> (patients/update-patient 1 "Jane Doe" "Female" "1990-01-01" "456 Elm St" "987-65-4321")
{:id 1, :name "Jane Doe", ...}
user=> (patients/get-patient-by-id 1)
{:id 1, :name "Jane Doe", ...}
user=> (patients/delete-patient 1)
nil
user=> (patients/get-patient-by-id 1)
nil
aleeusgr commented 3 months ago

1

aleeusgr commented 3 months ago

https://github.com/aleeusgr/hs-clojure/issues/10