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

posted on   荣锋亮  阅读(1127)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2017-11-12 gradle 配置java 项目maven 依赖
2017-11-12 gradle 插件
2017-11-12 gradle java 简单项目使用
2017-11-12 gradle 命令行
2017-11-12 gradle wrapper 简单使用
2017-11-12 gradle 安装试用
2017-11-12 linux 使用asciinema 进行命令行屏幕录制共享

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示