Edit and execute SQL queries in the browser using the CKAN DataStore API on the Analyze Boston Datasets
A User Guide is included in the application's Help dialog.
A Develop Guide has not been created yet.
The Administrator Guide is simply the "Installation" section below.
This project is motivated by the workflow hurdles when working with the CKAN datastore_search_sql
API,
which offers the full power of Postgres through a clumsy interface. Some challenges I encountered:
- The endpoint requires more than just URLEncoding (what about
*, ', !, (, )
) - The errors aren't particularly intuitive (i.e. any data exception, like
division_by_zero
results in an opaque 500 error)
- Clone the repo
- Get the latest Ace editor and store it in
src-noconflict/
- Customize config.js
- Run
php -f schema-generator.php > schema.js
- Serve it (I prefer
php -S localhost:8000
)
NOTE To disable the proxy, run localStorage.setItem('proxy',false);
WARNING This code is MESSY and the abuse of the global namespace is attrocious. Oops.
Prerequisites
- Profiency with Javascript, HTML and CSS
- Basic understanding of CKAN Project's dataset web services (especially
package_search
,datastore_search
&datastore_search_sql
) - Probably run
SELECT version();
so you know what version of Postgres you're working with (e.g.--PostgreSQL 9.6.9 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.9.3, 64-bit
)
Basically all the functionality is contained in app.js
+-Browser------------------------------------------------+
| index.html ---> app.js |
| - style.css -setup: config, render, etc |
| - Lib: ace.js -execute: call API & handle response |
| - Helpers -render: (re)draw UI elements |
| - help.js |
| - schema.js |
| - config.js |
+--------------------------------------------------------+
Basiscally, to change anything interesting, you should go into app.js
and make changes, taking care that you let all the setup<Stuff>()
functions run first, since they set stuff up and do the initial rendering.
For modal dialogs we use (abuse?) the :target
pseudo-selector.
To add a new modal dialog simply configure a new element with class="lightbox" id="your-id"
, then to display the modal use <a href="your-id">Link</a>
(or document.location.hash = "your-id"
)
In almost all cases, the Browser's developer tools are the best option.
A weak debug mode (localStorage.setItem('debug','true')
) will result in calls to log([])
getting displayed on the console.
You can create a nested log by passing {"label":"MyLabel","logs":[]}
Completely manual. Goodluck!
NOTE Most testing to date has been done in Chrome, and only the very slightest of attempts has been made at cross-browser testing.
- Documentation
- Error Examples (add to the troubleshooting section of
help.js
) - Example of Rollup/Cube
- Error Examples (add to the troubleshooting section of
- Features
- Query History: reverse chronological
- Schema Browser sidebar
- Schema Browser should filter to active table
- Schema Browser display to metadata about a dataset
- Project (ways to improve the project and code within)
- DRY the modals (with
<template>
etc) - Automated Testing
- Refactor to IFFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
- Build Script improvements like parellel curl, usage, etc
- Contribute to AnalzeBoston and/or as CKAN extension (See: https://docs.ckan.org/en/latest/extensions/index.html)
- DRY the modals (with
- Icebox (Things I'm not planning to implement)
- Editor Tabs (Do we really need this?)
- BUG: results for errors (Doesn't seem like this is needed?)
- Typehead: default transforms (e.g. into decimals, 1) create table of fully qualified names and types 2) implement
- Typeahad: transform hints: nullif('','')::decimal
- Adopt a framework
- Done
Developer GuideLayout: Resize & fullscreen panelsExample: CTE & WindowImprove Use of ConfigProxy (only needed to handle 409s)Separate scripts and CSSAdd DEBUG mode (withconsole.log()
)Example: PolygonFilter resultsLayout: Improve colors and positioningAdd datatype to schema for browser and typeaheadTypeahead Improvements: BUG: Typehead broken without tablenameTypeahead Improvements: Human readable table namesTypeahead Improvements: Show datatype in typeaheadTypeahead Improvements: Configurable autocomplete? (I think this means search tables until one is set)
Historyshow query historyRetrieve results
Scrape schema:SELECT * FROM "" LIMIT 1;
response.result.fields ex {type: "text", id: "year"}add basic typeaheadErrorslook at the response.success propertydisplay the error!
Download as CSV/TSVCopy to clipboardSchema browser panelEnable worksheet to have multiple queriesUsage InstructionsWelcome ScreenTrim semicolinsExample: PIVOT viaFILTER()
Example: PermitsExample: CrimeExample: 311Deeplinking (with query)Add Editor SavingChange Examples to dialog
This project is probably a good candidate for a CKAN extension
Some work will need to be done to genericize it.
We should look for indicators (e.g. field name contains "date") then set $.filed.info.type_override
in schema-generator.php
DateTime
_dt
_DT
_date
date$
timestamp
Total
Cost
- Move ace setup into app.js