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

ucast-prisma: support translation table and col names #355

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

srenatus
Copy link
Member

@srenatus srenatus commented Nov 7, 2024

support translating table and column names via extra options

An extra options object can be passed to ucastToPrisma to translate table and column names.
This is useful when the Prisma schema uses different names than the OPA policy used to generate
the conditions.

const p = ucastToPrisma(
  { or: [{ "tickets.resolved": false }, { "users.name": "ceasar" }] },
  "tickets0",
  {
    translations: {
      tickets: { $self: "tickets0", resolved: "resolved0" },
      users: { $self: "users0", name: "name0" },
    },
  }
);

In this example, the conditions { or: [{ "tickets.resolved": false }, { "users.name": "ceasar" }] }
will be rewritten to { OR: [{ tickets0: { resolved0: false } }, { users0: { name0: "ceasar" } }] },
assuming that the Prisma schema uses tickets0 and users0 as table names and resolved0 and name0
as column names respectively.

Copy link

changeset-bot bot commented Nov 7, 2024

🦋 Changeset detected

Latest commit: 2efe4e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@styra/ucast-prisma Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@srenatus srenatus force-pushed the push-yvmtknpzpqpq branch 4 times, most recently from 7be2211 to c48571c Compare November 7, 2024 09:55
@srenatus srenatus marked this pull request as ready for review November 7, 2024 09:55
@srenatus srenatus merged commit 5c7cb33 into main Nov 7, 2024
6 checks passed
@srenatus srenatus deleted the push-yvmtknpzpqpq branch November 7, 2024 10:01
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

Successfully merging this pull request may close these issues.

1 participant