Last active
April 25, 2017 15:58
-
-
Save AlJohri/63a7e6b39fb37661f5441242361894cb to your computer and use it in GitHub Desktop.
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
| ; https://github.com/r0man/sqlingvo/issues/75 | |
| (ns my-proj.core | |
| (:gen-class) | |
| (:require [clojure.string :as str] | |
| [sqlingvo.core :as sql] | |
| [sqlingvo.util :refer [sql-quote-backtick]] | |
| [sqlingvo.compiler :refer | |
| [defarity compile-2-ary | |
| compile-fn concat-sql compile-sql-join | |
| compile-expr]])) | |
| (defn underscore [s] | |
| (str/replace (name s) "-" "_")) | |
| (def my-db (sql/db :postgresql {:sql-name underscore})) | |
| (defmethod compile-fn :-> [db node] | |
| (let [[name & args] (:children node)] | |
| (assert (< 1 (count args)) "More than 1 arg needed.") | |
| (->> (map (fn [[arg-1 & arg-rest]] | |
| (concat-sql "(" | |
| (apply str (interpose (clojure.core/name (:val name)) (concat (compile-expr db arg-1) (->> arg-rest (map :val) (map clojure.core/name) (map #(str "'" % "'")))))) | |
| ")" )) | |
| (partition (count args) 1 args))))) | |
| (defn -main | |
| "I don't do a whole lot ... yet." | |
| [& args] | |
| (println (sql/select my-db [`(~(keyword "@>") [1 2] [3 4])] | |
| (sql/from :articles) | |
| (sql/limit 1))) | |
| (println (sql/select my-db [`(~(keyword "->") :original :meta :headline)] | |
| (sql/from :articles) | |
| (sql/limit 1))) | |
| ; doesn't work: | |
| ; (println (sql/select my-db [(sql/as '(`(~(keyword "->") :original :meta :headline)) :headline)] | |
| ; (sql/from :articles) | |
| ; (sql/limit 1))) | |
| (println "Done!")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment