import json
import psycopg2
/home/aivuk/.virtualenvs/nabu/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>. """)
$ su - postgres
$ createdb -O aivuk bolsonaro
$ psql bolsonaro
bolsonaro=# create table posts ( id serial primary key not null, post jsonb, content text ) ;
bolsonaro=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "aivuk";
bolsonaro=# GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO "aivuk";
bolsonaro=# create role authenticator nologin;
bolsonaro=# grant authenticator to aivuk ;
bolsonaro=# grant usage on schema public to authenticator ;
bolsonaro=# grant select on posts to authenticator ;
data = json.loads(open('./jairbolsonaro-2019.json', 'r').read())
conn = psycopg2.connect("dbname=bolsonaro user=aivuk password=pass")
cur = conn.cursor()
for d in data:
cur.execute("insert into posts (post, content) values (%s, %s)", [json.dumps(d), d['text']])
conn.commit()
Create file bolsonaro.conf with content:
db-uri = "postgres://aivuk:pass@localhost:5432/bolsonaro"
db-schema = "public"
server-host = "*"
db-anon-role = "authenticator"
jwt-secret = "sh3d3SeWWQTn85sDZ8ytKmtS36HJtEhJ"
server-port = 3001
download postgrest and run it:
$ ./postgrest bolsonaro.conf