Schmavery / drizzle-postgis

A Drizzle extension/plugin to help work with PostGIS and GeoJSON
https://schmavery.github.io/drizzle-postgis/
MIT License
12 stars 3 forks source link

"TypeError: col.shouldDisableInsert is not a function" prevents inserts with drizzle-orm@0.32.0 and drizzle-kit@0.23.0 #13

Open sc-it-rabolto opened 1 month ago

sc-it-rabolto commented 1 month ago

First of all, thanks for your work with this great package!

I have encountered with an issue using the latest drizzle packages, when trying to insert rows which contains fields with drizzle-postgis models.

My schema is:

const locationTable = createTable('location', {
  id: uuid('id')
    .default(sql`gen_random_uuid()`)
    .primaryKey(),
  coordinate: gis.point('coordinate', { srid: 4326 }).notNull()
})

and the code for the insert:

import { type db } from '@/server/db'
import { location } from '@/server/db/schema'

import { faker } from '@faker-js/faker'
import { Point } from 'drizzle-postgis'

const point = { type: "Point", coordinates: [faker.location.longitude(), faker.location.latitude()] } satisfies Point
const rows = [{
      id: faker.string.uuid(),
      coordinate: point
}]

await db.insert(location).values(rows)

Running the code above the following exception is thrown:

Stacktrace:

TypeError: col.shouldDisableInsert is not a function
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\dialect.ts:459:94)
    at Array.filter (<anonymous>)
    at PgDialect.buildInsertQuery (D:\Projects\dh\node_modules\src\pg-core\dialect.ts:459:68)
    at QueryPromise.getSQL (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:307:23)
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:322:35)
    at Object.startActiveSpan (D:\Projects\dh\node_modules\src\tracing.ts:27:11)
    at QueryPromise._prepare (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:317:17)
    at <anonymous> (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:332:16)
    at Object.startActiveSpan (D:\Projects\dh\node_modules\src\tracing.ts:27:11)
    at QueryPromise.execute (D:\Projects\dh\node_modules\src\pg-core\query-builders\insert.ts:331:17)

By checking drizzle's source code here, I think the column class has been extended with a new method shouldDisableInsert, which is not found on the custom columns generetad by this package.

Schmavery commented 1 month ago

Thanks for raising this issue and including your preliminary investigation!

The weird thing to me is that we use the customType utility as described here

https://github.com/Schmavery/drizzle-postgis/blob/c0e2ded226ab27af4f7af7ad35f1394f3d38c220/src/models.ts#L103-L118

So I'd expect other peoples stuff to be breaking too? Any chance you can copy paste one of the examples from the drizzle customType docs and see if that works on your setup?

digitaldjango commented 4 weeks ago

I've the same issue trying to use a polygon field in my schema. Interestingly when I copy the polygon custom type code from the package into my schema file everything works...