0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

postgrest の使い方

Last updated at Posted at 2023-04-13

前提条件

ユーザー scott
パスワード tiger123
データベース city
でログインできるとします。

サーバーの設定

ex01.conf
db-uri = "postgres://scott:tiger123@localhost:5432/city"
db-schema = "public"
db-anon-role = "scott"

サーバーの起動

$ postgrest ex01.conf
13/Apr/2023:11:54:31 +0900: Attempting to connect to the database...
13/Apr/2023:11:54:31 +0900: Connection successful
13/Apr/2023:11:54:31 +0900: Listening on port 3000
13/Apr/2023:11:54:31 +0900: Config reloaded
13/Apr/2023:11:54:31 +0900: Listening for notifications on the pgrst channel
13/Apr/2023:11:54:31 +0900: Schema cache loaded

表示

参考ページ
Tables and Views

curl

$ curl http://localhost:3000/cities
[{"id":"t3461","name":"広島","population":25176,"date_mod":"2003-09-24"}, 
 {"id":"t3462","name":"福山","population":47935,"date_mod":"2003-05-15"}, 
 {"id":"t3463","name":"東広島","population":28654,"date_mod":"2003-02-08"}, 
 {"id":"t3464","name":"呉","population":83152,"date_mod":"2003-10-09"}, 
 {"id":"t3465","name":"尾道","population":42791,"date_mod":"2003-08-04"}, 
 {"id":"t3466","name":"竹原","population":35687,"date_mod":"2003-01-21"}, 
 {"id":"t3467","name":"三次","population":81296,"date_mod":"2003-07-23"}, 
 {"id":"t3468","name":"大竹","population":21764,"date_mod":"2003-10-26"}, 
 {"id":"t3469","name":"府中","population":75423,"date_mod":"2003-12-15"}]

Httpie

$ http http://localhost:3000/cities
HTTP/1.1 200 OK
Content-Location: /cities
Content-Range: 0-8/*
Content-Type: application/json; charset=utf-8
Date: Thu, 13 Apr 2023 02:58:52 GMT
Server: postgrest/10.0.0
Transfer-Encoding: chunked

[
    {
        "date_mod": "2003-09-24",
        "id": "t3461",
        "name": "広島",
        "population": 25176
    },
    {
        "date_mod": "2003-05-15",
        "id": "t3462",
        "name": "福山",
        "population": 47935
    },
    {
        "date_mod": "2003-02-08",
        "id": "t3463",
        "name": "東広島",
        "population": 28654
    },
    {
        "date_mod": "2003-10-09",
        "id": "t3464",
        "name": "呉",
        "population": 83152
    },
    {
        "date_mod": "2003-08-04",
        "id": "t3465",
        "name": "尾道",
        "population": 42791
    },
    {
        "date_mod": "2003-01-21",
        "id": "t3466",
        "name": "竹原",
        "population": 35687
    },
    {
        "date_mod": "2003-07-23",
        "id": "t3467",
        "name": "三次",
        "population": 81296
    },
    {
        "date_mod": "2003-10-26",
        "id": "t3468",
        "name": "大竹",
        "population": 21764
    },
    {
        "date_mod": "2003-12-15",
        "id": "t3469",
        "name": "府中",
        "population": 75423
    }
]

削除

参考ページ
Deletions

curl

curl "http://localhost:3000/cities?id=eq.t3467" -X DELETE

Httpie

http DELETE  "http://localhost:3000/cities" id=="eq.t3466"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?