How to format date?

I tried:
  const allPosts = db
    .select({
      ...getTableColumns(posts),
      formatted: sql<string>`to_char(created_at, 'Mon DD, YYYY')`,
    })
    .from(posts);

but it does not return an array of objects. How do I get an array of objects from the above query?
Similar to what this statement returns:
const allPosts = await db.select().from(posts); // returns {title:string...}[]
Was this page helpful?