How to parse columns of type geometry or geography? #465
Answered
by
kimmobrunfeldt
kimmobrunfeldt
asked this question in
Q&A
-
Added this to document it for others I have How does one parse that? |
Beta Was this translation helpful? Give feedback.
Answered by
kimmobrunfeldt
Mar 5, 2023
Replies: 1 comment
-
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,
}, |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
kimmobrunfeldt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It can be parsed by adding a custom parser for slonik. For example: