Code Monkey home page Code Monkey 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.

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.