如何在使用Cayley时使用Postgres后端?

huangapple go评论79阅读模式
英文:

How to use Cayley with a Postgres backend?

问题

根据这个Github问题Cayley图数据库的Postgres后端功能已经实现。然而,目前在文档中没有示例,并且我在阅读代码时也无法弄清楚。有人可以帮忙吗?

编辑

要开始使用Cayley,我们可以使用以下命令加载源代码中附带的数据:

./cayley load --config=cayley.cfg.overview --quads=data/30kmoviedata.nq.gz

我尝试了两个cayley.cfg.overview文件的变体:

{
    "database": "sql",
    "db_path": "localhost:5432",
    "read_only": false
}

{
    "database": "sql",
    "db_path": "/var/lib/postgresql/9.4/main/cayley",
    "read_only": false
}

第一个与使用mongo的文件类似(5432是postgres服务器监听的端口)。至于第二个,我对我在那里做什么一无所知 :D。

无论如何,当我使用./cayley load --config=cayley.cfg.overview --quads=data/30kmoviedata.nq.gz命令时,我会得到以下错误(只有db_path的值不同):

Couldn't open database at localhost:5432: 
&errors.errorString{s:"missing \"=\" after \"127.0.0.1:5432\" in connection 
info string\""}
E1117 21:09:18.300033 16689 cayley.go:277] missing "=" after "localhost:5432" 
in connection info string"
英文:

As per this Github issue, the Postgres backend feature for the Cayley graph database is implemented. However, currently there aren't examples in the docs, and I couldn't figure it out by reading the code. Could someone help?

Edit

To start playing with Cayley, we can load data that comes with the source with the following command:

./cayley load --config=cayley.cfg.overview --quads=data/30kmoviedata.nq.gz

I tried two variations of the cayley.cfg.overview file:

{
    "database": "sql",
    "db_path": "localhost:5432",
    "read_only": false
}

and

{
    "database": "sql",
    "db_path": "/var/lib/postgresql/9.4/main/cayley",
    "read_only": false
}

The first one being analogous to the one used with mongo (5432 being the port at which the postgres server is listening). As for the second one, I have no clue of what I'm doing there :D.

In any case, when I use the ./cayley load --config=cayley.cfg.overview --quads=data/30kmoviedata.nq.gz command I get the following error (varying only the value of db_path):

Couldn't open database at localhost:5432: 
&errors.errorString{s:"missing \"=\" after \"127.0.0.1:5432\" in connection 
info string\""}
E1117 21:09:18.300033 16689 cayley.go:277] missing "=" after "localhost:5432" 
in connection info string"

答案1

得分: 3

看起来Cayley在底层使用了lib/pq。lib/pq的连接字符串大致如下:"user=pqgotest dbname=pqgotest sslmode=verify-full""postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full"。有关详细信息,请参阅lib/pq的文档,网址是godoc.org

(你可以在cayley/graph/sql/quadstore.go的connectSQLTables函数中看到sql.Open的调用位置。)

英文:

It looks like Cayley is using lib/pq under the covers. lib/pq connection strings look something like this: "user=pqgotest dbname=pqgotest sslmode=verify-full" or "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full"
For full details see the lib/pq documentation at godoc.org.

(You can see where the sql.Open call is made in cayley/graph/sql/quadstore.go connectSQLTables.)

huangapple
  • 本文由 发表于 2015年11月18日 07:33:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/33769116.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定