Skip to content

Instantly share code, notes, and snippets.

@dsandip
dsandip / postgis-topology-operators-example.graphql
Created January 18, 2019 04:39
PostGIS topology operators sample
query landmarks($district_polygon: geometry){
landmarks(where: {location: {_st_within: $district_polygon}}){
id
name
location
}
}
@dsandip
dsandip / PostGIS-example-response.json
Created January 17, 2019 09:23
Custom functions: Example custom PostGIS function query response
{
"data": {
"search_landmarks_near_user": [
{
"user_id": 3,
"location": {
"type": "Point",
"crs": {
"type": "name",
"properties": {
@dsandip
dsandip / sample-graphql-query.graphql
Created January 17, 2019 09:20
testing graphQL rendering
query {
search_landmarks_near_user(
args: {userid: 3, distance_kms: 20}
){
user_id
location
nearby_landmarks
}
}
@dsandip
dsandip / PostGIS-example-query.graphql
Last active January 17, 2019 09:23
Custom functions: Example custom PostGIS function query
query {
search_landmarks_near_user(
args: {userid: 3, distance_kms: 20}
){
user_id
location
nearby_landmarks
}
}
@dsandip
dsandip / PostGIS-example-custom-SETOF-table-and-function.sql
Created January 17, 2019 08:59
Custom functions: sample SETOF table and custom PostGIS function
-- SETOF table
CREATE TABLE user_landmarks (
user_id INTEGER,
location GEOGRAPHY(Point),
nearby_landmarks JSON
);
-- function returns a list of landmarks near a user based on the
-- input arguments distance_kms and userid
CREATE FUNCTION search_landmarks_near_user(userid integer, distance_kms integer)
@dsandip
dsandip / example-location-data-tables.sql
Last active January 30, 2019 07:02
Custom functions: sample location tables
-- Create PostGIS extensions if they don't exist
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
-- User location data
CREATE TABLE user_location (
user_id INTEGER PRIMARY KEY,
location GEOGRAPHY(Point)
);
@dsandip
dsandip / search_articles.sql
Created January 17, 2019 08:38
Custom functions: sample function - search_articles
CREATE FUNCTION search_articles(search text)
RETURNS SETOF article AS $$
SELECT *
FROM article
WHERE
title ilike ('%' || search || '%')
OR content ilike ('%' || search || '%')
$$ LANGUAGE sql STABLE;
@dsandip
dsandip / example-query-for-custom-sql-function.graphql
Last active January 17, 2019 11:14
Sample query for custom sql function support in GraphQL Engine
-- “search_articles” is a custom SQL function that takes a text input to search an ”article” table
query {
search_articles(
args: {search: "hasura"}
){
id
title
content
}
@dsandip
dsandip / custom-functions-test-data.md
Last active January 11, 2019 18:18
Test data for custom functions docs

Insert data into tables:

Table: landmark

Mutation:

mutation insertLandmark($objects: [landmark_insert_input!]!) {
    insert_landmark(objects: $objects) {
         returning{
EXPLAIN SELECT * FROM foo;
QUERY PLAN
---------------------------------------------------------
Seq Scan on foo (cost=0.00..155.00 rows=10000 width=4)
(1 row)