Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#1113): postgres parse date value from string or date object #3143

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Venipa
Copy link

@Venipa Venipa commented Oct 17, 2024

#1113 since this issue is still open and i recently started using pglite with electron i got this issue.

fixed it by just returning a new date that allows a Date and a string argument without changing much.

@zfben
Copy link

zfben commented Nov 15, 2024

when will this request merge?

@Venipa
Copy link
Author

Venipa commented Nov 15, 2024

@Angelelz any update on this issue? #1113

@pranshuchittora
Copy link

This issue is a major blocker, I can confirm that this change fixes this issue. Not sure about any side-effects or edge cases.
In case anyone needs patch via patch-package

patches/drizzle-orm+0.38.2.patch

diff --git a/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs b/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
index f558f6c..32185fa 100644
--- a/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
+++ b/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
@@ -58,7 +58,7 @@ class PgTimestamp extends import_common.PgColumn {
     return new Date(this.withTimezone ? value : value + "+0000");
   };
   mapToDriverValue = (value) => {
-    return value.toISOString();
+      return new Date(value).toISOString();
   };
 }
 class PgTimestampStringBuilder extends import_date_common.PgDateColumnBaseBuilder {
diff --git a/node_modules/drizzle-orm/pg-core/columns/timestamp.js b/node_modules/drizzle-orm/pg-core/columns/timestamp.js
index 5f793f0..b455b04 100644
--- a/node_modules/drizzle-orm/pg-core/columns/timestamp.js
+++ b/node_modules/drizzle-orm/pg-core/columns/timestamp.js
@@ -31,7 +31,7 @@ class PgTimestamp extends PgColumn {
     return new Date(this.withTimezone ? value : value + "+0000");
   };
   mapToDriverValue = (value) => {
-    return value.toISOString();
+    return new Date(value).toISOString();
   };
 }
 class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {

@koitoror
Copy link

Its a major blocker ..

@pranshuchittora
Copy link

This issue is a major blocker, I can confirm that this change fixes this issue. Not sure about any side-effects or edge cases. In case anyone needs patch via patch-package

patches/drizzle-orm+0.38.2.patch

diff --git a/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs b/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
index f558f6c..32185fa 100644
--- a/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
+++ b/node_modules/drizzle-orm/pg-core/columns/timestamp.cjs
@@ -58,7 +58,7 @@ class PgTimestamp extends import_common.PgColumn {
     return new Date(this.withTimezone ? value : value + "+0000");
   };
   mapToDriverValue = (value) => {
-    return value.toISOString();
+      return new Date(value).toISOString();
   };
 }
 class PgTimestampStringBuilder extends import_date_common.PgDateColumnBaseBuilder {
diff --git a/node_modules/drizzle-orm/pg-core/columns/timestamp.js b/node_modules/drizzle-orm/pg-core/columns/timestamp.js
index 5f793f0..b455b04 100644
--- a/node_modules/drizzle-orm/pg-core/columns/timestamp.js
+++ b/node_modules/drizzle-orm/pg-core/columns/timestamp.js
@@ -31,7 +31,7 @@ class PgTimestamp extends PgColumn {
     return new Date(this.withTimezone ? value : value + "+0000");
   };
   mapToDriverValue = (value) => {
-    return value.toISOString();
+    return new Date(value).toISOString();
   };
 }
 class PgTimestampStringBuilder extends PgDateColumnBaseBuilder {

This diff should work, but we need to adapt the types too, because when I run this patch, I am seeing issues with the drizzle-zod schema validation. Not sure how much related this is w.r.t. to this PR.

@EntropyValley
Copy link

Will this be patched into the other cores as well? I'm seeing a similar issue with mysql.

@Venipa Venipa changed the title fix(#1113): parse date value from string or date object fix(#1113): postgres parse date value from string or date object Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants