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

Upsert unique constraint column names are not normalized #9

Open
danielrearden opened this issue Aug 25, 2020 · 3 comments
Open

Upsert unique constraint column names are not normalized #9

danielrearden opened this issue Aug 25, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@danielrearden
Copy link

The column names passed in through the uniqueConstraintColumnNames parameter should be normalized just like the named value bindings are. In other words, if I submit { emailAddress: '[email protected]' } as the value bindings, I should be able to submit ['emailAddress'] as the unique constraint column. Right now, I have to normalize the name myself (i.e. ['email_address']).

@gajus gajus added the enhancement New feature or request label Aug 26, 2020
@gajus
Copy link
Owner

gajus commented Aug 26, 2020

The logic for handling normalization of keys is because ESLint may enforce id-match rule.

The same reason does not apply for unique constraints.

In some thread it was even discussed that we should allow to override this using explicit sql.identifier, e.g.

update(
  connection,
  'user',
  {
    [sql.identifier(['given_name'])]: 'foo'
  }
);

What's the logic for needing the unique constraint to be normalized?

@danielrearden
Copy link
Author

Beyond just consistency, it would also allow for some additional type safety when entering the unique column names:

function upsert<T extends NamedValueBindingsType> (
  connection: DatabaseConnectionType,
  tableName: string,
  namedValueBindings: T,
  inputUniqueConstraintColumnNames: ReadonlyArray<keyof T> | null = null,
  inputConfiguration: UpsertConfigurationType | null = null,
): Promise<unknown>

@gajus
Copy link
Owner

gajus commented Aug 26, 2020

Interesting. I like this. Will patch it up.

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

No branches or pull requests

2 participants