Fork me on GitHub
#beginners
<
2021-11-05
>
phasetr03:11:40

Nice to meet you. I have a question about a description of project.clj, leiningen. How do I specify the latest of master in dependencies in the project.clj file? I reported a bug, and the author fixed that in https://github.com/sicmutils/sicmutils/pull/383. I want to use this fixed version, but I do not know how to do.

seancorfield05:11:59

The Clojure CLI (and deps.edn) can easily use git deps but Leiningen requires a plugin. I haven't used Leiningen for six years at this point but I believe there's a lein-git-deps plugin (although it hasn't been touched for 8 years?). Maybe ask in #leiningen about git deps? Or switch your project to the CLI and deps.edn?

👀 1
phasetr05:11:19

Thank you for your reply! I will check them.

schmee10:11:59

• clone the repo • in project.clj, change defproject sicmutils "0.19.2" to defproject sicmutils "0.19.2-SNAPSHOT" • run lein install in the repo dir • in your project, change the dependency version to “0.19.2-SNAPSHOT”

orpheus05:11:46

I’m trying out migratus and it’s showing me how much I don’t understand about how to manage a database connection in a clojure app. I read through https://clojureverse.org/t/how-to-manage-database-connection-in-clojure/5067/5 and I’m still pretty confused on how I should go about managing a db connection (without using a 3rd party library.. I’ll eventually get to component/integrant/etc) The problem rn is that when I call miginit more than once in the REPL, I get a This connection has been closed . How do I keep my db connection alive and available without a third party library?

seancorfield05:11:46

Sounds like Migratus is closing the connection? I'm not familiar with that library but I would say using atoms to handle datasources and connections seems wrong to me.

seancorfield05:11:22

Looks like Migratus still uses java.jdbc rather than next.jdbc so your :db key should be a "db-spec", which is a hash map that describes your db -- basically :db db-config ought to do it.

seancorfield05:11:58

You don't need any of that get-datasource / get-connection stuff, as far as I can see @U01JYKT6ENL

orpheus05:11:41

Hm okay. if I don’t have the get-datasource/connection fns, when/where should I create those? just in the main- fn?

orpheus05:11:04

And what would I use instead of an atom?

seancorfield05:11:38

You don't need any of that for Migratus.

seancorfield05:11:05

What is db-config? A hash map with :dbtype / :dbname etc?

yes 1
seancorfield06:11:00

Using next.jdbc functions with Migratus won't help you since it uses the older java.jdbc library.

seancorfield06:11:10

We can talk about using next.jdbc in a program separately from Migratus (but that discussion better belongs in #sql).

👍 1
orpheus06:11:48

db-config is your next.jdbc map. Migratus says it takes a db connection so I was passing the db connection retrieved from jdbc/get-connection And sounds good, thank you.

seancorfield06:11:17

Migratus docs specifically show that it takes a db-spec hash map, albeit the old-fashioned one that even with java.jdbc has been outdated for years.

seancorfield06:11:25

(def config {:store                :database
             :migration-dir        "migrations/"
             :init-script          "init.sql" ;script should be located in the :migration-dir path
             ;defaults to true, some databases do not support
             ;schema initialization in a transaction
             :init-in-transaction? false
             :migration-table-name "foo_bar"
             :db {:classname   "org.h2.Driver"
                  :subprotocol "h2"
                  :subname     "site.db"}})
that is just the old-fashioned form of
(def config {:store                :database
             :migration-dir        "migrations/"
             :init-script          "init.sql" ;script should be located in the :migration-dir path
             ;defaults to true, some databases do not support
             ;schema initialization in a transaction
             :init-in-transaction? false
             :migration-table-name "foo_bar"
             :db {:dbtype "h2"
                  :dbname     "site.db"}})

orpheus06:11:07

gotchya.. so instead of trying to reuse and pass the connection just reuse the db-spec hash map 👍

seancorfield06:11:44

Let me know how that goes.

🙏 1
orpheus06:11:25

It’s working well. I can run those migrate commands multiple times from the repl without any errors now!

1
vinurs13:11:51

hello, i have a function in php like this $ret = openssl_decrypt($ret['encData'], 'aes-128-cbc', $key, OPENSSL_DONT_ZERO_PAD_KEY, $key); , how can i translate this in clojure

Benjamin14:11:53

(fn [{:keys [name]}] (keyword name))
is there an even more terse way to say this?

Darin Douglass14:11:43

(comp keyword :name)

🎉 1
cwchriswilliams16:11:47

Is it possible to have a spec to validate that a value of a map arg has a relationship with another arg? It's my first foray into spec and I'm trying to see what it can do. Whenever I try to extract a value from a map in my spec, I get a NullPointerException, telling me I'm probably doing it wildly wrong or applying a wildly wrong concept:

(defn arg-test
  [test-map other-field]
  (println test-map)
  )
(s/def ::pos-int-val (s/and int? pos?))
(s/def ::map-def (s/keys
                  :req [::pos-int-val]))
(s/fdef arg-test
  :args (s/and (s/cat :test-map ::map-def :other-field ::pos-int-val)
               #(< (get-in % [:test-map :test-val]) (:other-field %))))

(stest/check `arg-test)

dpsutton16:11:34

in that function you are treating % as if it is a map with keys that are the sequence of arguments. You should confirm what argument is actually passed to that function

cwchriswilliams16:11:07

My issue was actually that the namespace of the key was incorrect. I got it working by fully qualifying, but I'll do a bit more exploring to figure out a better way. Thank you for the suggestion though. It reminded me that in the world of Clojure, I can easily query into things like the type of % 🙂

dpsutton16:11:21

yeah. i looked at it and just instrumented the function rather than exercising it like that and made the function just print its argument and return true

dpsutton16:11:29

repl and redefining can help out in exploration

cwchriswilliams16:11:37

I just did some experimenting with instrument and that actually is really useful in figuring out what's going on. Thanks again! 🙂

👍 1
Grzegorz Smajdor20:11:10

Hi folks, have an issue with starting new project on osx, with clojure 1.10.3.998 and openjdk 17.0.1 2021-10-19, after creating a new project lein new figwheel kotek --reagent and then running lein figwheel inside, I get https://gist.github.com/gs/0466a64b568dc2bb39dbba2cbfd9b0ab Any help appriciated

seancorfield20:11:32

Is this on an M1 Mac? I'm just looking at the dependencies there (Figwheel / Hawk / Barbary WatchService) and it looks like the latter was originally a port to Java 6 of functionality from Java 7 and neither of those last two libraries have been updated in years).

seancorfield20:11:16

I've never used lein-figwheel but I got the impression that it's pretty much deprecated and folks should be using Figwheel Main instead, these days?

seancorfield20:11:00

There's are three Figwheel-related channels you could try asking in: #lein-figwheel #figwheel #figwheel-main @UNDL444G4

Grzegorz Smajdor20:11:23

right, its M1. thx will check channels!

seancorfield20:11:07

I'm guessing the Barbary filewatch library either doesn't have an M1 native impl or it relies on a low-level library that doesn't exist on an M1 Mac... purely a guess tho'...

seancorfield20:11:51

There should be native filewatch capability in the JDK itself but I don't know if there are updates to Figwheel/Sidecar that depend on that instead of Hawk.

Grzegorz Smajdor20:11:47

I might try to use figwheel main then, never used that before.

Grzegorz Smajdor22:11:45

hi, just experimenting with figwheel-main seems that the files are not hot-reloading on M1. Anything to fix that?

Grzegorz Smajdor22:11:55

I’ve run lein new figwheel-main test-app -- +deps --reagent

seancorfield22:11:31

I don't use Leiningen so I can't help you. I'm not currently doing ClojureScript so I can't help you with that either. Ask in the channels I pointed you at.

seancorfield22:11:26

(I haven't used Leiningen for six years and when I was doing ClojureScript some, earlier this year, I was using the Clojure CLI and a non-M1 Mac)

seancorfield22:11:46

But no, you do not need to add Hawk as a dependency. I only pointed that out because it seems really outdated and it is what lein-figwheel seems to be using via Figwheel Sidecar. Which is why I pointed you at Figwheel Main since I believe that is actively being maintained.

Grzegorz Smajdor22:11:18

great, thank you. I had some projects before I’ve switched to M1 and they were working, now need to get back to them… and they are not working anymore 😉

Grzegorz Smajdor22:11:32

should not have switched to M1 - life would be much more easier

seancorfield22:11:17

I went through two chipset changes on Mac and they usually have some speed bumps. 680x0 -> RISC and then RISC -> Intel. But I've been in the process of moving completely to Windows over the last few years -- no more Apple products for me!