fix: update timestamp definition if date parser is string#244
fix: update timestamp definition if date parser is string#244gdaybrice wants to merge 1 commit intoRobinBlomberg:masterfrom
Conversation
|
I added the Dates and timestamps are fundamentally different concepts. Timestamps can accurately be represented in a JS I think a lot of people want date columns as JS strings, but timestamp columns as JS Dates, and this PR would make that combination impossible. |
|
Thanks @brianmcd - so probably need another flag to target timestamps separately? |
|
Just wanted to voice my support for this feature addition. A new flag to define timestamps as strings would be great.
|
|
@kyle-mcguire this is exactly why I want to enforce strings, because of |
|
Just adding another +1 for a solution here (happy to have a separate flag if needed)! It would be great to be able to switch everything to strings at the driver level and have the ability to generate the equivalent types. Today I have to wrap the export type DateToString<T> = {
[P in keyof T]: T[P] extends Date ? string : T[P]
}
export function jsonArrayFrom<O>(expr: Expression<O>) {
const s = sql<
Simplify<O>[]
>`(select coalesce(json_agg(agg), '[]') from ${expr} as agg)`
return s as RawBuilder<Simplify<DateToString<O>>[]>
} |
|
I would also love a flag to indicate that |
|
Ty for this change. would love to see this merged! Eager for this fix :). |
|
FYI folks following this, looks like the custom type def feature just merged takes care of this. Confirming this works and can be achieved with this flag set: kysely-codegen --type-mapping='{"timestamp":"string","timestamptz":"string","date":"string"}' |
When using
--date-parser string, only thedatescalar type is updated to use string, while theTimestamptype definition still includesDate. This results in inconsistent type generation where timestamp columns still showDate | stringinstead of juststring.Current Behavior
With
--date-parser string, the generated types show:Expected Behavior
With
--date-parser string, the generated types should show:Proposed Fix
In
src/generator/dialects/postgres/postgres-adapter.ts, update the constructor to handle bothdatescalar andTimestampdefinition:Additional Context
datescalar type but not theTimestampdefinition--date-parser stringFixes #243