Fork me on GitHub
#beginners
<
2018-02-13
>
hawari.rahman1708:02:42

Hi everyone, how do you guys usually handle DB migrations? Do you: - Run it from your deployment script - Run it every time the jar is executed - Run it separately as another action (e.g. using REPL manually) - Others

pcbalodi08:02:11

I always like the idea of running migrations as a seperate action.

hawari.rahman1709:02:34

How is your approach on it in terms of clojure @pcbalodi? Do you still use library like migratus to do it, or do you prefer to do it manually to your database?

fmind09:02:12

Hi, I have a problem with indentation ... When I declare a function, I like to have the docstring next to the function name:

(defn path->name "Extract the base name from a file path."
  [path] (fs/base-name path))
But each time I change the docstring, the line with defn is indented with two spaces. Can I change or disable this behavior ?

delaguardo10:02:24

If you are using emacs + clojure-mode there is an option for that - https://github.com/clojure-emacs/clojure-mode#indentation-options

fmind10:02:27

I'm using CIDER with spacemacs, does CIDER use some features from clojure-mode ?

delaguardo10:02:27

cider is minor-mode for clojure buffers. you major mode still clojure-mode and indentation rules comes from it. So an answer is - you are using clojure-mode + cider

fmind10:02:41

I've tried to put this config in my layer, without success

(define-clojure-indent
  (defn 2)
  (defn- 2))

delaguardo10:02:17

try this (set clojure-docstring-fill-prefix-width 0)

fmind10:02:46

it works ! Thanks, you save me from a lot of frustration @delaguardo

delaguardo10:02:03

you are welcome)

fmind10:02:34

I know this does not follow the community standard, I like to fold my function and keep the docstring visible

delaguardo10:02:06

oh… but for that you might want to adjust folding rules instead of using non standard indentation

fmind10:02:13

it's mostly for private project, but I will keep that in mind if I release an open source project

pcbalodi10:02:40

@hawari.rahman17 I havent used migratus so I dont know best practices around it. I mostly use dogfish, its shell based

hawari.rahman1711:02:54

That's pretty handy, doesn't get tied to any runtime/language. Thank you @pcbalodi.

pcbalodi12:02:06

:+1::skin-tone-3:

funyako.funyao15612:02:17

@tbaldridge @mateusz.probachta thanks!

erhardtmundt13:02:52

could you explain me what this does? (map #(map hash v) (vals (group-by :id (concat coll-a coll-b))))

noisesmith17:02:17

“what this does” - as written, it blows up as soon as it tries to calculate a single value, because the function passed to map doesn’t accept an argument (I assume the actual code is different and actually accepts an argument)

erhardtmundt13:02:16

both coll-a and coll-b are vectors of hashes

schmee13:02:37

what is v?

josh_tackett14:02:46

@schmee v is probably a vector

josmith201615:02:41

In my spring java project with some clojure interop, I have some tests that test against an in memory database. My java code uses these properties to connect to the in memory database when testing:

datasource:
    url: jdbc:h2:mem:db
    username: sa
    password:
    driver-class-name: org.h2.Driver
    schema: classpath:db/sql/schema.sql
    data: classpath:db/sql/data.sql
    dbcp2:
      test-on-borrow: true
      validation-query: SELECT 1
  jpa:
    database: H2
    show-sql: false
    hibernate:
      ddl-auto: none
    database-platform: org.hibernate.dialect.H2Dialect
My clojure code retrieves the datasource from the environment like this
:classname   (System/getenv "jdbc_driver_class_name")
                         :subprotocol (System/getenv "subprotocol")
                         :subname     (System/getenv "subname")
                         :user        (System/getenv "jdbc_username")
                         :password    (System/getenv "jdbc_password")
and connects using clojure.java.jdbc. My question is, because the tests are in java which calls java which then calls the clojure code, what would I set those environment variables to, so my clojure code will connect to this in memory database on the classpath while testing?

josmith201615:02:33

My question really just boils down to this, how would I connect to the datasource(which is an in memory database on the classpath) in my above question with clojure.java.jdbc? Also is there a way to catch exceptions thrown in clojure?

jumar16:02:57

@ there shouldn't be any difference. As soon as it's the same process you should be perfectly able to connect to in-memory DB. You can catch exceptions using try with catch - see http://clojuredocs.org/clojure.core/try

josmith201618:02:50

You were right, it was the same, would you know if there is a way to set some of the other properties like

schema: classpath:db/sql/schema.sql
    data: classpath:db/sql/data.sql
when I’m creating the datasource with clojure.java.jdbc? Or is that something I can just ignore

prnc17:02:50

Hi, do you guys know if there is a list of most often used Java functions etc. in Clojure? Or some concise guide to Java "standard library" ? So that someone with no Java background could leverage the interop?

noisesmith17:02:54

for starters, we don’t use java functions (in java function is java.util.function.Function which is an API we really don’t need from clojure) - java libraries supply classes which have methods you can use. I learned java as follows: 1) I research “how to do X in clojure” and don’t like any of the answers (if any even exist) 2) I research “how to do X in java” then I translate to clojure using interop clojure interop with java is actually simpler and easier than java for anything that doesn’t require concrete inheritance or numerics https://clojure.org/reference/java_interop

noisesmith17:02:56

the javadoc format is a little crusty but it’s extremely comprehensive and consistent, which means I can get things done quickly now that I know what to expect from it

noisesmith18:02:04

to this:

user=> (java.net.URLEncoder/encode "foo;bar$baz" "UTF-8")
"foo%3Bbar%24baz"
(edited to use the correct non-depricated API)

noisesmith18:02:44

PS. many people would prefer to pull in a clojure library that “wraps” encoding a URL, despite it being a one liner. That’s an open discussion, perhaps your time as someone who doesn’t want to think about java takes precedence over complexity of your build and size of your jar

prnc18:02:44

hm, I see, makes sense, I was thinking that maybe someone is aware of some resource that could sometimes save you step (1) above

noisesmith18:02:37

some “java for clojure people” document would be interesting, it doesn’t exist as far as I know

prnc18:02:40

that would be great, google search is hijacked by "clojure for java devs" 😉

noisesmith18:02:45

what really helped me was going through that java interop documentation and actually making sure I could take a java class that comes with the vm and do that operation

noisesmith18:02:09

that plus needing to do things that were documented for java but not clojure

prnc18:02:28

cool, I will look through the Java interop reference, thanks!

noisesmith18:02:40

@prnc here’s another great example of a java interop one liner that eliminates the need for an entire library:

user=> (.encode (java.util.Base64/getEncoder) (.getBytes "hello"))
#object["[B" 0x758611de "[[email protected]"]
user=> (String. (.decode (java.util.Base64/getDecoder) *1))
"hello"

noisesmith18:02:06

and you can look up the javadoc for java.util.Base64 to see what precisely it’s doing

prnc18:02:32

yeah, that's super useful to know, I will keep looking if I find anything interesting on this topic will post here, cheers!

oliv21:02:11

hey guys, I’m trying to give a chance to atom ide. how can I see the clojure implementation ? ( like intelliJ CMD + Click )

oliv21:02:32

any package to “go to implementation” ?

seancorfield21:02:05

@oliv If you have a REPL running (necessary for all the fancy Clojure stuff), then it's ctl-opt-, followed by o

seancorfield21:02:21

(there's a #protorepl channel that will probably be helpful BTW)

oliv21:02:36

oh, thank you

oliv21:02:39

jump to talk there