Fork me on GitHub

can someone help me. I'm trying to generate csv file on the fly. using . and it works when I'm doing it with get request. In my case though I have to do it with post request (because data gets composed via So this, kinda works:

(defn download-csv [req]
  (let [result (run-om-query (:body req) (:user req))
        query-k (-> req :body ffirst)
        data (get-in result [query-k :data])]
    {:status 200
     :headers {"Content-Type" "text/csv"
               "Content-disposition" "attachment; filename=filename.csv"}
     :body  (ring-io/piped-input-stream
              (fn [out]
                (let [columns (-> data first keys)]
                  (with-open [wtr (io/writer out)]
                    (csv/write-csv wtr [columns])
                    (doseq [row data]
                      (csv/write-csv wtr [(map row columns)]))))))}))
but browser doesn't "recognize it". no "dowload to" popup comes up, etc.


i use but that is browser side, don't know if that helps


has a cljsjs wrapper


what's missing?


I have a feeling that this might be not possible in the same request ;(


if it's "post"


If you just drop a valid csv string in there does it work?


the content it returns from server is fine - it is correct csv. but browser doesn't recognize it as "file download"


as I said - if I ignore the om.parser part, and generate just random csv and use get, instead of post it works just fine - I don't even have to set the correct content-type and other headers


but I need to use post


@ag have you tried setting the content-type to application/download


I did. it's still didn't work

Arno Rossouw09:10:10

I like using emacs for clojure, is there a way to do code autocompletion, i'm using inferior-clojure module


yes, by using CIDER 😉

Arno Rossouw09:10:34

ok, cool. Will check

Oliver George10:10:42

How about treating vars like ns alias so we can use shorthand for creating keywords associated with a fn like ::myfn/props


does anyone have any experience with hugsql ( i'm trying to debug some tricky sql statements and i'd like to see what sql statement hugsql is generating under the hood.


;; For most HugSQL usage, you will not need the sqlvec functions.
;; However, sqlvec versions are useful during development and
;; for advanced usage with database functions.
(hugsql/def-sqlvec-fns "princess_bride/db/sql/characters.sql")
take a look at def-sqlvec-fns


For myself I found it very useful


@joshkh the best option would be to check your DB logs. Configure your database to log all the queries into a file. Or you may run the database not as a service but as process. So you’ll see all the queries in the console. For postgres, start it with postgres -E -D /usr/local/var/postgres (on Mac)


elegant solution! thanks


what is the clojure equiv of C's FILE__ ?


I want some debug msgs to dump FILE__ so it's easy to figure out where they are coming from


You can use (meta #'any-function-or-variable) ;; => {:line 13, :column 1, :file "path/to/file.clj", :name var-name, :ns #namespace[namespace-where-var-defined]} :file is related to your classpath

delaguardo13:10:04 there are more information about this


@qqq you mean like how tools.logging does?


@dominicm: not quite tools.logging: it's ... I'm looking at this cljs app, I see this div, whose body says "todo" -- I want to kow where this "todo" is coming from -- so I grep for "todo" in my source tree -- and I get many matches, so I'd really prefer is that div said "todo: foobart.clj: line 74" instead of just "todo"


@qqq you need a macro which looks at *ns*, which is how this is done in tools logging


@dominicm, @delaguardo: going with @delaguardo’s meta solution 🙂


That means they need a reference to the function they are in, no?


I know what I ca ndo (io/copy in out) -- however, is there a nice way to inject a "gunzip" in the middle of it?


so the input is a *.gz stream, and for the output, I want an uncompressed stream


very easy to use in my experience


nice, I did not reailze you could just 'wrap' and have it take care of the rest


I am looking for advice to connect to a Mysql Database. I am using jbdc and mysql/mysql-connector-java plugin to run a simple query to my database. however, the connection does not seem to connect (to a my local environment) and not able to pull any data. Does anyone know any helpful tutoriasl or walk-throughs to help me connect to a db. error messages: 1. {user=, password=}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ] 2. Cannot JSON encode object of class: class [B: [[email protected]


I would look at the stacktrace for 2, my bet is you have other library loaded that globally extends jdbc to automatically json encode things


1 looks like something from a connection pooling library, which again leads me to believe you are dealing with a much larger pile of code then your question suggests


Does anyone know if there's a 'Storm' channel? Specifically using Clojure spouts/bolts with Storm.


There is not. You might as well ask questions here and see if anyone responds...


Hey guys, I’m looking for some resources/examples of speccing and unit testing database transactions in Clojure w/ (for now). Does anyone have a project or resource they can point me to for testing functions for reads, writes, and deletes?


@admay Perhaps start with's own test suite? Your question is a bit vague so I'm not sure what you're really asking.


(I would also say that "unit testing" and "database transactions" don't really go together -- that's more of an "integration test")


So I have a bunch of functions like (fetch-from-db ...), (insert-into-db! ...), (delete-from-db! ...), and (update-in-db!)` that I need to test in order to pass my companies ‘code coverage’ standards and I’m not quite sure how to go about it. Like you said, ‘unit testing’ and ‘database transactions’ don’t really go together. I’m absolutely open to another approach given I’m very new to unit/integration testing as long as they’re automated. The automation is non-negotiable as per company standards.


if you separate all logic into functional data to data transforms without side effects, the part where you talk to the db can be a very small stub that should already be tested by the library you are using


if they ask you to test interaction with the db lib, then you need integration testing instead of unit testing, and someone needs to hook up a db for that testing environment


This also highlights the disadvantage of writing wrappers for things that already does since you are now creating extra code that you need to "test" to pass an arbitrary code coverage rule 🙂


(as well as actually creating a layer of logic where regressions can occur)


In order to test that insert-into-db! "does the right thing" you'd need to read the data back in and assert it matches your expectations -- which means that your tests rely on fetch-from-db which is a bit circular. And how would you test that fetch-from-db is doing the right thing? (would you insert-into-db! and then fetch-from-db and compare the result? Again, circular)