-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7d5ab70
Showing
25 changed files
with
26,849 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PG_CONN=postgres://{user}:{password}@{host}:5432/restaurants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variables file | ||
.env | ||
.env.development | ||
.env.production | ||
|
||
# gatsby files | ||
.cache/ | ||
public | ||
|
||
# Mac files | ||
.DS_Store | ||
|
||
# Yarn | ||
yarn-error.log | ||
.pnp/ | ||
.pnp.js | ||
# Yarn Integrity file | ||
.yarn-integrity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"endOfLine": "lf", | ||
"semi": false, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 gatsbyjs | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# restaurant-inspections | ||
|
||
Search restaurant inspection data from the Detroit Health Department. | ||
|
||
Built with Gatsby, a static-site generator for React & GraphQL. | ||
|
||
## Data | ||
|
||
We're using the `gatsby-source-pg` plugin to query data from PostgreSQL. Find a database dump in `src/data/restaurants.sql.bz2`. | ||
|
||
Assuming you have PostgreSQL installed locally, load it from your shell: | ||
```bash | ||
createdb restaurants | ||
psql -d restaurants -c 'create extension postgis' | ||
bunzip2 restaurants.sql.bz2 | ||
psql -d restaurants < restaurants.sql | ||
``` | ||
|
||
You'll find three tables in the `public` schema: `establishments`, `inspections` and `violations`. An establishment can have many inspections, and an inspection can have many violations. Following the [Postgraphile docs](https://www.graphile.org/postgraphile/introduction/), we've pre-defined indexes, foreign key constraints, and one Postgres function in our database. | ||
|
||
Here's a copy of that function; it queries restaurants on name and returns a list: | ||
```psql | ||
create or replace function search_establishments (input text) | ||
returns setof establishments as $$ | ||
select * from establishments | ||
where name ilike ('%' || input || '%') | ||
$$ language sql stable; | ||
``` | ||
|
||
It translates to this handy GraphQL query: | ||
```gql | ||
{ | ||
searchEstablishments(input: "taqueria") { | ||
edges { | ||
node { | ||
establishmentid | ||
name | ||
address | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
This data comes from [Detroit's open data portal](https://data.detroitmi.gov/browse?q=restaurants). | ||
|
||
## Styling | ||
|
||
Customizable [Semantic UI](https://github.com/pretzelhands/gatsby-starter-semantic-ui) coming soon | ||
|
||
## Develop | ||
|
||
Install Gatsby CLI globally: `npm install --global gatsby-cli` | ||
|
||
Define your database connection string in `.env.development`: | ||
``` | ||
PG_CONN=postgres://{user}:{password}@{host}:{port}/{dbname} | ||
``` | ||
|
||
`yarn install` or `npm install` installs depenedencies | ||
|
||
`gatsby develop` starts the development server and GraphiQL, an in-browser IDE for our site's data | ||
|
||
## Helpful links | ||
|
||
- [Gatsby documentation](https://www.gatsbyjs.org/) | ||
- [gatsby-source-pg plugin](https://www.gatsbyjs.org/packages/gatsby-source-pg/) | ||
- [PostGraphile documentation](https://www.graphile.org/postgraphile/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Implement Gatsby's Browser APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/browser-apis/ | ||
*/ | ||
|
||
// You can delete this file if you're not using it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require("dotenv").config({ | ||
path: `.env.${process.env.NODE_ENV}`, | ||
}) | ||
|
||
module.exports = { | ||
siteMetadata: { | ||
title: `Gatsby Default Starter`, | ||
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`, | ||
author: `@gatsbyjs`, | ||
}, | ||
plugins: [ | ||
`gatsby-plugin-react-helmet`, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `images`, | ||
path: `${__dirname}/src/images`, | ||
}, | ||
}, | ||
`gatsby-transformer-sharp`, | ||
`gatsby-plugin-sharp`, | ||
{ | ||
resolve: `gatsby-plugin-manifest`, | ||
options: { | ||
name: `gatsby-starter-default`, | ||
short_name: `starter`, | ||
start_url: `/`, | ||
background_color: `#663399`, | ||
theme_color: `#663399`, | ||
display: `minimal-ui`, | ||
icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site. | ||
}, | ||
}, | ||
{ | ||
resolve: "gatsby-source-pg", | ||
options: { | ||
connectionString: process.env.PG_CONN, | ||
schema: "public", | ||
}, | ||
}, | ||
// this (optional) plugin enables Progressive Web App + Offline functionality | ||
// To learn more, visit: https://gatsby.dev/offline | ||
// 'gatsby-plugin-offline', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Implement Gatsby's Node APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/node-apis/ | ||
*/ | ||
|
||
const path = require('path') | ||
|
||
exports.createPages = async ({ graphql, actions: { createPage }}) => { | ||
const res = await graphql(` | ||
{ | ||
postgres { | ||
establishments: allEstablishmentsList { | ||
establishmentid | ||
} | ||
} | ||
} | ||
`) | ||
|
||
res.data.postgres.establishments.forEach(e => { | ||
createPage({ | ||
path: `/establishment/${e.establishmentid}`, | ||
component: path.resolve('./src/templates/establishment-page.js'), | ||
context: { | ||
eid: e.establishmentid, | ||
}, | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Implement Gatsby's SSR (Server Side Rendering) APIs in this file. | ||
* | ||
* See: https://www.gatsbyjs.org/docs/ssr-apis/ | ||
*/ | ||
|
||
// You can delete this file if you're not using it |
Oops, something went wrong.