Postgis

Custom location data type
import { customType } from "drizzle-orm/pg-core";

export interface Point {
lat: number;
lng: number;
}

export const pointType = customType<{ data: Point; driverData: string }>({
dataType() {
return "geometry(Point,4326)";
},
toDriver(value: Point): string {
return `SRID=4326;POINT(${value.lng} ${value.lat})`;
},
fromDriver(value: string) {
const matches = value.match(/POINT\((?<lng>[\d.-]+) (?<lat>[\d.-]+)\)/);
const { lat, lng } = matches?.groups ?? {};

if (!matches) {
console.warn(
`Could not parse point value in function pointType.fromDriver
Currently returning() is not supported and select must use a
custom select like so: db.select({ geo: selectPoint('geo', place.geo) })`,
value,
);
}

return { lat: parseFloat(String(lat)), lng: parseFloat(String(lng)) };
},
});
import { customType } from "drizzle-orm/pg-core";

export interface Point {
lat: number;
lng: number;
}

export const pointType = customType<{ data: Point; driverData: string }>({
dataType() {
return "geometry(Point,4326)";
},
toDriver(value: Point): string {
return `SRID=4326;POINT(${value.lng} ${value.lat})`;
},
fromDriver(value: string) {
const matches = value.match(/POINT\((?<lng>[\d.-]+) (?<lat>[\d.-]+)\)/);
const { lat, lng } = matches?.groups ?? {};

if (!matches) {
console.warn(
`Could not parse point value in function pointType.fromDriver
Currently returning() is not supported and select must use a
custom select like so: db.select({ geo: selectPoint('geo', place.geo) })`,
value,
);
}

return { lat: parseFloat(String(lat)), lng: parseFloat(String(lng)) };
},
});
I'm getting this error, error: type "geometry(Point,4326)" does not exist I have installed postgis extension on supabase
1 Reply
P.S.Nikhil
P.S.NikhilOP11mo ago
if i change datatype geometry(Point,4326) -> geometry(Point) it's inserting values 0101000020E610000036AB3E575B674440B48EAA26887C52C0 into the table
Want results from more Discord servers?
Add your server