Back
keys (clj)
(source)function
(keys map)
Returns a sequence of the map's keys, in the same order as (seq map).
Examples
clojure
(deftest division
(is (= clojure.core// /))
(binding [*ns* *ns*]
(eval '(do (ns foo
(:require [clojure.core :as bar])
(:use [clojure.test]))
(is (= clojure.core// bar//))))))
(deftest t-Explicit-line-column-numbers
(is (= {:line 42 :column 99}
(-> "^{:line 42 :column 99} (1 2)" read-string meta (select-keys [:line :column]))))
(are [l c s] (= {:line l :column c} (-> s str->lnpr read meta (select-keys [:line :column])))
42 99 "^{:line 42 :column 99} (1 2)"
1 99 "^{:column 99} (1 2)")
(eval (-> "^{:line 42 :column 99} (defn explicit-line-numbering [])" str->lnpr read))
(is (= {:line 42 :column 99}
(-> 'explicit-line-numbering resolve meta (select-keys [:line :column])))))
jepsen-io/jepsen
(ns yugabyte.ycql.bank
(:refer-clojure :exclude [test])
(:require [clojure.tools.logging :refer [debug info warn]]
[clojure.core.reducers :as r]
[jepsen.client :as client]
[jepsen.checker :as checker]
[jepsen.generator :as gen]
[jepsen.tests.bank :as bank]
[jepsen.checker.timeline :as timeline]
[knossos.op :as op]
[clojurewerkz.cassaforte.client :as cassandra]
[clojurewerkz.cassaforte.cql :as cql]
[clojurewerkz.cassaforte.query :as q :refer :all]
[yugabyte.ycql.client :as c]))
(def setup-lock (Object.))
(def keyspace "jepsen")
(def table-name "accounts")
(c/defclient CQLBank keyspace []
(setup! [this test]
(c/create-transactional-table
conn table-name
(q/if-not-exists)
(q/column-definitions {:id :int
:balance :bigint
:primary-key [:id]}))
(info "Creating accounts")
(c/with-retry
(cql/insert-with-ks conn keyspace table-name
{:id (first (:accounts test))
:balance (:total-amount test)})
(doseq [a (rest (:accounts test))]
(cql/insert conn table-name
{:id a, :balance 0}))))
(invoke! [this test op]
(c/with-errors op #{:read}
(case (:f op)
:read
(->> (cql/select-with-ks conn keyspace table-name)
(map (juxt :id :balance))
(into (sorted-map))
(assoc op :type :ok, :value))
:transfer
(let [{:keys [from to amount]} (:value op)]
(cassandra/execute
conn
; TODO: separate reads from updates?
(str "BEGIN TRANSACTION "
"UPDATE " keyspace "." table-name
" SET balance = balance - " amount " WHERE id = " from ";"
"UPDATE " keyspace "." table-name
" SET balance = balance + " amount " WHERE id = " to ";"
"END TRANSACTION;"))
(assoc op :type :ok)))))
;; Shouldn't be used until we support transactions with selects.
(c/defclient CQLMultiBank keyspace []
(setup! [this test]
(info "Creating accounts")
(doseq [a (:accounts test)]
(info "Creating table" a)
(c/create-transactional-table
conn (str table-name a)
(q/if-not-exists)
(q/column-definitions {:id :int
:balance :bigint
:primary-key [:id]}))
(info "Populating account" a)
(c/with-retry
(cql/insert-with-ks conn keyspace (str table-name a)
{:id a
:balance (if (= a (first (:accounts test)))
(:total-amount test)
0)}))))
(invoke! [this test op]
(c/with-errors op #{:read}
(case (:f op)
:read
(let [as (shuffle (:accounts test))]
(->> as
(mapv (fn [x]
;; TODO - should be wrapped in a transaction after we
;; support transactions with selects.
(->> (cql/select-with-ks conn keyspace
(str table-name x)
(where [[= :id x]]))
first
:balance)))
(zipmap as)
(assoc op :type :ok, :value)))
:transfer
(let [{:keys [from to amount]} (:value op)]
(cassandra/execute conn
(str "BEGIN TRANSACTION "
(str "UPDATE " keyspace "." table-name from
" SET balance = balance - " amount
" WHERE id = " from ";")
(str "UPDATE " keyspace "." table-name to
" SET balance = balance + " amount
" WHERE id = " to ";")
"END TRANSACTION;"))
(assoc op :type :ok)))))
pedestal/pedestal
(ns io.pedestal.interceptor.error
(:require [io.pedestal.interceptor :as interceptor]
[clojure.core.match :as match]))
(defmacro error-dispatch
"Return an interceptor for doing pattern-matched error-dispatch, based on
the ex-data of the exception.
Pedestal wraps *all* exceptions in ex-info on error, providing the following
keys to match on: `:execution-id`, `:stage`, `:interceptor`, `:exception-type`
replikativ/datahike
(ns datahike.http.writer
"Remote writer implementation for datahike.http.server through datahike.http.client."
(:require [datahike.writer :refer [PWriter create-writer create-database delete-database]]
[datahike.http.client :refer [request-json] :as client]
[datahike.json :as json]
[datahike.tools :as dt :refer [throwable-promise]]
[taoensso.timbre :as log]
[clojure.core.async :refer [promise-chan put!]]))
(defrecord DatahikeServerWriter [remote-peer conn]
PWriter
(-dispatch! [_ arg-map]
(let [{:keys [op args]} arg-map
p (promise-chan)
config (:config @(:wrapped-atom conn))]
(log/debug "Sending operation to datahike-server:" op)
(log/trace "Arguments:" arg-map)
(put! p
(try
(request-json :post
(str op "-writer")
remote-peer
(vec (concat [config] args))
json/mapper)
(catch Exception e
e)))
p))
(-shutdown [_])
(-streaming? [_] false))
(defmethod create-database :datahike-server
[& args]
(let [p (throwable-promise)
{:keys [writer] :as config} (first args)]
;; redirect call to remote-peer as writer config
(deliver p (try (->
(request-json :post
"create-database-writer"
writer
(vec (concat [(-> config
(assoc :remote-peer writer)
(dissoc :writer))]
(rest args))))
(dissoc :remote-peer))
(catch Exception e
e)))
p))
(defmethod delete-database :datahike-server
[& args]
(let [p (throwable-promise)
{:keys [writer] :as config} (first args)]
;; redirect call to remote-peer as writer config
(deliver p (try
(-> (request-json :post
"delete-database-writer"
writer
(vec (concat [(-> config
(assoc :remote-peer writer)
(dissoc :writer))]
(rest args))))
(dissoc :remote-peer))
(catch Exception e
e)))
p))
fulcrologic/fulcro
(ns fulcro-todomvc.server
(:require
[com.fulcrologic.fulcro.mutations :as m :refer [defmutation]]
[clojure.core.async :as async]
[com.wsscode.pathom.core :as p]
[com.wsscode.pathom.connect :as pc]
[taoensso.timbre :as log]))
(pc/defmutation todo-new-item [env {:keys [id list-id text]}]
{::pc/sym `fulcro-todomvc.api/todo-new-item
::pc/params [:list-id :id :text]
::pc/output [:item/id]}
(log/info "New item on server")
(let [new-id (random-uuid)]
(swap! item-db assoc new-id {:item/id new-id :item/label text :item/complete false})
{:tempids {id new-id}
:item/id new-id}))
;; how to go from :address/id to address details.
(pc/defresolver item-resolver [env {:keys [item/id] :as params}]
{::pc/input #{:item/id}
::pc/output [:item/complete :item/label]}
(get @item-db id))
cognitect-labs/aws-api
(ns dynamodb-examples
(:require [clojure.core.async :as a]
[clojure.java.io :as io]
[clojure.data.json :as json]
[cognitect.aws.client.api :as aws]))
(let [ ;; The aws-supplied example data are all json. We can use them
;; as/is, but we need keys defined the input specs to be
;; keywords if we want to validate the structure first!
xform-specified-keys
(fn [k]
(get (reduce (fn [a v] (assoc a v (keyword v)))
{}
["B" "BOOL" "BS" "Item" "L" "M" "N" "NS" "NULL" "PutRequest" "S" "SS"])
k
k))]
(->> ["Forum.json"
"Reply.json"
"Thread.json"]
(map #(-> (io/file "examples" "resources" "dynamodb" %)
slurp
(json/read-str :key-fn xform-specified-keys)))
(map #(aws/invoke ddb {:op :BatchWriteItem
:request {:RequestItems %}}))))