Giter Club home page Giter Club logo

cartodb-sql-api's Introduction

CartoDB-SQL-API Build Status

The CARTO’s SQL API allows you to interact with your data inside CARTO, as if you were running SQL statements against a normal database.

  • Run queries with fine-grained permissions through Auth API.
  • Export data in multiple geospatial formats (CVS, geopackage, KML, SHP, spatialite, geojson, topojson, etc).
  • Schedule jobs using Batch Queries.
  • Copy queries allows you to use the PostgreSQL copy command for efficient streaming of data to and from CARTO.

Build

Requirements:

Optional:

PostGIS setup

A template_postgis database is expected. One can be set up with

$ createdb --owner postgres --template template0 template_postgis
$ psql -d template_postgis -c 'CREATE EXTENSION postgis;'

Install

To fetch and build all node-based dependencies, run:

$ npm install

Run

You can inject the configuration through environment variables at run time. Check the file ./config/environments/config.js to see the ones you have available.

While the migration to the new environment based configuration, you can still use the old method of copying a config file. To enabled the one with environment variables you need to pass CARTO_SQL_API_ENV_BASED_CONF=true. You can use the docker image to run it.

Old way:

$ node app.js <env>

Where <env> is the name of a configuration file under ./config/environments/.

Test

$ npm test

You can try to run the tests against the dependencies from the dev-env. To do so, you need to build the test docker image:

$ docker build -t sqlapi -f private/Dockerfile .
$ docker-compose -f private/docker-compose.yml build

Then you can run the tests like:

$ docker-compose -f private/docker-compose.yml  run sql-api-tests

It will mount your code inside a volume. In case you want to play and run npm test or something else you can do:

$ docker-compose -f private/docker-compose.yml run --entrypoint bash sql-api-tests

So you will have a bash shell inside the test container, with the code from your host.

⚠️ WARNING Some tests still fail inside the docker environment. Inside CI they don't yet use the ci folder to run the tests either. There is a failing test which prevents it.

Coverage

$ npm run cover

Open ./coverage/lcov-report/index.html.

Documentation

You can find an overview, guides, full reference, and support in CARTO's developer center. The docs directory contains different documentation resources, from a higher level to more detailed ones.

Contributing

Versioning

We follow SemVer for versioning. For available versions, see the tags on this repository.

License

This project is licensed under the BSD 3-clause "New" or "Revised" License. See the LICENSE file for details.

cartodb-sql-api's People

Contributors

alberhander avatar algunenano avatar alvarobp avatar andrewbt avatar andrewxhill avatar andy-esch avatar csobier avatar csubira avatar demimismo avatar dependabot[bot] avatar dgaubert avatar esloho avatar ethervoid avatar fdansv avatar javisantana avatar jgoizueta avatar jmnavarro avatar juanignaciosl avatar lekum avatar luisbosque avatar manuellr avatar matallo avatar oleurud avatar pramsey avatar rjimenezda avatar rochoa avatar shylpx avatar thedae avatar tokumine avatar zenitram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cartodb-sql-api's Issues

Do not hardcode geometry column names

The current code assumes "the_geom" and "the_geom_webmercator" both include geometric data.
ref: app/controllers/app.js

This ticket is to drop the assumption and actually check each field type instead.

Add support for SVG output format

Add support for format=svg.

How to return attributes ?
Should style be left to caller ? (I guess so, assuming it is possible).
Should identifier attribute be parameterizable or forced as "cartodb_id" or similar ?
Should transforms be left to caller ? (I guess so, assuming it is possible).
Should we automatically provide bounding box information to help with transforms ?

[REGRESSION] INSERT or UPDATE RETURNING returns no rows

The fix of #13 broke .. RETURNING .. queries because now any non-select is threated specially.

Needs to be fixed in the "master" branch.
Also needs automated tests, for both RETURNING and returning something meaningful for "affected rows" when there's no RETURNING clause

Review the README file

- Mention the requirement of a "publicuser" postgresql user
- Move configuration section before usage section (or within it)
- Merge "core requirements" and "dependencies" section ?
- ...

Basically just try to set things up w/out knowing anything about node.js and see if it works.
It's been done today with the "cartodb" README with good results.

Add modular authentication support

It's currently impossible to use the SQL-API without setting up a redis database and having the redis server running. Since it seems that redis use is authentication it would be nice to have the possibility to use other authentication mechanisms making it easier to just start an SQL-API with only PostgreSQL running.

metadata.test fails

uncaught: AssertionError: null == "1"
at /home/src/cartodb/CartoDB-SQL-API/test/unit/metadata.test.js:21:16

only add cache headers to unauthenticated queries

this sidesteps the obvious problems of us having to bypass the cache for mutable queries.

We know that all non-auth are read only, and also can assume that authenticated queries are by and large made as a result of writes being made against a table.

content-disposition

Would be nice to be able to push data to cartodb and then read right back into TileMill. TileMill likes a helping hand to know the file format of urls that respond with geodata and setting content-disposition will enable this. So, if the user requests:

http://tileio.cartodb.com/api/v1/sql?q=SELECT%20*%20FROM%20places_by_lon_lat&format=geojson
Then having cartodb set content-disposition to something like foo.geojson or foo.json would allow the data to be autorecognized as geojson in tilemill.

ref: https://github.com/Vizzuality/cartodb/issues/217

add cross origin headers on errors

when the api fails (i.e a query has syntax errors) the response has no cross origin headers and it is not posible to manage the error on the client side

KML output format

We want to support KML output.
It seems we supported it long ago, given issue #5
Commit 19b2829 by Andrew Hill seems to be the one introducing it on September 2011. Could not find the commit that removed it.

Add basic Auth to SQL API capabilities

bc back history

as node does not communicate with postgres we have to:

  • setup synching of the password hash to redis
  • reimpiment the password hashing algorithm that rails uses in redis
  • update the api itself to allow username/password
  • when user changes password, redis hash must be update (etc, you get the idea)

Error: socket hang up

Some requests result in a socket hang up error message. Sounds like a crash of the server, but I'm not sure what it is. Anyway I'd expect a meaningful error message always...

I can't install CartoDB-SQL-API en my machine

I didn't find anything about libxmljs in the README file.

This is the error:

npm ERR! [email protected] preinstall: make node
npm ERR! sh "-c" "make node" failed with 2
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! make node
npm ERR! You can get their info via:
npm ERR! npm owner ls libxmljs
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command "node" "/Users/jmedina/nvm/v0.6.14/bin/npm" "install"
npm ERR! cwd /Users/jmedina/Workspace/CartoDB-SQL-API
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.12
npm ERR! code ELIFECYCLE
npm ERR! message [email protected] preinstall: make node
npm ERR! message sh "-c" "make node" failed with 2
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/jmedina/Workspace/CartoDB-SQL-API/npm-debug.log
npm not ok

If you want to see the complete trace:

http://pastie.org/4596125

Drop redis hard dependency

Being able to specify connection parameters and permissions in a simple file would enable easier setup and testing.
Redis use should then be a pluggable thing to still play nicely with cartodb.

csv format output

Would be nice to be able to dump out rows as csv as well as json, geojson, and kml.

eg:

http://tileio.cartodb.com/api/v1/sql?q=SELECT%20*%20FROM%20places_by_lon_lat&format=csv

A parameter could be accepted to control what is done with the geometry. Options could include:

  • detect simple points, dump lon/lat in separate columns
  • dump geometry into a field called 'wkt' in WKT format
  • dump geometry in a single field as geojson (like datacouch.com)

Remove configuration from repository ?

Not sure what's the best practice here, but the .yml for main cartodb are not in the repo so maybe neither should the env.js in here, or we'd always be forced to work in a dirty git tree while developing if we need any special setting (PGSQL port for me..)

Server uses 100% CPU while sending data

Fetching data from the API shows "node" process keeping CPU 100% busy for the whole transfer period.
It took 6.5 minutes for me to download 148MB from "localhost" and for all that time node was up there heating the room

Process exits: remaining conns slots reserved for non-replication superuser conns

Running development branch of Carto-SQL-API (output from git rev-list --all | wc -l is 217) on an Ubuntu 12.04 LTS w/ PostgreSQL 9.1 installed. The output from SELECT postgis_lib_version(); reads:

POSTGIS="2.0.1 r9979" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 20
09" LIBXML="2.7.8" LIBJSON="UNKNOWN"

The SQL-API returns both GeoJSON and JSON from AJAX requests coming the client application (ModestMaps, markers.js, wax.js and jQuery). Inspecting the log files of 2 consecutive runs, the error is raised after 85 (1st run) and 87 (2nd run) SQL requests to port 8282 (at which the SQL API is listening). The max connection in postgresql.conf is set to 100.

Below you find the output from the node.js process:

events.js:45
throw arguments[1]; // Unhandled 'error' event
^
error: remaining connection slots are reserved for non-replication superuser connections
at [object Object]. (/home/gisuser/src/CartoDB-SQL-API/node_modules/pg/lib/connection.js:412:11)
at [object Object].parseMessage (/home/gisuser/src/CartoDB-SQL-API/node_modules/pg/lib/connection.js:287:17)
at Socket. (/home/gisuser/src/CartoDB-SQL-API/node_modules/pg/lib/connection.js:45:22)
at Socket.emit (events.js:64:17)
at Socket._onReadable (net.js:672:14)
at IOWatcher.onReadable as callback

Please let me know should you require further information to narrow down your investigation into this issue.

error msgs

when you execute some query and its wrong the server responds with a 400 error but the response does not include any error information.

It would be good to have something like (JSON):

{error: "rambo relation not found"}

SQL-API fails after doing a request

I've achieved install CartoDB-SQL-API, but now, when I make a request to the api the server fails.

1.9.2 :~/WorkSpace/CartoDB-SQL-API $ node app.js development
CartoDB SQL API listening on port 8080
FATAL ERROR: v8::HandleScope::Close() Local scope has already been closed

Node version: 0.6.14
NPM version: 1.1.12

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.