Skip to content

Instantly share code, notes, and snippets.

@malditogeek
Created February 16, 2018 15:04
Show Gist options
  • Save malditogeek/a091277656aeb37766d884fc04bb488f to your computer and use it in GitHub Desktop.
Save malditogeek/a091277656aeb37766d884fc04bb488f to your computer and use it in GitHub Desktop.
'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