PostgREST 8.0.0 + PostgreSQL -13.4-1 + Windows10でテストをするための、PostgREST 8.0.0のインストールと設定と実行
2. PostgREST v8.0.0 release page をクリック github に移動
3. 下に移動
4. postgrest-v8.0.0-windows-x64.zip をダウンロードします。
5. 解凍します
6. postgrest.exe (t がついています) を
C:\Program Files\PostgreSQL\13\bin に コピーします。
7. 貼り付け
8. 対象のフォルダーへのアクセスは拒否されました
このフォルダーへコピーするには管理者の権限が必要です
と 警告されますが、
続行
を押します。
9. postgres に t がつくだけなので、見間違えそうになりますが、別のexe です。
postgres.exe
postgrest.exe
10. コマンドプロンプトから
cd C:\Program Files\PostgreSQL\13\bin
postgrest
で動作確認できます、
Usage: postgrest [-e|--example] [--dump-config | --dump-schema] FILENAME
PostgREST 8.0.0 (0bc7c03) / create a REST API to an existing Postgres database
などが表示されていれば、オッケーです。
11. Tutorial 0 - Get it Running を選択して、サンプルの todos の動作を実行していきます。
Step 1. Relax, we’ll help (ステップ1.リラックスしてください)
Step 2. Install PostgreSQL (ステップ2.PostgreSQLをインストールします)
Step 3. Install PostgREST (ステップ3.PostgRESTをインストールします)
まで、終了しています。
13. Step 4. Create Database for API(ステップ4.API用のデータベースを作成する)から、今回用にデータベースのパスワードのみを変更して、psqlで実行します。
----------------------
create schema api;
create table api.todos (
id serial primary key,
done boolean not null default false,
task text not null,
due timestamptz
);
insert into api.todos (task) values
('finish tutorial 0'), ('pat self on back');
create role web_anon nologin;
grant usage on schema api to web_anon;
----------------------
grant select on api.todos to web_anon;
***この行を変更***create role authenticator noinherit login password 'mysecretpassword';
create role authenticator noinherit login password 'pg13dbPasswd';
----------------------
grant web_anon to authenticator;
\q
14. psql を実行します
Server [localhost]: Enterですすむ
Database [postgres]: Enterですすむ
Port [5432]: Enterですすむ
Username [postgres]: Enterですすむ
Client Encoding [SJIS]: Enterですすむ
ユーザ postgres のパスワード: pg13dbPasswd (画面には表示されません) を入力して、Enterですすむ
psql (13.4)
"help"でヘルプを表示します。
postgres=# が表示されれば、オッケー
15. 続行するには何かキーを押してください . . .
で Enterを押すと、画面がクローズされます。
16. Step 5. Run PostgREST (ステップ5.PostgRESTを実行します)
***この行を変更***db-uri = "postgres://authenticator:mysecretpassword@localhost:5433/postgres"
db-uri = "postgres://authenticator:pg13dbPasswd@localhost:5432/postgres"
db-schema = "api"
db-anon-role = "web_anon"
で、tutorial.conf を作成します
17. メモ帳を管理者として実行します。
18.
19. C:\Program Files\PostgreSQL\13\bin
に
tutorial.conf
として、保存します。
20. × で閉じます。
21. サイトの ./postgrest tutorial.conf は 実行するのがWindowsなので
コマンドプロンプトから
cd C:\Program Files\PostgreSQL\13\bin
postgrest tutorial.conf
となります。
このアプリの機能のいくつかがwindows defenderファイアウォールでブロックされています
の警告がでるので、
アクセスを許可する
を押します。
22. 下記のように表示で、起動しています。
C:\Program Files\PostgreSQL\13\bin>postgrest tutorial.conf
25/Aug/2021:18:32:00 +0900: Attempting to connect to the database...
25/Aug/2021:18:32:00 +0900: Connection successful
25/Aug/2021:18:32:00 +0900: Listening on port 3000
25/Aug/2021:18:32:00 +0900: Config re-loaded
25/Aug/2021:18:32:00 +0900: Listening for notifications on the pgrst channel
25/Aug/2021:18:32:00 +0900: Schema cache loaded
は、ブラウザで
正しく、jsonが返されています。
[{"id":1,"done":false,"task":"finish tutorial 0","due":null},
{"id":2,"done":false,"task":"pat self on back","due":null}]
実行時のエラーportが違うと
tutorial.conf の文字コードが違うと
のような、エラーとなりました。
サイトのインストール方法のscoopなとで、