Skip to content

Commit

Permalink
Updates for README, add keywords for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
russellsteadman committed Apr 11, 2023
1 parent c4fd96d commit 40863b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
example
test
test
.github
56 changes: 30 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Geo Library for Amazon DynamoDB
# Geo Querying for Amazon DynamoDB

This project is an unofficial port of [awslabs/dynamodb-geo][dynamodb-geo] (based on the [original](https://github.com/robhogan/dynamodb-geo.js) by Rob Hogan), bringing creation and querying of geospatial data to Node JS developers using [Amazon DynamoDB][dynamodb].
This project is a Node.js location querying library for [Amazon DynamoDB][dynamodb] through geohashing. It is based on AWS's [awslabs/dynamodb-geo][dynamodb-geo] and Rob Hogan's [robhogan/dynamodb-geo.js][dynamodb-geo-js], and it works directly with [AWS DynamoDB SDK][aws-sdk-dynamodb].

## Features

Expand All @@ -18,10 +18,11 @@ npm install dynamo-locx

## Getting started

First you'll need to import the AWS sdk and set up your DynamoDB connection:
Start by setting up the DynamoDB client. This is the same as you would do for any other DynamoDB application. For local development, you can use the following:

```js
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";

const ddb = new DynamoDBClient({
endpoint: "http://localhost:8000", // For local development only
region: "us-east-1",
Expand All @@ -30,26 +31,22 @@ const ddb = new DynamoDBClient({

To test locally, you can run `docker run -p 8000:8000 deangiberson/aws-dynamodb-local` to spin up a local docker instance exposed on port 8000.

Next you must create an instance of `GeoDataManagerConfiguration` for each geospatial table you wish to interact with. This is a container for various options (see API below), but you must always provide a `DynamoDB` instance and a table name.
Next, create an instance of `GeoDataManagerConfiguration` for each geospatial table. This allows you to configure per-table options, but at minimum you must provide a `DynamoDB` instance and a table name. See the [configuration reference][#configuration-reference] for more details.

```js
import ddbGeo from "dynamo-locx";
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, "MyGeoTable");
```

You may modify the config to change defaults.

```js
const config = new ddbGeo.GeoDataManagerConfiguration(ddb, "MyGeoTable");
config.longitudeFirst = true; // Use spec-compliant GeoJSON, incompatible with awslabs/dynamodb-geo
```

Finally, you should instantiate a manager to query and write to the table using this config object.
Then use the configuration to instantiate a manager to query and write to the table.

```js
const myGeoTableManager = new ddbGeo.GeoDataManager(config);
```

## Choosing a `hashKeyLength` (optimising for performance and cost)
## Choosing a hash key length

The `hashKeyLength` is the number of most significant digits (in base 10) of the 64-bit geo hash to use as the hash key. Larger numbers will allow small geographical areas to be spread across DynamoDB partitions, but at the cost of performance as more [queries][dynamodb-query] need to be executed for box/radius searches that span hash keys. See [these tests][hashkeylength-tests] for an idea of how query performance scales with `hashKeyLength` for different search radii.

Expand Down Expand Up @@ -90,12 +87,12 @@ console.dir(createTableInput, { depth: null });
ddb
.send(new CreateTableCommand(createTableInput))
// Wait for it to become ready
.then(function () {
return waitForTableToBeReady(
.then(() =>
waitForTableToBeReady(
{ client: ddb, maxWaitTime: 20 },
{ TableName: config.tableName }
);
})
)
)
.then(function () {
console.log("Table created and ready!");
});
Expand All @@ -106,20 +103,21 @@ ddb
```js
myGeoTableManager
.putPoint({
RangeKeyValue: { S: "1234" }, // Use this to ensure uniqueness of the hash/range pairs.
RangeKeyValue: { S: "1234" }, // Use this to ensure uniqueness of the hash/range pairs
GeoPoint: {
// An object specifying latitutde and longitude as plain numbers. Used to build the geohash, the hashkey and geojson data
// An object specifying latitude and longitude as plain numbers
// These are used to build the geohash, the hashkey, and geojson data
latitude: 51.51,
longitude: -0.13,
},
PutItemInput: {
// Passed through to the underlying DynamoDB.putItem request. TableName is filled in for you.
// Passed through to the underlying PutItem request, TableName is prefilled
Item: {
// The primary key, geohash and geojson data is filled in for you
country: { S: "UK" }, // Specify attribute values using { type: value } objects, like the DynamoDB API.
// The primary key, geohash, and geojson data are prefilled
country: { S: "UK" }, // Specify attribute values using the AttributeValue type
capital: { S: "London" },
},
// ... Anything else to pass through to `putItem`, eg ConditionExpression
// ... Anything else to pass through to PutItem request, e.g. ConditionExpression
},
})
.then(function () {
Expand All @@ -140,7 +138,7 @@ myGeoTableManager
.updatePoint({
RangeKeyValue: { S: "1234" },
GeoPoint: {
// An object specifying latitutde and longitude as plain numbers.
// An object specifying latitude and longitude as plain numbers.
latitude: 51.51,
longitude: -0.13,
},
Expand Down Expand Up @@ -304,6 +302,14 @@ Because all paginated `Query` results are loaded into memory and processed, it m

The Geohash used in this library is roughly centimeter precision. Therefore, the library is not suitable if your dataset has much higher density.

## License

Where not otherwise noted, copyright project contributors and licensed under an Apache 2.0 License. See LICENSE for full details.

## Legal Disclaimer

This project is not affiliated with or endorsed by Amazon Technologies, Inc. or any of its affiliates. Amazon and DynamoDB are trademarks of Amazon Technologies, Inc. and used nominatively only.

[npm]: https://www.npmjs.com
[updateitem]: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html
[deleteitem]: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_DeleteItem.html
Expand All @@ -314,11 +320,9 @@ The Geohash used in this library is roughly centimeter precision. Therefore, the
[geojson]: https://geojson.org/geojson-spec.html
[example]: https://github.com/russellsteadman/dynamo-locx/tree/master/example
[dynamodb-geo]: https://github.com/awslabs/dynamodb-geo
[dynamodb-geo-js]: https://github.com/robhogan/dynamodb-geo.js
[dynamodb]: http://aws.amazon.com/dynamodb
[dynamodb-query]: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
[hashkeylength-tests]: https://github.com/russellsteadman/dynamo-locx/blob/master/test/integration/hashKeyLength.ts
[choosing-hashkeylength]: #choosing-a-hashkeylength-optimising-for-performance-and-cost

## License

Apache 2.0 © 2023 Russell Steadman, Rob Hogan. See LICENSE for full details.
[aws-sdk-dynamodb]: https://www.npmjs.com/package/@aws-sdk/client-dynamodb
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dynamo-locx",
"version": "0.1.0",
"description": "A javascript port of awslabs/dynamodb-geo, for dynamodb geospatial querying",
"description": "Simple geospatial querying for Amazon DynamoDB",
"scripts": {
"prepublish": "tsc",
"clean": "rimraf dist",
Expand All @@ -13,6 +13,18 @@
"author": "Russell Steadman <[email protected]> (https://www.russellsteadman.com/)",
"repository": "https://github.com/russellsteadman/dynamo-locx.git",
"license": "Apache-2.0",
"keywords": [
"dynamodb",
"geospatial",
"geo",
"location",
"geoquery",
"aws",
"geohash",
"geodata",
"geojson",
"geolocation"
],
"dependencies": {
"long": "^5.2.1",
"nodes2ts": "^2.0.0"
Expand Down

0 comments on commit 40863b2

Please sign in to comment.