Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert a specific column when reading or writing to the database #825

Open
janiu-001 opened this issue Mar 13, 2024 · 2 comments
Open

convert a specific column when reading or writing to the database #825

janiu-001 opened this issue Mar 13, 2024 · 2 comments

Comments

@janiu-001
Copy link

janiu-001 commented Mar 13, 2024

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;
@janiu-001
Copy link
Author

Dear expert:

Any update?

@porsager
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants