Skip to content

Instantly share code, notes, and snippets.

View ashafa's full-sized avatar

Tunde Ashafa ashafa

View GitHub Profile
;; I want to be able to do something like this...
(defdbtest has-and-belongs-to-many-creates-find-functions
(let [humedai (manufacturer/create (valid-manufacturer-with {:name "Humedai Automotive"}))
s3000xi (product/create {:name "S-3000xi" :manufacturer_id (:id humedai)})
s3000xl (product/create {:name "S-3000xl" :manufacturer_id (:id humedai)})
chambars (dealer/create {:name "Chambers Motors"})
ira (dealer/create {:name "IRA Autos"})
tundre (dealer/create {:name "Tundre Automotives"})]
(dealer/insert-relationship chambars (:id s3000xi))
(ns clj-record.query
(:require [clojure.contrib.str-utils :as str-utils]))
(defn- clause-and-parameters [join-with values]
[(str-utils/str-join join-with (reduce (fn [v1 v2] (conj v1 (if (nil? v2) "NULL" "?"))) [] values)) (filter (complement nil?) values)])
(defn between [value1 value2]
(fn [attribute]
(let [[clause parameters] (clause-and-parameters " AND " [value1 value2])]