Back
some-> (clj)
(source)macro
(some-> expr & forms)
When expr is not nil, threads it into the first form (via ->),
and when that result is not nil, through the next etc
Examples
seancorfield/next-jdbc
(ns next.jdbc-test
"Basic tests for the primary API of `next.jdbc`."
(:require [clojure.core.reducers :as r]
[clojure.string :as str]
[clojure.test :refer [deftest is testing use-fixtures]]
[next.jdbc :as jdbc]
[next.jdbc.connection :as c]
[next.jdbc.test-fixtures
:refer [with-test-db db ds column
default-options stored-proc?
derby? hsqldb? jtds? mssql? mysql? postgres? sqlite?]]
[next.jdbc.prepare :as prep]
[next.jdbc.result-set :as rs]
[next.jdbc.specs :as specs]
[next.jdbc.types :as types])
(:import (com.zaxxer.hikari HikariDataSource)
(com.mchange.v2.c3p0 ComboPooledDataSource PooledDataSource)
(java.sql ResultSet ResultSetMetaData)))
(deftest multi-rs
(when (mssql?)
(testing "script with multiple result sets"
(let [multi-rs
(jdbc/execute! (ds)
[(str "begin"
" select * from fruit;"
" select * from fruit where id < 4;"
" end")]
{:multi-rs true})]
(is (= 2 (count multi-rs)))
(is (= 4 (count (first multi-rs))))
(is (= 3 (count (second multi-rs)))))))
(when (mysql?)
(testing "script with multiple result sets"
(let [multi-rs
(jdbc/execute! (ds)
[(str "select * from fruit;"
" select * from fruit where id < 4")]
{:multi-rs true})]
(is (= 2 (count multi-rs)))
(is (= 4 (count (first multi-rs))))
(is (= 3 (count (second multi-rs)))))))
(when (stored-proc?)
(testing "stored proc; multiple result sets"
(try
(let [multi-rs
(jdbc/execute! (ds)
[(if (mssql?) "EXEC FRUITP" "CALL FRUITP()")]
{:multi-rs true})
zero-updates [{:next.jdbc/update-count 0}]]
(cond (postgres?) ; does not support multiple result sets yet
(do
(is (= 1 (count multi-rs)))
(is (= zero-updates (first multi-rs))))
(hsqldb?)
(do
(is (= 3 (count multi-rs)))
(is (= zero-updates (first multi-rs))))
(mysql?)
(do
(is (= 3 (count multi-rs)))
(is (= zero-updates (last multi-rs))))
:else
(is (= 2 (count multi-rs)))))
(catch Throwable t
(println 'call-proc (:dbtype (db)) (ex-message t) (some-> t (ex-cause) (ex-message))))))))
PrecursorApp/precursor
(ns pc.http.routes.api
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clojure.core.memoize :as memo]
[clojure.string :as str]
[clojure.tools.reader.edn :as edn]
[crypto.equality :as crypto]
[defpage.core :as defpage :refer (defpage)]
[pc.auth :as auth]
[pc.crm :as crm]
[pc.datomic :as pcd]
[pc.early-access]
[pc.http.doc :as doc-http]
[pc.http.team :as team-http]
[pc.http.handlers.custom-domain :as custom-domain]
[pc.models.chat-bot :as chat-bot-model]
[pc.models.doc :as doc-model]
[pc.models.flag :as flag-model]
[pc.models.team :as team-model]
[pc.profile :as profile]
[ring.middleware.anti-forgery :as csrf]
[slingshot.slingshot :refer (try+ throw+)]))
(defpage new [:post "/api/v1/document/new"] [req]
(let [params (some-> req :body slurp edn/read-string)
read-only? (:read-only params)
doc-name (:document/name params)]
(if-not (:subdomain req)
(let [cust-uuid (get-in req [:auth :cust :cust/uuid])
intro-layers? (:intro-layers? params)
doc (doc-model/create-public-doc!
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when cust-uuid {:document/creator cust-uuid})
(when read-only? {:document/privacy :document.privacy/read-only})
(when doc-name {:document/name doc-name})))]
(when intro-layers?
(doc-http/add-intro-layers doc))
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
(if (and (:team req)
(auth/logged-in? req)
(auth/has-team-permission? (pcd/default-db) (:team req) (:auth req) :admin))
(let [doc (doc-model/create-team-doc!
(:team req)
(merge {:document/chat-bot (rand-nth chat-bot-model/chat-bots)}
(when-let [cust-uuid (get-in req [:cust :cust/uuid])]
{:document/creator cust-uuid})
(when read-only?
{:document/privacy :document.privacy/read-only})
(when doc-name
{:document/name doc-name})))]
{:status 200 :body (pr-str {:document (doc-model/read-api doc)})})
{:status 400 :body (pr-str {:error :unauthorized-to-team
:redirect-url (str (url/map->URL {:host (profile/hostname)
:protocol (if (profile/force-ssl?)
"https"
(name (:scheme req)))
:port (if (profile/force-ssl?)
(profile/https-port)
(profile/http-port))
:path "/new"
:query (:query-string req)}))
:msg "You're unauthorized to make documents in this subdomain. Please request access."})}))))
(defpage create-team [:post "/api/v1/create-team"] [req]
(let [params (some-> req :body slurp edn/read-string)
subdomain (some-> params :subdomain str/lower-case str/trim)
coupon-code (some-> params :coupon-code)
cust (get-in req [:auth :cust])]
(cond (empty? cust)
{:status 400 :body (pr-str {:error :not-logged-in
:msg "You must log in first."})}
typedclojure/typedclojure
(ns typed.clojure.jvm
"JVM-specific annotations and operations.
See typed.clojure for cross-platform ops."
(:require clojure.core.typed
[clojure.core.typed.current-impl :as impl]
[clojure.core.typed.internal :refer [take-when]]
[typed.cljc.runtime.env-utils :refer [delay-type]]
[clojure.core.typed.macros :as macros]))
(defmacro override-classes [& args]
(assert (even? (count args)))
`(do ~@(map (fn [[nme [frees & {:as opts}]]]
`(override-class ~@(some-> (not-empty frees) vector) ~nme ~(or (not-empty opts) {})))
(partition-all 2 args))))
typedclojure/typedclojure
(ns ^:typed/skip-from-repo-root clojure.core.typed.test.load-test
(:require [clojure.core.typed.load :as load]
[clojure.test :refer :all]))
;; ensures evaluation occurs
(deftest evaluation-test
(is (try (some-> (find-ns 'clojure.core.typed.test.typed-load.eval)
ns-name
remove-ns)
(load/typed-load1 "clojure/core/typed/test/typed_load/eval")
nil
(catch clojure.lang.ExceptionInfo e
(-> e ex-data :blame :file #{"clojure/core/typed/test/typed_load/eval.clj"})))))
SevereOverfl0w/vim-replant
(do
(clojure.core/create-ns 'replant.locate)
(clojure.core/in-ns 'replant.locate)
(clojure.core/require '[clojure.core :refer :all])
(some identity
(for [potential-dev-ns ['dev 'user 'boot.user]
potential-fn ['resume 'go 'start]]
(do
(try (require potential-dev-ns)
(catch Exception _))
(some-> (find-ns potential-dev-ns)
(ns-resolve potential-fn)
(str)
(->> (re-matches #"#'(.*)")
(second))
symbol)))))