© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
72 replies
volks

Custom Type interpreted as String

Hello everyone, I am having some issues with getting Drizzle to work with PostGIS, I am trying to have support for PostGIS's Point geometry. This is what I have setup

export type Point = {
    longitude: number;
    latitude: number;
};

export const pointDB = customType<
    {
        data: Point;
        driverData: string;
    }
>({
    dataType() {
        return 'GEOMETRY(POINT, 4326)';
    },
    toDriver(value: Point): string {
        return `SRID=4326;POINT(${value.longitude} ${value.latitude})`;
    },
    fromDriver(value: string): Point {
        const matches = value.match(/POINT\((?<longitude>[\d.-]+) (?<latitude>[\d.-]+)\)/);
        const { longitude, latitude } = matches.groups;

        return {
            longitude: parseFloat(longitude),
            latitude: parseFloat(latitude),
        };
    },
});
export type Point = {
    longitude: number;
    latitude: number;
};

export const pointDB = customType<
    {
        data: Point;
        driverData: string;
    }
>({
    dataType() {
        return 'GEOMETRY(POINT, 4326)';
    },
    toDriver(value: Point): string {
        return `SRID=4326;POINT(${value.longitude} ${value.latitude})`;
    },
    fromDriver(value: string): Point {
        const matches = value.match(/POINT\((?<longitude>[\d.-]+) (?<latitude>[\d.-]+)\)/);
        const { longitude, latitude } = matches.groups;

        return {
            longitude: parseFloat(longitude),
            latitude: parseFloat(latitude),
        };
    },
});


But the data returned stays a string

carriers: Array(1)0: 
id: "db34d18d-b4d0-42e2-8121-29d47ad18327"
location: "POINT(44.769368 20.4631)"
carriers: Array(1)0: 
id: "db34d18d-b4d0-42e2-8121-29d47ad18327"
location: "POINT(44.769368 20.4631)"


This is my query
const carriers = await db.select({
    id: activeCarriers.employeeId,
    location: sql<Point>`st_astext(active_carriers.location) as location`,
    })
    .from(activeCarriers)
return { carriers }
const carriers = await db.select({
    id: activeCarriers.employeeId,
    location: sql<Point>`st_astext(active_carriers.location) as location`,
    })
    .from(activeCarriers)
return { carriers }


This is happening across packages in monorepo, not sure if that could cause the type inference to fail
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Json column type returning as plain string?
Drizzle TeamDTDrizzle Team / help
16mo ago
bit type goes to postgresql as a string
Drizzle TeamDTDrizzle Team / help
2y ago
Timestamp as string
Drizzle TeamDTDrizzle Team / help
3y ago
sql`` expression being interpreted as JS literal in Drizzle Studio
Drizzle TeamDTDrizzle Team / help
2w ago
Next page