-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Are we able to use string instead of new Date() ? #123
Comments
I too have this problem! Especially since Postgres accepts microsecond precision which JavasScript Date objects do not support. |
This is not a perfect fix, but you can sort of trick Typescript into allowing a Date value, at least for const isoDateString = new Date().toISOString()
// 👇 where "date_column" is a `timestamp` column
await db.insertInto("foo").values({ date_column: isoDateString as unknown as Date }).execute() I had a project where I needed to insert a timestamp value as a string and this worked. |
This sounds like a duplicate of #121. Someone posted a solution there: import { Selectable } from 'kysely'
const results: Selectable<Thing> = await db.selectFrom('thing').selectAll().execute() Please check if that solves the issue. If so, I will add the solution to the README. |
@RobinBlomberg This is a different issue. The issue is that
No it doesn't. Restart vscode or reboot its typescript server. If you're able to compile that typescript, then surely the typescript running inside vscode also accepts the code. There's probably nothing kysely-codegen should do here. If you change the selectable type, then the result type is also function toDate(date: string) {
return sql<Date>`${date}`
}
const rows = await db
.selectFrom("overnight.daily_overnight_performance")
.where("date", "=", toDate("2023-06-02"))
.execute() I'd say this is cleaner than a cast. |
Should be fixed now in kysely-codegen@0.17.0! Use the new |
postgres generated code for table is:
I want to filter by date:
but it's an error:

and cannot run the script.
If I change Timestamp type from:
to:
it still shows the error:

but at least I can run the script.
Can you make it so it generates code where date string is acceptable for selection?
Upvote & Fund
The text was updated successfully, but these errors were encountered: