开发者社区> 镜像站> NPM> cartodb-tools
cartodb-tools
knex based sql library for cartodb
Last updated 4 months ago by cwmma .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cartodb-tools 
SYNC missed versions from official npm registry.

cartodb tools

npm install cartodb-tools --save

some tools for working with cartodb, for now works only with api keys.

API is shamelessly copied from KNEX 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.

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

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 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

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

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

cartodb.raw('VACUUM ANALYZE').noTransaction().batch().then(function () {
  console.log('yay!');
}).catch(function () {
  console.log('no!');
});

Current Tags

  • 2.11.1                                ...           latest (4 months ago)

36 Versions

  • 2.11.1                                ...           4 months ago
  • 2.11.0                                ...           4 months ago
  • 2.10.0                                ...           a year ago
  • 2.9.0                                ...           a year ago
  • 2.8.1                                ...           2 years ago
  • 2.8.0                                ...           2 years ago
  • 2.7.1                                ...           2 years ago
  • 2.7.0                                ...           2 years ago
  • 2.6.5                                ...           2 years ago
  • 2.6.4                                ...           3 years ago
  • 2.6.3                                ...           3 years ago
  • 2.6.2                                ...           3 years ago
  • 2.6.1                                ...           3 years ago
  • 2.6.0                                ...           3 years ago
  • 2.5.0                                ...           4 years ago
  • 2.4.3                                ...           4 years ago
  • 2.4.2                                ...           4 years ago
  • 2.4.1                                ...           4 years ago
  • 2.4.0                                ...           4 years ago
  • 2.3.5                                ...           5 years ago
  • 2.3.4                                ...           5 years ago
  • 2.3.3                                ...           5 years ago
  • 2.3.2                                ...           5 years ago
  • 2.3.1                                ...           5 years ago
  • 2.3.0                                ...           5 years ago
  • 2.2.7                                ...           5 years ago
  • 2.2.6                                ...           5 years ago
  • 2.2.5                                ...           5 years ago
  • 2.2.4                                ...           5 years ago
  • 2.2.3                                ...           5 years ago
  • 2.2.2                                ...           5 years ago
  • 2.2.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (7)
Dev Dependencies (1)