Fork me on GitHub
#beginners
<
2018-09-06
>
bartuka01:09:38

Hi ppl, I’m using monger to work with MongoDB and I have a question. Should I define my database connection once and reuse it on every interaction with the database or should I already start my functions with a let [conn (mg/connect "db")\n db (mg/get-db conn)] ...?

dadair01:09:27

There are libraries that help with this sort of thing, allowing you to build the connection once and then pass it around to different parts of your application. A selection of these libraries includes: Component, Integrant, Mount

seancorfield01:09:36

@iagwanderson Setting up the DB connection can be quite expensive so I'd recommend doing it once (during application startup, using Component etc per @dadair) and then have that connection passed around (as part of your system state, per Component etc).

bartuka01:09:57

thanks, I saw the overhead when I was running my application right now. I will take a look at this library now. thanks @dadair and @seancorfield

bartuka05:09:13

just for the record, I managed to get mount working here to pass a stateful conection of mongodb… worked so well ! thanxs again

seancorfield05:09:28

Some people will caution that mount relies on mutable global state and that may prove problematic as your app expands... 🙂

stardiviner07:09:20

How to merge a list out map elements which has same key value pair? Like this ({:title "one" :text "text 1"} {:title "one" :text "text 1.1111"} {:title "two" :text "....."} ...) -->> ({:title "one" :text ("text 1" "text 1.1111" ...)} {title "two" :text (......)} ) ?

stardiviner07:09:11

Is there some simple ways to do this? I have a newbie way, use if to detect map whether has same key pair :title "one", then put :text together. I guess there are better solution?

onionpancakes07:09:50

I would suggest group-by to group the maps. Then write a func to merge/reduce each group of maps.

schmee07:09:44

here’s one way: (for [[k vs] (group-by :title a)] {:title k :text (mapv :text vs)})

stardiviner11:09:37

@scallions @schmee Thanks, learned group-by and mapv.

az15:09:26

Hi, trying to understand datomic ions, should I just be thinking about this as micro services?

az15:09:52

or can I build a larger app using ions?

henrik15:09:35

@aramz You can totally build an app with it.

az15:09:54

that’s fantastic

az15:09:33

would you recommend this to beginners?

henrik15:09:44

You'll find that connection time is slower when the lambda is not warm though. Subsequent requests are fast.

henrik15:09:25

I'd say that it would depend more on your familiarity with AWS than Clojure. Or willingness to learn, at least. I powered through.

az15:09:25

looking for the easiest way to deploy and hack on some hobby projects with clojure and datomic

henrik15:09:05

You'll have a problem, and it'll turn out to be IAM settings, for example.

johnj15:09:12

I would suggest local (on-premise) datomic-free/clojure

johnj15:09:34

for hobby stuff

henrik15:09:08

I don't know, my local dev experience with Ions has been pretty great. Nice not to have to set up the DB and so on.

henrik15:09:21

There is a cost involved with using AWS, of course. It's not huge, but it's there.

az15:09:02

@henrik thank you, going to give it a go

henrik15:09:05

@aramz Follow the tutorial to begin with. It'll be easier to ask for and receive help. Join #datomic and #ions-aws if you haven't already.

Drew Verlee20:09:06

whats the coolest way to split up a vector (? [1 2 3 4] 2) => [[1] [3 4]] such that u get the values before and after it? partition-by comes really close but you cant seem to distinguish between before, the value and after... which it returns

kenj20:09:34

perhaps split-at?

mfikes20:09:35

I’d use split-at, but if you need to avoid seqs and keep with vectors you could perhaps define something based on subvec, like

(defn split-vec [v n]
  (let [ndx (.indexOf v n)]
   [(subvec v 0 ndx) (subvec v (inc ndx))]))