3

I am trying to create a web app in clojure. i have used clojurescript om and react. there are two files core.cljs and db.clj. core.cljs contains ui for login page and db.clj contains all database connections.

Now i am trying to call a db.clj method add-user[username password] in core.cljs.

In db.clj

   (defn add-user [username,password]
        (sql/with-connection db
          (sql/insert-values :users [:username :password]
                             [username password])))

In core.cljs

       (dom/button #js {:ref "submit"
             :onClick (fn[e](add-user usname passwrd))}"submit")

But i am not able to call that method in core.cljs. It shows some error message like

clojure.lang.ExceptionInfo : failed compiling file:src\login_page\core.cljs
clojure.lang.ExceptionInfo : No such namespace: login_page.db, could not locate login_page/db.cljs, login_page/db.cljc, or Closure namespace "login_page.db"
User_1191
  • 981
  • 2
  • 8
  • 24
Silpa
  • 133
  • 1
  • 8
  • you can not call "server-side" clojure from your clojurescript. you have to run some sort of web-server to handle the requests. – cfrick Dec 08 '15 at 08:06
  • what can i do to handle the request.i am new to this.. – Silpa Dec 08 '15 at 09:54
  • you might want to look at http://www.luminusweb.net/ or at the web frameworks at http://www.clojure-toolbox.com/ – cfrick Dec 08 '15 at 09:59

1 Answers1

3

Rename db.clj to either db.cljs or db.cljc. That should get you past the 'No such namespace' error message.

That's the basic gist of it. Of course your dependencies on clj libraries will have to be removed - that might be the reason for the negative comment below. Alter your code so that you use a simple atom as your database. That should get you developing.

And you can wait for a much better answer than this one that will show you how to get the Client and Server communication setup. But it may not come because, as pointed out in the comments, there is already documentation for this, and unfortunately quite a few choices that have to be made. Another unfortunate thing is that the way to do it now may not be the way to do it early next year. Watch the Om-Next space!

I've never had any problems compiling .cljs or .cljc files. You just have to set up your lein project.clj file properly. There will be plenty of examples if you Google around, or you can take a look at the following small Github project: https://github.com/chrismurrph/passing-time - no need to worry about the code, just look at its project.clj file.

Chris Murphy
  • 6,411
  • 1
  • 24
  • 42
  • ...and will crash on attempt to compile that namespace as cljs instead. Marvellous work there :) – D-side Dec 08 '15 at 15:38
  • Yes, that was indeed the reason for my sarcastic comment. At the time you were solving one problem only to cause another one to appear, that would just lead to another question. Now that the explaination of "how to get something working" has been added, the OP now has some clues about where to look further. Now that is indeed marvellous work, without sarcasm this time. – D-side Dec 11 '15 at 22:39