首页 > 其他 > 详细

postgraphile 基本试用

时间:2018-07-05 00:13:21      阅读:397      评论:0      收藏:0      [点我收藏+]

我的测试环境使用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
);

自动更新结果
技术分享图片

  • 数据查询操作
    ```code
    query {
    allPeople{
    nodes {
    id
    name
    }
    }
    }
<img width="699" height="458" src="7e4d60d1-f7f9-4752-8170-ef9f56a668b2_files/82548778.png">
* 添加数据
```code
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/

postgraphile 基本试用

原文:https://www.cnblogs.com/rongfengliang/p/9265979.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!