Timestamp as string

so when i have a timestamp in string mode, setting new Date().toISOString() does not work - i need to drop the trailing Z from it can drizzle handle this?
2 Replies
Andrii Sherman
Maybe, not sure. We can perform runtime checks for valid strings in each dialect. However, I'm uncertain about the possibility of making your string a valid one. I need to think a bit more to determine if it's really possible (maybe it is). Regardless, there are other measures you can take to ensure your app handles dates exactly as you desire. You can implement a custom mapping logic to achieve the same timestamp in string mode behaviour but with more control.
const customStringTimestamp = customType<
{ data: string; driverData: string; config: { fsp: number } }
>({
dataType(config: { fsp: number }) {
const precision = typeof config.fsp !== 'undefined'
? ` (${config.fsp})`
: '';
return `timestamp${precision}`;
},
toDriver(value: string): string {
return value.slice(0, 19).replace('T', ' ')
}
});
const customStringTimestamp = customType<
{ data: string; driverData: string; config: { fsp: number } }
>({
dataType(config: { fsp: number }) {
const precision = typeof config.fsp !== 'undefined'
? ` (${config.fsp})`
: '';
return `timestamp${precision}`;
},
toDriver(value: string): string {
return value.slice(0, 19).replace('T', ' ')
}
});
thdxr
thdxrOP2y ago
yeah this is making me realize that iso8601 is not the standard basically i want mode: "string" to return iso8601 timestamps and same for writing them custom type is a good solution
Want results from more Discord servers?
Add your server