summaryrefslogtreecommitdiff
path: root/test/clojure_sql/core_test.clj
blob: b5d65e7710bce70b5ea6f19dabe39ae7851590f9 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
(ns clojure-sql.core-test
  (:refer-clojure :exclude [sort-by])
  (:require [clojure-sql.core :refer :all]
            [midje.sweet :refer :all]))

(fact
  @(table :user)
  => ["SELECT * FROM \"user\""]
  
  @(-> (table :user) (select '(= :username "george")))
  => ["SELECT * FROM \"user\" WHERE (\"user\".\"username\" = ?)" "george"]

  @(-> (table :user) (project {:username :u}))
  => ["SELECT \"user\".\"username\" AS \"u\" FROM \"user\""]

  @(-> (table :user) (project {'(+ :username :password) :u}))
  => ["SELECT (\"user\".\"username\" + \"user\".\"password\") AS \"u\" FROM \"user\""])

(into {} (-> (table :user) (project '{(+ :username :password) :u})))

(-> (table {(-> (table :users)
                (project '[:username (+ 1 2 3)])
                (rename '{(+ 1 2 3) :x})
                (select `(exists ~(table :users)))) :u})
    println)