绑定完请刷新页面
取消
刷新

分享好友

×
取消 复制
hasura-graphql 集成 pipelinedb 1.0.0
2022-03-01 14:18:34

pipelinedb 1.0.0 已经是一个标准的pg 扩展了,同时以前的语法也有变动,但是集成进hasura-graphql 更方便了

使用docker-compose 运行

环境准备

  • docker-compose 文件
version: "3"
services:
  db:
   image: dalongrong/pipelinedb:1.0.0
   environment:
   - "POSTGRES_PASSWORD=dalongdemo"
   ports:
   - "5432:5432"
  graphql-engine:
    image: hasura/graphql-engine:v1.0.0-alpha25
    ports:
    - "8080:8080"
    environment:
    - "POSTGRES_PASSWORD:dalongdemo"
    command: >
      /bin/sh -c "
      graphql-engine --database-url postgres://postgres:dalongdemo@db/postgres serve --enable-console;
      "
  • 创建pipelinedb stream 数据模型
CREATE FOREIGN TABLE wiki_stream (
        hour timestamp,
        project text,
        title text,
        view_count bigint,
        size bigint)
SERVER pipelinedb;
CREATE VIEW wiki_stats WITH (action=materialize) AS
SELECT hour, project,
        count(*) AS total_pages,
        sum(view_count) AS total_views,
        min(view_count) AS min_views,
        max(view_count) AS max_views,
        avg(view_count) AS avg_views,
        percentile_cont(0.99) WITHIN GROUP (ORDER BY view_count) AS p99_views,
        sum(size) AS total_bytes_served
FROM wiki_stream
GROUP BY hour, project;

添加数据

  • insert 数据
可以使用官方的demo(数据比较大,有点慢)
curl -sL http://pipelinedb.com/data/wiki-pagecounts | gunzip | \
        psql -c "
        COPY wiki_stream (hour, project, title, view_count, size) FROM STDIN"
或者直接insert
INSERT INTO wiki_stream (hour,project,title,view_count,size)
VALUES ('2015-07-05 9:00:00','rong','bbb',4,100)
说明: 可以多添加几条数据

配置graphql

添加add 就可以了,新的比以前的更明确了,直接就是view 的明称

  • add graphql 
  • 查询 

说明

使用新的还是比较方便的,同时集成起来也更清晰了

参考资料

http://docs.pipelinedb.com/index.html 
https://github.com/rongfengliang/pipelinedb-hasura-graphql

分享好友

分享这个小栈给你的朋友们,一起进步吧。

PipelineDB
创建时间:2022-02-28 14:06:00
PipelineDB
展开
订阅须知

• 所有用户可根据关注领域订阅专区或所有专区

• 付费订阅:虚拟交易,一经交易不退款;若特殊情况,可3日内客服咨询

• 专区发布评论属默认订阅所评论专区(除付费小栈外)

技术专家

查看更多
  • 飘絮絮絮丶
    专家
戳我,来吐槽~