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

no support for date column type? #914

Closed
edwinbernadus opened this issue May 27, 2024 · 4 comments · Fixed by #1177
Closed

no support for date column type? #914

edwinbernadus opened this issue May 27, 2024 · 4 comments · Fixed by #1177

Comments

@edwinbernadus
Copy link
Contributor

Does the database schema not support column Date type?
kysely has ColumnType<Date>

Screenshot 2024-05-27 at 17 06 36
@0xOlias
Copy link
Collaborator

0xOlias commented May 27, 2024

Hey @edwinbernadus, thanks for opening. We could consider adding a new primitive type (probably p.date()) that uses the JS native Date type in your indexing code. I don't know that there is an obvious choice of which column type to use at the SQL level (for both Postgres and SQLite) - any ideas?

It would be helpful to learn more about your use case. Most users store datetimes as UNIX timestamps using the p.bigint() or p.int() column type - is there a reason that doesn't work for you? We'll be more likely to prioritize this if we can understand how your use case may generalize to more users. Thanks!

@edwinbernadus
Copy link
Contributor Author

+1 for p.date()
datetime with timestamp

why prefer datetime to bigint?

  1. easier to read query result
  2. on the client side, no need to convert anymore from bigint to datetime

p.bigint() is ok, but it is so much better if provide p.date()

@0xOlias
Copy link
Collaborator

0xOlias commented May 28, 2024

on the client side, no need to convert anymore from bigint to datetime

The JS native Date object is not serializable, so Date values would still need to be converted to a string or number over the wire, and converted back into Date client-side. Also, Date is just a wrapper over a millisecond granularity Unix timestamp anyway (see screenshot).

Screen Shot 2024-05-28 at 12 46 51 PM

If you can provide a code snippet from a Ponder app or client app that demonstrates the clear value of a p.date() type, that would be very helpful.

@edwinbernadus
Copy link
Contributor Author

Since i dont have experience on kysely,
the snippet is on drizzle API
(apologize for that)

Table Definition (drizzle)

blockTimestamp: timestamp("block_timestamp", {
            withTimezone: true,
        }).notNull(),
Screenshot 2024-05-29 at 19 22 31

Function to convert from timestamp to date

export function convertTimestampToDate(timestamp: bigint) {
    return new Date(Number.parseInt(timestamp.toString()) * 1000);
}

@kyscott18 kyscott18 mentioned this issue Oct 21, 2024
@kyscott18 kyscott18 linked a pull request Oct 21, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Todo to Done in Ponder Roadmap Nov 8, 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 a pull request may close this issue.

2 participants