Efficient method for attribute conversion in schema transformations

What is the recommended method for converting certain attributes in my schema when saving it to a database?

Let's say I have the following schema defined:

const Something = Schema.Struct({
  id: SomethingId,
  createdAt: DateTimeUtc
});


Currently, I am using two separate transformations for reading and writing the entity (createdAt is an int with the millis in my database).

const ReadSomethingEntity = Schema.transform(
  Schema.Struct({
    id: SomethingId,
    createdAt: Schema.Int
  }),
  Something,
  // ...
);

const WriteSomethingEntity = Schema.transform(
  Schema.Struct({
    id: SomethingId,
    createdAt: Schema.Int
  }),
  Something,
  // ...
);


I'm wondering if there is a more efficient approach or shortcut that I might be overlooking.
Was this page helpful?