Closed tombohub closed 1 month ago
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 timestamp
columns in MySQL:
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 where
uses the Selectable
type, which is Date
in Timestamp
.
@tombohub
it still shows the error:
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 Date |Â string
. What you (the user) can do is create a helper function like this:
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 --date-parser
option.
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