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)) };
  },
});


I'm getting this error,
error: type "geometry(Point,4326)" does not exist

I have installed postgis extension on supabase
Was this page helpful?