drizzle-cursor icon indicating copy to clipboard operation
drizzle-cursor copied to clipboard

Does not work with date columns

Open erickreutz opened this issue 1 year ago • 8 comments

const cursorConfig: CursorConfig = {
  cursors: [{ order: 'DESC', key: 'createdAt', schema: schema.users.createdAt }],
  primaryCursor: { order: 'DESC', key: 'id', schema: schema.users.id },
};

const cursor = generateCursor(cursorConfig);

When then passing it to db.queries.users.findMany results in:

value.toISOString is not a function. (In 'value.toISOString()', 'value.toISOString' is undefined)

erickreutz avatar Feb 01 '24 20:02 erickreutz

Got the same issue

croshim avatar Feb 08 '24 20:02 croshim

Hi @erickreutz @croshim do you have a reproducible example? I added some tests and SQL generated query works fine, I guess could be due to null record that drizzle's eq, gt or lt functions not handle.

xantiagoma avatar Feb 15 '24 03:02 xantiagoma

Hi,

I was able to find a workaround for this error by changing the schema definition from:

createdAt: timestamp('created_at').notNull().defaultNow(),

to

createdAt: timestamp('created_at', { mode: 'string' }).notNull().defaultNow(),

croshim avatar Feb 16 '24 09:02 croshim

yes,same problem. this fixed.

 createdAt: customTimestamp('createdAt', {
      withTimezone: true,
      precision: 3,
    })
      .notNull().default(sql`now()`),

productdevbook avatar Mar 01 '24 07:03 productdevbook

I want my date column to be nullable

erickreutz avatar Mar 09 '24 21:03 erickreutz

Experiencing the same error. Tried with both drizzle v0.29.5 and v0.30.10. Same "value.toISOString" message.

elijaholmos avatar May 24 '24 20:05 elijaholmos

I have the same issue.

Making this change solved, but it doesn't feel great.

createdAt: timestamp('created_at').notNull().defaultNow(),

to

createdAt: timestamp('created_at', { mode: 'string' }).notNull().defaultNow(),

vwnd avatar Sep 10 '24 11:09 vwnd

Could someone provide a reproducible minimal example? I've been trying to figure it out the error on

  • https://github.com/xantiagoma/drizzle-cursor/blob/main/test/extended/dates.pg.test.ts
  • https://github.com/xantiagoma/drizzle-cursor/blob/main/test/extended/dates.mysql.test.ts but not luck yet.

xantiagoma avatar Sep 10 '24 21:09 xantiagoma