Skip to content

Commit

Permalink
Ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed May 19, 2014
1 parent 188cdee commit 3a6a754
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,19 @@ You need to specify a stringable primary key on the way in. The final keys look

cell!S2CELLID!PRIMARYKEY

Since this indexing scheme relies on range queries, it's unlikely primary IDs
will be used as hash keys in DynamoDB because you can [only do a range query within a single hash key](http://0x74696d.com/posts/falling-in-and-out-of-love-with-dynamodb-part-ii/).

## What about [MongoDB](http://www.mongodb.org/)?

MongoDB [uses S2 for its spherical indexes](http://blog.mongodb.org/post/50984169045/new-geo-features-in-mongodb-2-4).

Where [mongo turns cells into query parameters](https://github.com/mongodb/mongo/blob/f5ed485c97b08490f59234bc1ddef2c80c2c88b9/src/mongo/db/index/expression_index.h#L42-161).

## What about Amazon DynamoDB-geo?

It only supports point queries, and is written in Java.

## What kinds of queries are supported?

* intersects
Expand Down
48 changes: 48 additions & 0 deletions lib/dynamodb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var AWS = require('aws-sdk');

AWS.config.update({
accessKeyId: 'fake',
accessSecretKey: 'fake',

This comment has been minimized.

Copy link
@mick

mick May 19, 2014

Contributor

should be secretAccessKey

endpoint:new AWS.Endpoint('http://localhost:4567'),
region:'us-east-1'
});

var dynamo = new AWS.DynamoDB();

This comment has been minimized.

Copy link
@mick

mick May 19, 2014

Contributor

should pass the endpoint option to DynamoDB.

var dynamo = new AWS.DynamoDB({endpoint:new AWS.Endpoint('http://localhost:4567')});

var geoTable = {
'TableName': 'geo',
'AttributeDefinitions': [
{'AttributeName': 'id', 'AttributeType': 'S'},
{'AttributeName': 'data', 'AttributeType': 'S'}
],
'KeySchema': [
{'AttributeName': 'id', 'KeyType': 'RANGE'}
],
'ProvisionedThroughput': {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 50
},
'GlobalSecondaryIndexes': [
{
'IndexName': 'geo-index',
'KeySchema': [
{ 'AttributeName': 'id', 'KeyType': 'RANGE' }
],
'Projection': { 'ProjectionType': 'KEYS_ONLY' },
'ProvisionedThroughput': {
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 50
}
}
]
};

module.exports.createTable = function(client, cb) {
client.createTable(geoTable, function (err) {
console.log(arguments);
if (err) return cb(err);
cb(null);
});
};

module.exports.client = dynamo;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
"queue-async": "~1.0.7",
"s2": "~0.3.0",
"uniq": "~1.0.0",
"lodash": "~2.4.1"
"lodash": "~2.4.1",
"aws-sdk": "~2.0.0-rc.17"
},
"devDependencies": {
"tap": "~0.4.9",
"memdown": "~0.9.0"
"memdown": "~0.9.0",
"dynalite": "~0.3.6"
}
}
35 changes: 35 additions & 0 deletions test/dynamo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var test = require('tap').test,
dynamo = require('../lib/dynamodb');

function setup(cb) {
var dynalite = require('dynalite')({
createTableMs: 0,
updateTableMs: 0,
deleteTableMs: 0
});
dynalite.listen(4567, function() {
dynamo.createTable(dynamo.client, function() {
cb(function(end) {
dynalite.close(end);
});
});
});
}

test('dynamo', function(t) {
setup(function(close) {
var params = { tableName: 'cb' };

var doc = {
id: 'testing',
period: 1234,
requests: 5
};

dynamo.client.putItem(doc, params, function(err) {
close(function() {
t.end();
});
});
});
});

0 comments on commit 3a6a754

Please sign in to comment.