postgres
postgres copied to clipboard
convert a specific column when reading or writing to the database
Dear expert,
Do the postgres support the similar functionality like the typeorm transformer? We have a request to convert the column value before updating/querying
export interface ColumnOptions extends ColumnCommonOptions {
/**
* Specifies a value transformer that is to be used to (un)marshal
* this column when reading or writing to the database.
*/
transformer?: ValueTransformer | ValueTransformer[];
}
i noticed the postgres also support transformer, but seem to a global change for all the tables, and the to is commented
/** Transforms incoming and outgoing row values */
value?: ((value: any) => any) | {
/** Transform function for values in result rows */
from?: ((value: unknown, column: postgres.Column<string>) => any) | undefined;
// to?: ((value: unknown) => any) | undefined; // unused
} | undefined;
Dear expert:
Any update?
You should have the info needed to make such functionality using transform, but that said, this is not an ORM, but a postgres driver embracing being as close to PostgreSQL as possible, so I'd recommend doing what you want to in a DB level trigger instead if possible?