Git Product home page Git Product logo

graphql-on-various-pg's Introduction

Hasura GraphQL engine on various Postgres flavours

TimescaleDB

  1. Follow the timescale tutorial to install and run a timescale db instance. (https://docs.timescale.com/v0.9/getting-started/installation/mac/installation-homebrew)

  2. Follow this tutorial to import a sample dataset. Here we are using New York City taxicab data. (https://docs.timescale.com/v0.9/tutorials/tutorial-hello-nyc). Follow this tutorial till the point to import data.

  3. Follow https://docs.hasura.io to run the GraphQL engine - with the correct database credentials pointing to your timescaledb instance.

  4. Open the console hasura console, and track all the tables.

  5. Create views with timescaledb specific functions, for timescale specific queries.

  6. Use Run SQL in console to create these views and track them:

-- Average fare amount of rides with 2+ passengers by day
CREATE VIEW avg_fare_w_2_plus_passenger_by_day AS (
    SELECT date_trunc('day', pickup_datetime) as day, avg(fare_amount) as avg_fare
    FROM rides
    WHERE passenger_count > 1
    GROUP BY day ORDER BY day
);

-- Total number of rides by day for first 5 days
CREATE VIEW ride_count_by_day AS (
  SELECT date_trunc('day', pickup_datetime) as day, COUNT(*) FROM rides
    GROUP BY day ORDER BY day
);

-- Number of rides by 5 minute intervals
--   (using the TimescaleDB "time_bucket" function)
CREATE VIEW rides_in_5min_intervals AS (
SELECT time_bucket('5 minute', pickup_datetime) AS five_min_interval, count(*) as rides
  FROM rides
  GROUP BY five_min_interval ORDER BY five_min_interval
);
  1. Once the above is done, then we can run GraphQL queries on these views.
query {
  avg_fare_w_2_plus_passenger_by_day(limit: 10) {
    day
    avg_fare
  }
}

query FirstTenDaysWithRidesMoreThan30k {
  ride_count_by_day(limit: 10, where: {count : {_gt: 30000}}) {
    day
    count
  }
}

query NoOfRidesIn5minIntervalBefore02Jan {
  rides_in_5min_intervals(where: {five_min_interval:{_lt: "2016-01-02 00:00"}}) {
    five_min_interval
    rides
  }
}

Citus DB

See details in citus/README.md.

graphql-on-various-pg's People

Contributors

coco98 avatar ecthiender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphql-on-various-pg's Issues

Test with citus triggers

Just had a conversation with Craig today. This landed at citus a few weeks ago:
http://docs.citusdata.com/en/v8.0/extra/triggers.html

At a high-level, Craig said that our updatable views system which uses triggers to enforce ACL can work if the trigger instrumentation is on the coordinator database. When the coordinator rewrites queries for the sharded tables and pushes that out, everything should just work. Triggers running on the sharded database won't work because set local will not be passed down to them.

Let's try things out with citus again and depending on issues we run into we can talk to the engineering folks at Citus to help us out.

Citus queries status

query AllClicksOfCompany5 {
  clicks (where: {company_id: {_eq: 5}}){
    cost_per_click_usd
    clicked_at
    site_url
    user_ip
    user_data
    ad {
      name
      campaign {
        name
      }
    }
  }
}

@ecthiender This works now. Is it because of hasuranightly/raven:2821b67 (the new build).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.