Created
September 10, 2013 08:53
-
-
Save neotyk/6506738 to your computer and use it in GitHub Desktop.
Hack to make Korma select for update
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 korma-for-update | |
(:require [clojure.test :refer :all] | |
[korma.core :refer [entity-fields defentity select* as-sql exec-raw]] | |
[korma.db :refer (postgres defdb)])) | |
;; TODO: use your local db | |
(defdb local (postgres {:db "neotyk" | |
:user "neotyk" | |
:host "localhost" | |
:password ""})) | |
;; on psql: | |
;; neotyk=# create table t1 (id serial primary key, v varchar(8)); | |
(defentity t1 (entity-fields :id :v)) | |
;; Populate test data at psql: | |
;; neotyk=# insert into t1 (v) values ('boo'); | |
(deftest a-test | |
(testing "select for update" | |
;; assuming that on psql: | |
;; neotyk=# select * from t1; | |
;; id | v | |
;; ----+----- | |
;; 1 | boo | |
;; (1 row) | |
(is (= [{:v "boo" :id 1}] | |
(-> (select* t1) | |
(#(str (as-sql %) " for update")) | |
(exec-raw :results)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment