diff --git a/README.md b/README.md index 42d45292..70bf931e 100644 --- a/README.md +++ b/README.md @@ -701,7 +701,7 @@ Asteroid Model's with a GeoPoint property and an attached DataSource may be quer Find the 3 nearest coffee shops. - CoffeeShop.attach(oracle); + CoffeeShop.attachTo(oracle); var here = new GeoPoint({lat: 10.32424, long: 5.84978}); CoffeeShop.find({where: {location: {near: here}}}, function(err, nearbyShops) { console.info(nearbyShops); // [CoffeeShop, ...] diff --git a/index.js b/index.js index f7cd0b3b..fcce0eb6 100644 --- a/index.js +++ b/index.js @@ -9,4 +9,10 @@ var asteroid = module.exports = require('./lib/asteroid'); */ asteroid.Connector = require('./lib/connectors/base-connector'); -asteroid.Memory = require('./lib/connectors/memory'); \ No newline at end of file +asteroid.Memory = require('./lib/connectors/memory'); + +/** + * Types + */ + +asteroid.GeoPoint = require('./lib/geo-point'); \ No newline at end of file diff --git a/lib/geo-point.js b/lib/geo-point.js new file mode 100644 index 00000000..f3010134 --- /dev/null +++ b/lib/geo-point.js @@ -0,0 +1,18 @@ +/** + * Export the `GeoPoint` class. + */ + +module.exports = GeoPoint; + +function GeoPoint(data) { + if(!(this instanceof GeoPoint)) { + return new GeoPoint(data); + } + + this.lat = data.lat; + this.long = data.long || data.lng; +} + +// TODO remove this +// register the type +require('jugglingdb/lib/model-builder').ModelBuilder.registerType(GeoPoint); \ No newline at end of file