-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ucast-prisma: support translation table and col names
- Loading branch information
Showing
6 changed files
with
118 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
"@styra/ucast-prisma": patch | ||
--- | ||
|
||
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. | ||
|
||
```typescript | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters