cartodb / cartodb-nodejs Goto Github PK
View Code? Open in Web Editor NEWNode.js package for easy access to CartoDB's APIs
License: BSD 4-Clause "Original" or "Old" License
Node.js package for easy access to CartoDB's APIs
License: BSD 4-Clause "Original" or "Old" License
Instead of Mocha's default
I was looking at the example in the readme and when I run the "var client = new CartoDB({..." , I receive an error saying 'new' object is not a function. Any thoughts?
We need the module owner to 'npm publish' the module new version.
@javisantana Can you publish the new version to npm?
thanks!
var isWriteQuery = CartoDB.prototype.isWriteQuery = function(sql) {
return /insert|alter|delete|update/gi.test(sql);//KGMOD added 'alter'
};
It's easy enough to use the SQL API to do something like user.cartodb.com/api/v2/sql?format=SHP&q=SELECT * FROM tablename
Being able to choose which format you'd like to view your data in is fantastic. How do I do that using this library?
Currently, SELECT * FROM tablename
is giving me nice JSON output, but I'd also like the ability to download shapefiles when necessary. Is that possible?
The callback function never seems to fire/data never get's returned to the callback. Event handling works fine. I'll try to put together some examples over my break.
Here's an example of how I'm handling my queries without using a callback:
var id = req.params.id;
client.query("select * from monroecountysnap where cartodb_id = " + id);
client.on('error', function (error) {
console.log("id fail");
});
client.on('data', function (data) {
res.send(data);
});
I'm not sure if this is deliberate or a bug. If the former, then the documentation should reflect the proper usage. I think we need a few more in depth examples of how to use the library. I'm happy to share my code, I'm just not sure how to share it without exposing my username and password for CartoDB while still allowing other developers access to the data. (Which should probably be it's own separate issue, should I just create a generic account that I don't mind sharing with the world?)
I wanna something like this:
client = CartoDB.connect(credentials);
client.on('connect', function() {
client.sql("select * from blabla");
})
client.on('data', function(results) {
//do something with results
});
client.on('error', fucntion() ...);
after doing an sql.execute()
a successful response returns a string, not parsed JSON. This is different behavior from v0.3.0 where it would return actual JSON.
I am getting when attempting to do an insert. Any ideas?
cartodb About to perform a POST query to https://rossc1.cartodb.com/api/v1/sql +0ms
cartodb There was an error with the request <html>
<head><title>411 Length Required</title></head>
<body bgcolor="white">
<center><h1>411 Length Required</h1></center>
<hr><center>nginx</center>
</body>
</html>
+194ms
We are tryingto use Busla's forked version to query our on-premise CartoDB instance at https://cartodb.brighterdevelopment.com
We tried a very simple test:
'use strict';
var CartoDB = require('cartodb');
exports.init = function(req, res){
var client = new CartoDB({user:"demo-admin",cartodb_url:"https://cartodb.brighterdevelopment.com", api_key:"OUR_API_KEY_GOES_HERE"});
var outputRows = function(err, data) {
// do something
};
client.on('connect', function() {
client
.query("select * from {table} limit 5", {table: 'ne_10m_populated_places_simple'}, outputRows)
});
client.connect();
};
NOTE: we also tested with the alternative parameter, "api_url", via the Master branch of cartodb-nodejs
We receive this error:
Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE
at SecurePair. (tls.js:1367:32)
at SecurePair.emit (events.js:92:17)
at SecurePair.maybeInitFinished (tls.js:979:10)
at CleartextStream.read as _read
at CleartextStream.Readable.read (_stream_readable.js:340:10)
at EncryptedStream.write as _write
at doWrite (_stream_writable.js:225:10)
at writeOrBuffer (_stream_writable.js:215:5)
at EncryptedStream.Writable.write (_stream_writable.js:182:11)
at write (_stream_readable.js:601:24)
Any help would be HUGELY appreciated.
Our goals is to query our on premise-instance via https.
We are open to any / all approaches.
Thank you!
Chai is a good one
In sql L96
debug('There was an error with the request %s', body.error);
There are cases where we are trying to make a request without internet service and the body message does not have a key error and so it throws a hard error and crashes the node program running. Bter to do a if (body && body.error) to keep this from happening.
Calling client.connect() before client.on('connect', func... will not work. Only figured this out after mucking around in the examples where connect is always called last. Improving the quality of the first impression makes it easier for people to start using the library.
Main Stack Overflow questions is here.
http://stackoverflow.com/questions/43686029/angular4-webpack-having-trouble-finding-loading-module
So is there a problem with CartoDB or ajv? I'm not that aware of how Carto handles their calls so maybe it's another lib not liking the difference in versioning?
Deprecated and will no longer be supported in 3.0 https://github.com/senchalabs/connect/wiki/Connect-3.0
underscore is already there and already contains a templating utility. Might have been sufficient here.
Even further, node support es6 template strings as of v4
The tmpl function should support multiple values e.g.
UPDATE {table} SET {field}= {val} WHERE ({id}>=32 AND {id}<=42) OR {id} IN (26, 28, 66)
Currently only the first {id} is replaced.
This may not be the most efficient way, but you could rewrite:
s = s.replace('{'+p+'}', d[p]);
as
s = s.split('{'+p+'}').join(d[p]);
I think the module does not depend on underscore but the package.json fetch the library.
Instead of :
SQL.execute(sql [,vars][, options][, callback])
Use :
SQL.execute(sql, options);
SQL.execute(sql, {
vars: vars
callback: callback
})
Pros :
I'm using the nodejs client, but not sure if this issue belongs to here or https://github.com/CartoDB/CartoDB-SQL-API.
When loading my site over HTTPS (eg. deployed on heroku), I am getting message warning me that the SQL request is sent over HTTP. Is there a way to configure so that all requests are sent over HTTPS?
Mixed Content: The page was loaded over HTTPS, but requested an insecure script
'http://jue.cartodb.com/api/v1/map?stat_tag=API&config=%7B%22version%22%3A%2…
_thumbnail%22%2C%22team_name%22%5D%7D%7D%5D%7D&callback=_cdbc_1212937049_1'.
This request has been blocked; the content must be served over HTTPS.
I don't know if this is truly an error, but if a single cartodbClient instance is reused among multiple simultaneous requests, the following error occurs:
_http_outgoing.js:335
throw new Error('Can't set headers after they are sent.');
^
so I can't do this:
var cartodbClient = new CartoDB({user: config.cartodb.USER, api_key: config.cartodb.API_KEY});
app.route('/myroute')
.post(function(req, res) {
cartodbClient.on('connect',function()....
but creating a new instance in the post handler works fine-
this library should be npm installable
Why is the import api limited to a fileName and or URL. Why can we not just pass a stream of raw data as an option? I would love this to exist so I can get rid of my own implementation.
As of today I believe the cartodb.com has been depracated and no longer works to make request and someone will need to update the cartodb.com/api/ to be carto.com/api/ in the /lib/resources.json file and then push the build to npm to allow people to upgrade and patch the problem. This is a BREAKING issue and a hot fix should be released.
README.md lines 40-43 says:
client.on('data', function(data) {
console.log(results.rows);
});
And results are undefined. It should be:
client.on('data', function(data) {
console.log(data.rows);
});
Cheers!
Since I host CartoDB myself I needed to allow for an additional parameter cartodb_url
and change resources.json
to reflect the change.
Creating a client can now be run with:
var client = new CartoDB({
user: secret.USER,
api_key: secret.API_KEY,
/* e.g. http://myusername.cartodb.com */
cartodb_url: ''
});
You want a PR?
File: lib/cartodb.js
Line: 119
if(sql.length > 2048)
this.oa.get(.....
I think the correct way it'd be:
if(sql.length < 2048)
this.oa.get(.....
Adding a shell command in the test section in the package.json is sufficient.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.