Created
February 16, 2018 15:04
-
-
Save malditogeek/a091277656aeb37766d884fc04bb488f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const WKX = require('wkx') | |
const Sequelize = require('sequelize') | |
// Workaround for the missing JSON-C (ST_GeomFromGeoJSON) dep in CloudSQL | |
// Issue: https://issuetracker.google.com/issues/37302950 | |
class CloudSQLGeo extends Sequelize.DataTypes.GEOGRAPHY { | |
constructor() { | |
super() | |
this.key = 'CustomGeo' | |
} | |
_stringify(value, options) { | |
var wkt = WKX.Geometry.parseGeoJSON(value).toWkt() | |
return `ST_GeomFromText('${wkt}', 4326)` | |
} | |
} | |
module.exports = { | |
CloudSQLGeo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment