Search code examples
interfaceclojurenamespacesrecord

How can I access a record in a library in Clojure?


I'm writing a library that implements a protocol and trying to access the record outside the namespace.

storage.clj contains the record:

(defrecord FrienduiStorage []
  f-glob/FrienduiStorage
  (get-all-users [this]
   (db/get-all-users)))

I require it like so [sventechie.friendui-mysql.storage :refer :all]. Then instantiate it like this (def FrienduiStorageImpl (->FrienduiStorage)) but this doesn't work: (get-all-users (FrienduiStorageImpl)) "RuntimeException: Unable to resolve symbol: get-all-users in this context". What am I doing wrong?

The full library repo is at (http://github.com/sventechie/friendui-mysql/). I've made a minimal usage example (http://github.com/sventechie/friendui-mysql-example/).


Solution

  • To formalize @mavbozo's comments to your question into an answer, you need to add an import to the regular class

    So definition is

    (ns sventechie.friendui-mysql.storage)
    (defrecord FrienduiStorage [])
    

    and usage is:

    (ns somewhere.else
      (:require [sventechie.friendui-mysql.storage :refer :all])
      (:import [sventechie.friendui-mysql.storage.FrienduiStorage]))