Effect CommunityEC
Effect Community11mo ago
5 replies
James!

Configuring SQL Schema to Return Dates as Strings Instead of JS Date Objects

I am curious to know how I can get SqlSchema & the internal DB driver it uses to return dates as "Strings" instead of converting them to JS Date.

My ideal situation is that all date transformations would be handled by my Effect schema.

I dont like the idea of going db driver -> convert to Date -> Effect schema converts Date to Utc. There is now another layer I need to worry about (pg driver doing date conversions). I'd much prefer leaving all Date stuff to a single layer (Effect schema)
By having this extra layer I now need to ensure my environment is configured correctly handle Dates with JS

export const PgLive = PgClient.layer({
  ...fields,
   // I couldn't find a setting to configure this
});

 SqlSchema.findOne({
        Request: S.String,
        Result: S.Struct({ 
            date: S.DateTimeUtcFromDate, <~ I'd prefer to use S.DateTimeUtc & convert an inocoming string -> S.DateTimeUtc
       }),
        Returning: (id) => sql`select * from docs where id ${id}`
})
Was this page helpful?