Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:52:17+00:00 2026-06-03T19:52:17+00:00

As a Clojure learning exercise, I am porting Bulbs ( http://bulbflow.com ), a graph-database

  • 0

As a Clojure learning exercise, I am porting Bulbs (http://bulbflow.com), a graph-database library I wrote, from Python to Clojure.

One of the things I’m still somewhat fuzzy on is how to structure the library in a Clojure idiomatic way.

To support multiple databases, Bulbs uses dependency injection. The different database backends are abstracted away in a custom Client class that implements an interface, and the client is configured at runtime.

The Graph object and its various proxy objects hold an instance of the low-level Client object:

# bulbs/neo4jserver/graph.py

class Graph(object):

    default_uri = NEO4J_URI

    def __init__(self, config=None):
        self.config = config or Config(self.default_uri)
        self.client = Neo4jClient(self.config)

        self.vertices = VertexProxy(Vertex, self.client)
        self.edges = EdgeProxy(Edge, self.client)

You use Bulbs by creating a Graph object for the respective graph-database server:

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()

And then you can create vertices and edges in the database via the proxy objects:

>>> james = g.vertices.create(name="James")
>>> julie = g.vertices.create(name="Julie")
>>> g.edges.create(james, "knows", julie)

This design makes it easy to use Bulbs from the REPL because all you have to do is import and instantiate the Graph object (or possibly pass in a custom Config object if needed).

But I’m not sure how to approach this design in Clojure since the Graph object and its proxies need to hold the Client object, which is configured at runtime.

What’s the Clojure-way of doing this?

UPDATE: This is what I ended up doing…

;; bulbs/neo4jserver/client.clj

(def ^:dynamic *config* default-config)

(defn set-config!
  [config]
  (alter-var-root #'*config* (fn [_] (merge default-config config))))

(defn neo4j-client
  [& [config]]
  (set-config! config))

(neo4j-client {:root_uri "http://localhost:7474/data/db/"})

(println *config*)

UPDATE 2:

Andrew Cooke pointed out that using a global var would preclude you from being able to use multiple, independent graph “instances” in your program, whereas you can in the Python version.

And so I came up with this:

(defn graph
  [& [config]]
  (let [config (get-config config)]
    (fn [func & args]
      (apply func config args))))

(defn create-vertex
  [config data]
  (let [path (build-path vertex-path)
        params (remove-null-values data)]
    (rest/post config path params)))

(defn gremlin
  [config script & [params]]
  (rest/post config gremlin-path {:script script :params params}))

And then you can call the different functions like this:

(def g (graph {:root_uri "http://localhost:7474/data/db/"}))

(g create-vertex {:name "James"})

(g gremlin "g.v(id)" {:id 178})

Now I haven’t delved into macros yet, and I’m not too sure of the merits of this approach compared to others so feedback welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:52:19+00:00Added an answer on June 3, 2026 at 7:52 pm

    Protocols are well suited to this in Clojure, you define a protocol (a lot like an interface) that defines all the functions required to interface with a database, then at runtime you call the contructor of the graph protocol that builds in instance of the protocol that connects to your DB of choice.

    the basic flow is very much the same, except using Clojure protocols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying (as a self-learning exercise) to create a Clojure macro that will generate
I'm learning Clojure and as an exercise I wanted to write something like the
I've been learning Clojure, and since I come from a Ruby, and before that
I'm learning clojure and have been using 4clojure.com to get better. I just completed
I'm learning Clojure solving the problems listed on 4clojure . One of the exercises
I am thinking about learning Clojure, but coming from the c-syntax based (java, php,
I'm currently learning clojure, but I was wondering how to get and store user
I am just learning Clojure and am having trouble moving my code into different
When I'm learning Clojure of some languages, the readability and convenience of syntax is
I'm writing a little parser in clojure for learning purpose. basically is a TSV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.