PostgREST docker-compose 试用
PostgREST 是一款很不错的直接将pg 数据库暴露为restapi ,使用了基于行级别安全访问控制,
比较全的restapi 查询以及集成了swagger openapi
docker-compose 文件
version: '3'
services:
server:
image: postgrest/postgrest
ports:
- "3001:3000"
links:
- db:db
environment:
PGRST_DB_URI: postgres://app_user:password@db:5432/app_db
PGRST_DB_SCHEMA: public
PGRST_DB_ANON_ROLE: app_user #In production this role should not be the same as the one used for the connection
depends_on:
- db
db:
image: postgres
ports:
- "5433:5432"
environment:
POSTGRES_DB: app_db
POSTGRES_USER: app_user
POSTGRES_PASSWORD: password
swagger:
image: swaggerapi/swagger-ui
ports:
- "8081:8080"
environment:
API_URL: http://localhost:3001/
运行
- 启动
docker-compose up -d
- swagger-ui
open http://localhost:8081
- 添加表数据
-- DDL generated by Postico 1.4.3
-- Not all database features are supported. Do not use for backup.
-- Table Definition ----------------------------------------------
CREATE TABLE userapps (
id SERIAL PRIMARY KEY,
name text
);
-- Indices -------------------------------------------------------
CREATE UNIQUE INDEX userapps_pkey ON userapps(id int4_ops);
INSERT INTO "public"."userapps"("id","name")
VALUES
(1,E'dalong'),
(2,E'app');
- 效果
参考资料
http://postgrest.org/en/v5.1/tutorials/tut0.html
http://postgrest.org/en/v5.1/install.html#docker