Giter VIP home page Giter VIP logo

Comments (5)

ptaoussanis avatar ptaoussanis commented on June 8, 2024

Hi Eric,

Thanks for getting in touch!

The problem you're running into here isn't to do with make-conn-spec, but with the fact that you're trying to define a function of [& body]. Function arguments are evaluated right away - in this case before the bindings established by with-conn are actually in effect.

I might be able to make a suggestion if I understood better what you're trying to accomplish. I'm not familiar with Hyperion - took a look at the page just now, but couldn't find a simple description of what expectations it has for adapter APIs.

Could you point me toward a simple spec somewhere?

from carmine.

ekosz avatar ekosz commented on June 8, 2024

Hey Peter,

I'll give a quick run-down on how Hyperion works. Hyperion has a bunch of DataStores. Each one for a different database. The datastore is created with an database argument, which is then passed to each of its functions.

I would like to treat this database argument like the carmine macro. Example.

If I can get the first two specs of this file to pass I think I'll have smooth sailing from there.

from carmine.

ptaoussanis avatar ptaoussanis commented on June 8, 2024

Okay, I looked over the links briefly.

So can I clarify:

  1. You're trying to implement hyperion.abstr/Datastore for Carmine.
  2. https://github.com/ekosz/hyperion/blob/redis/redis/src/hyperion/redis.clj is working already?
  3. You'd like to now make the connection stuff configurable through open-db?

Is that right?

I would like to treat this database argument like the carmine macro. Example.

Are you saying you're trying to get db to behave like the with-conn macro? That won't be possible (the one's a function, the other a macro), but it also doesn't seem like it should be necessary if all you want to do is satisfy #3 above.

What stops you from just giving the desired connection pool & spec to each with-conn call?

So, for example, something like:

(defn- save-record [db record]
  (let [kind (:kind record)
        key (name (:key record))
        my-pool  (some-fn db)
        my-spec (some-fn db)]
    (carmine/with-conn my-pool my-spec
      (r/set (str kind ":" key) record))
    record))

I'm not sure what form db takes exactly, but I'm assuming the options are somehow accesible through it, right?

So maybe something like:

(defn open-db [options]
  (let [defaults {:host "127.0.0.1" :port 6379 :password nil :timeout 0 :db 0}
        pool (r/make-conn-pool :max-active 8)
        connection-spec (merge defaults options)]
    {:pool pool :spec connection-spec})))

Then assuming open-db returns the db that's gonna get passed to save-record...

(defn- save-record [db record]
  (let [kind (:kind record)
        key (name (:key record)]
    (carmine/with-conn (:pool db) (:spec db)
      (r/set (str kind ":" key) record))
    record))

Disclaimer: I may have completely misunderstood how the API is working :)

from carmine.

ekosz avatar ekosz commented on June 8, 2024

Alrighty, I was able to come up with a nice compromise where I didn't have to repeat myself too much. Thank you for your help!

You can check out the redis module of Hyperion here.

from carmine.

ptaoussanis avatar ptaoussanis commented on June 8, 2024

Cool- that seems perfect.

A few other comments in case they're helpful:

  • open-db would also be a good place to allow overriding the connection pool options if you wanted. There's no overlap between pool and connection-spec options, so you could just lump the two together in the single options map.
  • I'm not sure how concerned you are about performance, but be aware that r/keys is O(n) so if this is being called often, you may prefer to maintain your own list of keys in a ist or some other kind of index.

Cheers!

from carmine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.