drizzle postgis geometry always geometry(point)

Hello, i am currently testing out the basic postGis support and it would be nice if i can get it working as desired... Basically i want point/pointZ and linestring/linestringZ... The 0.31.0 release added geometry from the PostgreSQL PostGIS extension, however, as indicated it currently only supports type: "point". But the release also states, that we can specify any other string to use some other type...
type

The current release has a predefined type: point, which is the geometry(Point) type in the PostgreSQL PostGIS extension. You can specify any string there if you want to use some other type
type

The current release has a predefined type: point, which is the geometry(Point) type in the PostgreSQL PostGIS extension. You can specify any string there if you want to use some other type
i was wondering what steps are necessary to get eg: linestring to work? point: geometry("point", { type: "point" }), or point: geometry("point", { type: "pointZ" }),results in:
CREATE TABLE "test" (
"point" geometry(point)
)
CREATE TABLE "test" (
"point" geometry(point)
)
on drizzle-kit generate with linestring i tried: linestring: geometry("linestring", { type: "linestring" }) or linestring: geometry("linestring", { type: "linestringZ" }) resulting in:
CREATE TABLE "test" (
"linestring" geometry(point)
)
CREATE TABLE "test" (
"linestring" geometry(point)
)
on drizzle-kit generate the only way to get around this issue that i am currently aware is just manually swap out the geometry(point) with geometry(linestring) in the generated sql and then migrate...
3 Replies
eXecuteye
eXecuteyeOP9mo ago
I have looked a bit more into it and it seems that the geometry field is really only meant for point as sqlType for geometry seems to be hardcoded to point and the mapFrom/ToDriverValue function only supports 2 dimensional points for now...
export class PgGeometryObject<T extends ColumnBaseConfig<'json', 'PgGeometryObject'>> extends PgColumn<T> {
static readonly [entityKind]: string = 'PgGeometryObject';

getSQLType(): string {
return 'geometry(point)';
}

override mapFromDriverValue(value: string): { x: number; y: number } {
const parsed = parseEWKB(value);
return { x: parsed[0], y: parsed[1] };
}

override mapToDriverValue(value: { x: number; y: number }): string {
return `point(${value.x} ${value.y})`;
}
}
export class PgGeometryObject<T extends ColumnBaseConfig<'json', 'PgGeometryObject'>> extends PgColumn<T> {
static readonly [entityKind]: string = 'PgGeometryObject';

getSQLType(): string {
return 'geometry(point)';
}

override mapFromDriverValue(value: string): { x: number; y: number } {
const parsed = parseEWKB(value);
return { x: parsed[0], y: parsed[1] };
}

override mapToDriverValue(value: { x: number; y: number }): string {
return `point(${value.x} ${value.y})`;
}
}
dee
dee9mo ago
was just trying to figure out the same thing, thanks for investigating
peachneo
peachneo5mo ago
yes docs appear inconsistent with implementation

Did you find this page helpful?