postgraphile 基本试用

我的测试环境使用docker 进行的安装

基本安装

./start_containers.sh
  • postgraphile(postgraphql)
npm install -g postgraphile

基本使用

  • 创建数据库
psql -U postgres -h localhost
create database appdemo
  • 启动postgraphile

    使用watch 参数可以自动更新api

postgraphile -c "postgres://postgres:postgres@localhost:5432/appdemo" --watch

参考结果

  • 使用graphql playground访问
  • 创建表
create table person (
  id serial primary key,
  name varchar not null,
  about text,
  email varchar not null unique,
  created_at timestamp default current_timestamp
);

自动更新结果

  • 数据查询操作
query {
  allPeople{
    nodes {
      id
      name
    }
  }
}

  • 添加数据
mutation {
  createPerson(input:{
     clientMutationId:"demoappdemo",
     person:{
      name:"dalong",
      about:"demoappdemo",
      email:"1141591465@qq.com",
      createdAt:"2018-07-10"
     }
  }){
    person {
      name
      about
      email
    }
  }
}

与prisma比较

主要是扩展行行,prisma是多数据库支持的,基于nodejs 开发模式,同时生态不错,有好多相关的组件,使用上主要
以模型优先的模式,postgraphile 相对就简单了,只需要安装基本上不用写代码(当然角色,权限的问题,依然需要处理,
而且在ID的处理上postgraphile有点模糊,还有待仔细阅读。
详细的比较后边会有介绍

参考资料

https://www.graphile.org/postgraphile/introduction/
https://www.prisma.io/

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

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2015-07-04 图片加载js类库
2015-07-04 js 触摸类库

导航

< 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
点击右上角即可分享
微信分享提示