Cardboard client generator
Parameters
configobject a configuration objectconfig.mainTablestring the name of a DynamoDB table to connect toconfig.regionstring 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('@mapbox/dyno')(dynoConfig),
});Returns cardboard a cardboard client
Parameters
inputFeature|FeatureCollection a GeoJSON object to write to the databasedatasetstring the dataset to write the feature tocallbackfunction 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
inputstring|Array(string) the feature idsdatasetstring the id of the dataset that these features belong tocallbackfunction 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
inputstring|Array(string) the feature idsdatasetstring the id of the dataset that these features belong tocallbackfunction 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
callbackfunction 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;
});