-
Notifications
You must be signed in to change notification settings - Fork 860
Raw database access fallback #2052
Comments
Hello, I'd like ask you what the man can imagine under given issue? Very thanks for explaining the initial intension. |
The |
Hi, I noticed the examples given here as well as in the release notes don't actually work due to this bug: prisma/prisma#3300 |
Why does this api is not exposed in "prisma-binding"? |
@terion-name - thanks for opening the issue in prisma-binding! It would be great for somebody in the community to open a pull-request adding support. Keep in mind that we have an upcoming addition to add support for parameter interpolation. It might be worth it to wait for this change. cc @maticzav |
@sorenbs I believe |
@maticzav well I've checked - bindings do not expose UPD |
Introduction
Prisma exposes a flexible API that conforms to the OpenCRUD specification.
This API has excellent developer ergonomics and is powerful enough to cover most use cases. Sometimes, however you need to drop down to the native API of the underlying database to performa a more complex operation. This ticket specifies how raw database access can be exposed in the existing GraphQL API.
API
Considerations:
The two following API extensions are proposed:
Option A: Nested input
Option B: Enum based
Option B should have
database
be an optional argument.Databases
SQL
SQL databases are queried using a SQL string:
Return value is an array of objects:
To return multiple result sets, simply use aliases to perform multiple
executeRaw
mutationsMongoDB
MongoDB is queried using a string containing a normal MongoDB query operation:
Return value is an array of objects:
Some mongo queries return a single object. In that case the single object is wrapped in an array.
Elasticsearch
Elastic is queried using the normal query DSL:
And returns an array of objects:
Redis
Redis supports a large set of commands, for example scan:
Return set is an array containing either nested arrays, objects or scalar values depending on the command:
Notes
Also see https://www.youtube.com/watch?v=YUjlBuI8xsU
Configuration
This feature significantly widens the database access given to users of a Prisma service. Therefore, it should be possible to configure the feature to limit access or completely disable it.
Disable completely
In the databases section of the PRISMA_CONFIG you can set the field
rawAccess
to false to disable raw database access. If the field is not specified it defaults to false.Fine-grained control
Any query run through the
executeRaw
mutation is executed with the privileges of the database user configured for the connector. This includes the ability to access a schema belonging to a different service in a multi-tenant prisma installation. We should explore how we can allow raw database access while limiting the scope to the same service.Prisma Client
The prisma client is implemented in several different languages. This describes the Typescript implementation and other languages will have a similar API.
API
To execute a raw query you need to specify what database to query, as well as the actual query. The following is the method definition for querying the default database:
For convenience, the default database can also be queried directly:
The method interface can differ for different types of databases. For example a Elastic Search database requires you to specify the collection as well as the query:
Example
returns
The text was updated successfully, but these errors were encountered: