Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nivekuil committed Sep 11, 2022
1 parent c5199c8 commit bf49fc9
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions test/qbits/alia_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@
PRIMARY KEY (id)
);")

(alia/execute session "CREATE TABLE IF NOT EXISTS namespaced (
\"namespaced/id\" int,
\"namespaced/text\" varchar,
PRIMARY KEY (\"namespaced/id\")
);")

(alia/execute session "CREATE TABLE IF NOT EXISTS reserved (
\"view\" int,
\"all\" varchar,
PRIMARY KEY (\"view\")
);")

(alia/execute session "CREATE TABLE IF NOT EXISTS blobs (id uuid, data blob, PRIMARY KEY (id));"))

(defn teardown-test-keyspace
Expand Down Expand Up @@ -488,6 +500,43 @@
(alia/execute *session* "SELECT * FROM simple WHERE id = :id;"
{:values {:id an-id}})))))

(testing "reserved-names"
(let [prep-write (alia/prepare *session* "INSERT INTO reserved (\"view\", \"all\") VALUES(:\"view\", :\"all\");")
prep-read (alia/prepare *session* "SELECT * FROM reserved WHERE \"view\" = :\"view\";")
an-id (int 100)]

(is (= nil
(alia/execute *session* prep-write {:values {:view an-id
:all "inserted via reserved bindings"}})))

(is (= [{:view an-id
:all "inserted via reserved bindings"}]
(alia/execute *session* prep-read {:values {:view an-id}})))

(is (= [{:view an-id
:all "inserted via reserved bindings"}]
(alia/execute *session* "SELECT * FROM reserved WHERE \"view\" = :\"view\";"
{:values {:view an-id}})))))

(testing "namespaced-named-bindings"
(let [prep-write (alia/prepare *session* "INSERT INTO namespaced (\"namespaced/id\", \"namespaced/text\") VALUES(:\"namespaced/id\", :\"namespaced/text\");")
prep-read (alia/prepare *session* "SELECT * FROM namespaced WHERE \"namespaced/id\" = :\"namespaced/id\";")
an-id (int 100)]


(is (= nil
(alia/execute *session* prep-write {:values {:namespaced/id an-id
:namespaced/text "inserted via namespaced named bindings"}})))

(is (= [{:namespaced/id an-id
:namespaced/text "inserted via namespaced named bindings"}]
(alia/execute *session* prep-read {:values {:namespaced/id an-id}})))

(is (= [{:namespaced/id an-id
:namespaced/text "inserted via namespaced named bindings"}]
(alia/execute *session* "SELECT * FROM namespaced WHERE \"namespaced/id\" = :\"namespaced/id\";"
{:values {:namespaced/id an-id}})))))

(testing "parameterized set"
(let [;; s-parameterized-set (prepare "select * from users where emails=?;")
]))
Expand Down

0 comments on commit bf49fc9

Please sign in to comment.