Cardboard client generator
Parameters
config
object a configuration objectconfig.mainTable
string the name of a DynamoDB table to connect toconfig.region
string the AWS region containing the DynamoDB tableconfig.dyno
[dyno] a pre-configured dyno client for connecting to DynamoDB
Examples
var cardboard = require('cardboard')({
table: 'my-cardboard-table',
region: 'us-east-1',
});
var cardboard = require('cardboard')({
dyno: require('dyno')(dynoConfig),
});
Returns cardboard a cardboard client
Parameters
input
Feature|FeatureCollection a GeoJSON object to write to the databasedataset
string the dataset to write the feature tocallback
function the callback for the error and repsonse to be passed to
Examples
// Create a point, then retrieve it.
var feature = {
type: 'Feature',
properties: {},
geometry: {
type: 'Point',
coordinates: [0, 0]
}
};
cardboard.put(feature, 'my-dataset', function(err, result) {
err === undefined; // no error
result.features.length === 1; // one feature was added
result.features[0].id === 'random-id'; // that is a bit more random
});
Delete features from a dataset
Parameters
input
string|Array(string) the feature idsdataset
string the id of the dataset that these features belong tocallback
function the callback function to handle the response
Examples
carboard.del('feature-id', 'dataset-id', function(err) {
err === undefined; // unless something is really broken
});
carboard.del(['feature-one', 'feature-two'], 'dataset-id', function(err) {
err === undefined; // unless something is really broken
});
Retrieve a feature collection for a list of feature ids
Parameters
input
string|Array(string) the feature idsdataset
string the id of the dataset that these features belong tocallback
function the callback function to handle the response
Examples
cardboard.get('feature-id', 'my-dataset', function(err, final) {
if (err) throw err;
final.features[0].id === 'feature-id'; // true: the feature was retrieved
});
// get multiple features at once
cardboard.get(['one', 'two'], 'my-dataset', function(err, result) {
err === undefined;
result.features.length === 2; // a feature for each id
});
// Attempt to retrieve a feature that does not exist
cardboard.get('non-existent-feature', 'my-dataset', function(err, result) {
err === undefined; // this is not an error
result.features.length === 0; // nothing was found
});
Create a DynamoDB table with Cardboard's schema
Parameters
callback
function the callback function to handle the response
Examples
// Create the cardboard table specified by the client config
cardboard.createTable(function(err) {
if (err) throw err;
});