Skip to content

Instantly share code, notes, and snippets.

@emwalker
Last active February 27, 2021 07:06
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emwalker/5da4408ca9bd1245b7c3709dc8e02439 to your computer and use it in GitHub Desktop.
Save emwalker/5da4408ca9bd1245b7c3709dc8e02439 to your computer and use it in GitHub Desktop.
Geting set up with Cayley and Postgres (April 2018)

Getting set up with Cayley and Postgres (April 2018)

Initialize the database

$ createdb testdb
$ wget https://github.com/cayleygraph/cayley/releases/download/v0.7.2/cayley_0.7.2_darwin_amd64.tar.gz
$ tar zxvf cayley_0.7.2_darwin_amd64.tar.gz
$ cat >cayley.cfg.json
{
  "store": {
    "backend": "postgres",
    "address": "postgres://postgres@localhost:5432/testdb?sslmode=disable",
    "read_only": false
  }
}
<CMD-D>
$ ./cayley_0.7.2_darwin_amd64/cayley init --config=./cayley.cfg.json
I0421 10:10:31.656097   26828 cayley.go:63] Cayley version: 0.7.2 (3091e673e8d9a945a71e286ca90f5e478e3ac503)
I0421 10:10:31.656249   26828 cayley.go:76] using config file: ./cayley.cfg.json
I0421 10:10:31.656406   26828 database.go:187] using backend "postgres" (postgres://postgres@localhost:5432/testdb?sslmode=disable)

Load the data

$ wget https://raw.githubusercontent.com/oren/cayley-postgres/master/canada.nq
$ ./cayley_0.7.2_darwin_amd64/cayley load --config=./cayley.cfg.json --load=./canada.nq
I0421 10:14:12.980555   27154 cayley.go:63] Cayley version: 0.7.2 (3091e673e8d9a945a71e286ca90f5e478e3ac503)
I0421 10:14:12.980705   27154 cayley.go:76] using config file: ./cayley.cfg.json
I0421 10:14:12.980916   27154 database.go:187] using backend "postgres" (postgres://postgres@localhost:5432/testdb?sslmode=disable)

Query the data using a repl

$ ./cayley_0.7.2_darwin_amd64/cayley repl --config=./cayley.cfg.json
I0421 10:14:58.259904   27217 cayley.go:63] Cayley version: 0.7.2 (3091e673e8d9a945a71e286ca90f5e478e3ac503)
I0421 10:14:58.260072   27217 cayley.go:76] using config file: ./cayley.cfg.json
I0421 10:14:58.260249   27217 database.go:187] using backend "postgres" (postgres://postgres@localhost:5432/testdb?sslmode=disable)
creating new history file: ".cayley_history"
cayley> g.V("person:justin").Out("in love with").All()

****
id : person:sophie
-----------
1 Result
Elapsed time: 5.667 ms

cayley>

More queries can be found at https://github.com/oren/cayley-postgres (but the setup instructions are dated).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment