-
Notifications
You must be signed in to change notification settings - Fork 863
Passive Postgres Connector #1749
Comments
How about stored procedures? |
@msand Great point. Could you write up a few examples for stored procedures and how you want to expose them through GraphQL? |
@sorenbs PostGraphile has great support for them: https://www.graphile.org/postgraphile/procedures/
At least in PostgreSQL they are really quite powerful, supporting these languages in the base distribution: SQL, PL/pgSQL, PL/Tcl, PL/Perl, and PL/Python. And these externally maintained ones: So, essentially they can be used for almost any and all back-end work. This can simplify: Not to mention how the query planner tends to do very well when it can pre-compile and combine procedures, it also decreases network traffic, and places more of the computation right next to the data (less context switching and communication, more intelligent optimization when combining procedures, etc). Of course, it's no silver bullet, and won't always be faster or the right tool for the job. Edit: This probably belongs here: https://github.com/graphcool/prisma/issues/1641 |
Just realized this was the mysql issue, but mostly the same should apply with regards to use cases. |
Just a few words to comment the differences with our approach. Passive SQL connectors are similar to what we do at NileDB (https://github.com/NileDB/com.niledb.core), but we follow a simpler approach because we support PostgreSQL only. So, our model is based 100% on PostgreSQL capabilities (tables, views, fields, references, data types, schemas, ...). Are you going to have a different PassiveSQL connector models for each supported database engine or are you trying to use the same model for all supported database engines? The problem I see with having only one model for every supported database engine is that existing databases may be using specifics of each database engine (i.e. tables in different schemas, specific data-types like tsvector, ...., materialized views, gist indexes, ...) and it is very difficult to support different databases in the same model [meta-model] (common denominator problem). IMHO. Our approach is different from the beginning. Although we don't support other databases directly (PostgreSQL only), we can get data from different sources using PostgreSQL's FDW (Foreign Data Wrappers) [https://wiki.postgresql.org/wiki/Foreign_data_wrappers]. You can integrate data from different sources at the same time (i.e. integrate data from MySQL, SQL Server, a flat file, ... in the same GraphQL query). With this approach, we can provide a GraphQL API on top of almost anything (including flat files, any database, ...). The same occurs with aggregations, stored procedures, ..., we don't support them, but it is very easy for us to create a PostgreSQL VIEW on top of a query that uses aggregation functions and expose the VIEW through GraphQL. We are developing NileDB to use it in our own business use cases. We needed to provide GraphQL API on top of existing complex databases (with tables in different schemas, ...). We evaluated Postgraphile, but its query capabilities, .., where not enough, so we decided to implement our own Graphql layer in Java. |
Prisma currently supports existing Postgres databases. As part of the upcoming changes to the datamodel, we will introduce support for existing MySQL databases: prisma/prisma#3408 The new MongoDB connector already works with existing databases: prisma/prisma#1643 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 10 days if no further activity occurs. Thank you for your contributions. |
Passive Sql Connector
Prisma supports two kinds of database connectors:
This is a living document outlining all considerations for a passive SQL connector. This is not a final spec - please contribute by commenting below.
Configuration points
Fundamental mapping
Extra
Example SDL
Relation Mapping
Below are given examples for all possible relation configurations. We can likely support a more concise syntax
one-one
one relation column
two relation columns
relation table
one-many
one relation column
relation table
many-many
relation table
Special consideration: join-table with extra columns
A join table can have extra columns that should be accessible in the API. This is especially critical if the columns are required and mutations should be supported.
This can be supported by modelling the join table as a normal table with two one-relations with a single relation column. In the future we can add direct support for extra fields on relations in query and mutation API.
Data Types
See #1753
Questions
Int
Float
Decimal
Boolean
String
DateTime
SDL Generation
The passive connector requires an SDL file that describes the layout of the database schema. If the database schema follows common conventions we can automatically generate this SDL file. If the database schema deviates from common conventions we can generate a partial SDL file that the developer can use as a starting point.
The text was updated successfully, but these errors were encountered: