使用带有clojure的窗口设置本地PostgreSQL实例?

时间:2012-12-28 23:24:35

标签: postgresql heroku clojure

我正试图遵循这个tutuorial https://devcenter.heroku.com/articles/clojure-web-application。尽管如此,我在设置本地postgresql数据库进行测试时遇到了一些困难。

第一个障碍是在Windows shell中运行“postgres -D pg”导致错误“不允许具有管理权限的用户执行PostgreSQL”。为了得到一个回合,我尝试运行pg_ctl start -D。\。我认为它有效,除了它无法访问“postgresql.conf”文件。

运行“creatdb shouter”也不起作用,所以我运行了“createdb -U postgres shouter”。但是现在当我尝试启动lein repl时,我只是得到了这个错误:

$lein repl
Could not find artifact postgresql:postgresql:pom:8.4-702.qdbc4 in central (http://repo1.maven.org/maven2
Could not find artifact postgresql:postgresql:pom:8.4-702.qdbc4 in clojars (https://clojars.org/repo/)
Could not find artifact postgresql:postgresql:jar:8.4-702.qdbc4 in central (http://repo1.maven.org/maven2
Could not find artifact postgresql:postgresql:jar:8.4-702.qdbc4 in clojars (https://clojars.org/repo/)
Check :dependencies and :repositories for typos.
It's possible the specified jar is not in any repository.
If so, see "Free-floating Jars" under http://j.mp/repeatability
Exception in thread "Thread-1" clojure.lang.ExceptionInfo: Could not resolve dependencies {:exit-code 1}
        at clojure.core$ex_info.invoke(core.clj:4227)
        at leiningen.core.classpath$get_dependencies.doInvoke(classpath.clj:128)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:605)
        at leiningen.core.classpath$resolve_dependencies.doInvoke(classpath.clj:144)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at leiningen.core.eval$prep.invoke(eval.clj:60)
        at leiningen.core.eval$eval_in_project.invoke(eval.clj:220)
        at leiningen.repl$start_server.doInvoke(repl.clj:65)
        at clojure.lang.RestFn.invoke(RestFn.java:470)
        at leiningen.repl$repl$fn__1788.invoke(repl.clj:145)
        at clojure.lang.AFn.applyToHelper(AFn.java:159)
        at clojure.lang.AFn.applyTo(AFn.java:151)
        at clojure.core$apply.invoke(core.clj:601)
        at clojure.core$with_bindings_STAR_.doInvoke(core.clj:1771)
        at clojure.lang.RestFn.invoke(RestFn.java:425)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.RestFn.applyTo(RestFn.java:132)
        at clojure.core$apply.invoke(core.clj:605)
        at clojure.core$bound_fn_STAR_$fn__3984.doInvoke(core.clj:1793)
        at clojure.lang.RestFn.invoke(RestFn.java:397)
        at clojure.lang.AFn.run(AFn.java:24)
        at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:1)

看起来你的project.clj文件可能没有指定正确的依赖项。这是一个简短的示例项目,具有与之比较的工作依赖项:

project.clj:

(defproject hello "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [org.clojure/java.jdbc "0.2.3"]
                 [postgresql/postgresql "8.4-702.jdbc4"]])

从repl开始工作。

user> (require '[clojure.java.jdbc :as sql])
nil

user> (def pgsqldb {:subprotocol "postgresql"                                                              
                    :subname "//127.0.0.1:5432/dbname"                                                    
                    :user "postgres"                                                                       
                    :password "...."})
#'user/pgsqldb
user> (sql/with-connection pgsqldb )
nil

user> (sql/with-connection pgsqldb 
         (sql/with-query-results rs ["SELECT * 
                                      FROM information_schema.tables 
                                      WHERE table_type = 'BASE TABLE' 
                                        AND table_schema = 'public' 
                                      ORDER BY table_type, table_name"] 
           (count rs)))
50