Fork me on GitHub
#leiningen
<
2024-03-20
>
Gabriel Rech12:03:49

Hi folks, Wasn't able to find this anywhere, so I thought on asking here. I have a project where I'm using a dynamodb and leveraging the clj-dynamodb-local plugin to boot up the db during tests, which can be done via the lein dynamodb-local command. What I was looking for is if there is any way of linking the REPL startup with the dynamodb boot; meaning that whenever I triggered the REPL to start (using Calva as IDE here, in case its relevant) I could have an injection or profile that would automatically boot dynamodb together. Any ideas on how I could achieve that? Thanks!

pez12:03:14

There are probably better ways to do it, but I wonder if you could achieve this with a Calva custom Jack-in command-line: https://calva.io/connect-sequences/#custom-command-line

Gabriel Rech13:03:04

I guess I could modify the leiningen jack-in command to call the dynamodb-local task as well? Like it states on the plugin docs: > You can start DynamoDB Local, followed by any other tasks you may want to run, using the following: >

$ lein dynamodb-local other-tasks...
> (<https://github.com/dmcgillen/clj-dynamodb-local?tab=readme-ov-file#leiningen > |ref>) So I'm assuming if I can concatenate the task to the leiningen boot command used by calva it should fire up the db. Though, I'm not entirely sure how to append this to calva boot sequence. Do you have any example for leiningen? I didn't find an example for leiningen in calva documentation you sent. PS: The downside of this approach is that it would be only for me; I was wondering if I could have this within leiningen configuration so other folks would share the same behavior when booting the REPL

pez13:03:12

If “other folks” are other folks using the project, you can pack the REPL start as a shell script and make the custom jack-in command line a simple call to this shell script

til 1
pez13:03:27

Anyway, I agree that ideally you want to find the Leiningen way to do this.

Gabriel Rech15:03:26

Ok, so a dug a little deeper into some other repositories and found a way that seems to work, so sharing it here: We can include clj-dynamodb-local/clj-dynamodb-local as a :dev dependency to project.clj and use its own fns to force booting during a REPL startup. E.g. -> Project.clj

:profiles {:dev {:injections   [(require '[service.dynamodb-local :as dynamodb-local])
                                  (dynamodb-local/run)]
                   :dependencies [[clj-dynamodb-local/clj-dynamodb-local "0.1.2"]]....
-> src/service/dynamodb_local.clj
(ns service.dynamodb-local
  (:require [dynamodb-local.core :as core])
  (:import ( File)))

(defn run
  [& _]
  (let [info    (core/create-dynamo-db-logger println)
        project {:dynamodb-local {:port       8000
                                  :in-memory? true
                                  :db-path    (str (System/getProperty "user.home") File/separator ".clj-dynamodb-local")}}]
    (core/ensure-installed info)
    (let [dynamodb-process (core/start-dynamo info project)]
      (core/handle-shutdown info dynamodb-process))))