Skip to content

How to parse columns of type geometry or geography? #465

Discussion options

You must be logged in to vote

It can be parsed by adding a custom parser for slonik. For example:

import wkx from 'wkx'
const geographyParser = (value: string | null): any | null => {
  if (value === null) {
    return null
  }

  const wkbBuffer = Buffer.from(value, 'hex')
  const geometry = wkx.Geometry.parse(wkbBuffer)
  return geometry.toGeoJSON()
}


// later in your slonik `createPool` options:
  {
    name: 'geography',
    parse: geographyParser,
  },

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kimmobrunfeldt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant