P.S.Nikhil
P.S.Nikhil
Explore posts from servers
DTDrizzle Team
Created by P.S.Nikhil on 1/14/2024 in #help
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
2 replies
TtRPC
Created by P.S.Nikhil on 12/15/2023 in #❓-help
How to cache trpc server request next.js app router
is it the right way ctx.headers.set( "Cache-Control", "public, max-age=43200, stale-while-revalidate=120, immutable", );
6 replies