Fork me on GitHub
#sql
<
2020-06-21
>
adam01:06:54

Is this (sql/query ds ["SELECT COUNT(1) FROM \"user\" WHERE email = ?" ""]) how to count in next.jdbc or there is a shortcut to it?

adam03:06:06

Also, is it possible to drop the table prefix on returned results?.. to use (:id user) instead of (:user/id user) in: (let [user (first (find-by-keys datasource :user {:email "some@email"})) id (:user/id user)

seancorfield04:06:19

@somedude314 The most common way folks count stuff in SQL is something like SELECT COUNT(*) AS n FROM ... and then run that through (-> (sql/query ...) (first) :n) (or whatever you alias the count as).

👌 3
seancorfield04:06:04

As for the qualified column names -- try to learn to live with them. It's a deliberate design decision and namespaced keywords are idiomatic Clojure.

seancorfield04:06:10

(you could use a :builder-fn to provide unqualified names but I strongly recommend you try to get used to them and work with them before just abandoning them: Spec relies heavily on namespaced keywords and you'll see them crop up in Datomic and other query languages)

adam08:06:53

Thanks, will definitely keep them when the result is coming from more than one table