postgraphile 基本试用
我的测试环境使用docker 进行的安装
基本安装
- pg 数据库
我使用的是timesacledb 复制集版本,参考https://github.com/timescale/streaming-replication-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/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2015-07-04 图片加载js类库
2015-07-04 js 触摸类库