g0v / kuansim

鄉民關心你 - 事件追蹤分析系統
http://hack.g0v.tw/kuansim/mynkDCEAXgc
30 stars 8 forks source link

Setup pgest web in vagrant box #13

Closed hychen closed 11 years ago

hychen commented 11 years ago

目標 架設restful db

clkao commented 11 years ago

我知道你遇到的問題了:一般 db user 無法 create extension plv8

所以先這樣:

sudo su postgres -c 'psql MYDB'
MYDB> create extension plv8

然後:

pgrest --db tcp://user:pass@localhost/MYDB

應該就可以了。

clkao commented 11 years ago

updated the pgrest recipe, it installs pgextwlist and allows plv8 extension created by non-superusers. try again.

hychen commented 11 years ago

the result after 'vagrant destroy ; vagrant up'

sudo su postgres -c 'createdb MYDB'
sudo su postgres -c 'psql MYDB'
MYDB> create extension plv8
sudo npm i plv8x -g
sudo su postgres -c "plv8x --db tcp://localhost/MYDB --import pgrest:./package.json

error: password authentication failed for user "postgres"
clkao commented 11 years ago

can you create a normal dbuser? nod-pg has a bug using unix socket for connecting db

hychen commented 11 years ago

ok

Best regards, Hsin Yi Chen

More about me: http://about.me/hychen

2013/6/13 Chia-liang Kao notifications@github.com

can you create a normal dbuser? nod-pg has a bug using unix socket for connecting db

— Reply to this email directly or view it on GitHubhttps://github.com/g0v/kuansim/issues/13#issuecomment-19376056 .

hychen commented 11 years ago

vagrant@vagrant-ubuntu-precise-64:/vagrant$ sudo su postgres -c 'createdb MYDB' vagrant@vagrant-ubuntu-precise-64:/vagrant$ sudo su postgres -c 'psql MYDB' MYDB> create extension plv8 vagrant@vagrant-ubuntu-precise-64:/vagrant$ sudo su postgres -c "plv8x --db tcp://postgres:hackg0v@localhost/MYDB --import pgrest:./package.json" vagrant@vagrant-ubuntu-precise-64:/vagrant$ sudo su postgres -c "plv8x --db tcp://postgres:hackg0v@localhost/MYDB --inject 'plv8x_json pgrest_select(plv8x_json)=pgrest:pgrest_select'"

/usr/lib/node_modules/plv8x/node_modules/tmp/lib/tmp.js:260 throw err; ^ error: type plv8x_json does not exist at Connection.parseE (/usr/lib/node_modules/plv8x/node_modules/pg/lib/connection.js:537:11) at Connection.parseMessage (/usr/lib/node_modules/plv8x/node_modules/pg/lib/connection.js:382:17) at Socket. (/usr/lib/node_modules/plv8x/node_modules/pg/lib/connection.js:101:18) at Socket.EventEmitter.emit (events.js:95:17) at Socket. (_streamreadable.js:736:14) at Socket.EventEmitter.emit (events.js:92:17) at emitReadable (_stream_readable.js:408:10) at emitReadable (_stream_readable.js:404:5) at readableAddChunk (_stream_readable.js:165:9) at Socket.Readable.push (_stream_readable.js:127:10)

but the web server works bug the data is empty.

sudo su postgres -c "pgrest --db tcp://postgres:hackg0v@localhost/MYDB" Serving tcp://postgres:hackg0v@localhost/MYDB on http://localhost:3000/collections

hychen commented 11 years ago

$script = <<SCRIPT sudo su postgres -c 'createdb MYDB' sudo su postgres -c "psql MYDB -c 'create extension plv8'" sudo npm i pgrest -g sudo su postgres -c "pgrest --db tcp://postgres:hackg0v@localhost/MYDB" & SCRIPT