https://github.com/appgeo/cartodb
carto sql lib for node
https://github.com/appgeo/cartodb
carto hacktoberfest knex nodejs
Last synced: 3 months ago
JSON representation
carto sql lib for node
- Host: GitHub
- URL: https://github.com/appgeo/cartodb
- Owner: AppGeo
- License: mit
- Created: 2015-05-08T18:07:11.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-10-04T14:39:13.000Z (about 3 years ago)
- Last Synced: 2025-07-06T00:56:22.493Z (3 months ago)
- Topics: carto, hacktoberfest, knex, nodejs
- Language: JavaScript
- Homepage:
- Size: 188 KB
- Stars: 18
- Watchers: 8
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
cartodb tools
===```bash
npm install cartodb-tools --save
```some tools for working with cartodb, for now works only with api keys.
API is shamelessly copied from [KNEX](http://knexjs.org/) as is much of the code,
see the documentation over their for details, currently does not support table creation.One difference is that geojson geometries are treated as such and converted to
geometries appropriate to the `the_geom` field in cartodb.```js
var cartodb = require('cartodb-tools')('username', 'api-key');cartodb('myTable')
.select('foo')
.where('bar', 'baz')
.then(function (resp) {
//use resp
})
.catch(function (err) {
// something bad happened
});
```Write Stream
```js
var cartodb = require('cartodb-tools')('username', 'api-key')
cartodb.createWriteStream('table_name', opts);
// available options are `create` to create a new table
```the query object has a few cartodb specific methods
# batch
the batch method will use the [carto batch api](https://carto.com/docs/carto-engine/sql-api/batch-queries/) method for doing the query, since this will never return results don't use it for selects, though you can if you want it's just kinda pointless
```js
cartodb('myTable')
.update({
foo: 'bar'
})
.where('bar', 'baz')
.batch()
.then(function (resp) {
//use resp
})
```you can also use the .onSuccess or .onError method to run those queries if the first one failed or succeeded
```js
cartodb('myTable')
.update({
foo: 'bar'
})
.where('fake collumn', 'baz')
.batch()
.onSuccess(cartodb('errors_log').insert({
error_message: 'NONE!',
date: cartodb.raw('CURRENT_TIMESTAMP')
}))
.onError('INSERT INTO errors_log (job_id, error_message, date) VALUES (\'<%= job_id %>\', \'<%= error_message %>\', NOW())')
.then(function (resp) {
//use resp
})
```By default raw queries are wrapped in a transaction, use `.noTransaction()` to avoid this, useful for queries that can't be in transactions
```js
cartodb.raw('VACUUM ANALYZE').noTransaction().batch().then(function () {
console.log('yay!');
}).catch(function () {
console.log('no!');
});
```