Hi, What about something like this -
* Create a protocol called IGraphDBClient or something similar and create a spec. * Provide different client implementations in their own namespaces using deftype, eg. bulbs.db.neo4j/client, bulbs.db.orientdb/client, etc. * Put your core functions in a core ns, eg. bulbs.core. Write all your functions there. Ideally they should all work on top of the IGraphDBClient protocol. You could provide client factory functions as well, eg. (neo4j-client ...), (orientdb-client ...), etc. Does this work for you? Regards, BG On Fri, May 11, 2012 at 2:23 PM, James Thornton <james.thorn...@gmail.com> wrote: > 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? > > Thanks. > > - James > > > > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- Baishampayan Ghose b.ghose at gmail.com -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en