Read Database Recordsλ︎
Using next.jdbc.sql
functions provides a Clojure data structures approach, where as next.jdbc/execute!
uses specific SQL statement code.
Generic read record functionλ︎
Use the generic create function from the database schema design section
(defn read-record
"Insert a single record into the database using a managed connection.
Arguments:
- table - name of database table to be affected
- record-data - Clojure data representing a new record
- db-spec - database specification to establish a connection"
[db-spec sql-query]
(with-open [connection (jdbc/get-connection db-spec)]
(jdbc-sql/query connection sql-query)))
Read account_holder recordsλ︎
Call the read-record
function with the development database specification and a Clojure vector containing a string of the SQL select statement.
Return all the records from a specific table
Return records that match a specific where clause
(read-record db-specification-dev ["select * from public.account_holders where first_name = ?" "Rachel"])
Read account recordsλ︎
Create a new record in the public.accounts
table.
Return all the records from a specific table
Return records that match a specific where clause
(read-record db-specification-dev ["select * from public.accounts where account_number = ?" "1234567890"])
Read transaction history recordsλ︎
Create a record in the public.transaction_history
table.
Return records that match a specific where clause
(read-record db-specification-dev ["select * from public.transaction_history where transaction_date = ?" "2020-09-11"])
Generating example data from Clojure Spec