Last active
July 11, 2018 16:57
-
-
Save gdeer81/5470227 to your computer and use it in GitHub Desktop.
an example of updating an oracle database from clojure the server, user names, and passwords have been changed to protect the innocent
This file contains hidden or 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
(ns db-test.core | |
(:require [clojure.java.jdbc :as j]) | |
(use [korma.db]) | |
(use [korma.core]) | |
(:gen-class)) | |
(defn setup-connection [] | |
(def oracle-db {:classname "oracle.jdbc.odbc.OracleDriver" | |
:subprotocol "oracle" | |
:subname "thin:@//remotehost:1521/derpina1" | |
:user "user" | |
:password "pass" }) | |
(j/get-connection oracle-db) | |
(default-connection oracle-db) | |
(defentity PGDV_REPAIR)) | |
(def records (select PGDV_REPAIR (fields :PROD_ID :RETAIL :GOTO_RETAIL) (where {:REPAIR_ID [in [2 5]]}))) | |
(defn alter-goto-repair [] | |
(doseq [row records] | |
(update PGDV_REPAIR | |
(set-fields {:GOTO_RETAIL (+ (rand-int 100) (:RETAIL row))}) | |
(where {:REPAIR_ID [in [2 5]]}) | |
(where {:PROD_ID (:PROD_ID row)})))) | |
(defn -main | |
"This function is where all the functions in this namespace come together" | |
[& args] | |
(setup-connection) | |
(alter-goto-repair)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment