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

Support database views in diesel print-schema #1482

Closed
lukesutton opened this Issue Jan 16, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@lukesutton

lukesutton commented Jan 16, 2018

Problem Description

The diesel print-schema command doesn't output definitions for database views in Postgresql.

What are you trying to accomplish?

For more complex queries I would like to be able to create a view in the database and associate it with a Queryable struct. This would be especially useful, since Postgresql now has support for materialized views.

What is the expected output?

I would expect the diesel cli to output macro calls for views. If not by default then as an option.

What is the actual output?

All tables, but no views.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 16, 2018

Unfortunately, we can't really do this until we more generally separate "data sources" from "tables". The problem is that all tables in Diesel must have a primary key, and there's no way that we could infer that. Humans can just pick a random arbitrary column and call that the primary key (and many views actually do logically have one), but I don't want to do that in Diesel CLI

@sgrif sgrif closed this Jan 16, 2018

@lukesutton

This comment has been minimized.

lukesutton commented Jan 16, 2018

Totally fair! I imagined there was some constraint there. My approach at this point has been to synthesize a primary key for rows in views and manually add table! declarations for them, which is working pretty well.

@sgrif

This comment has been minimized.

Member

sgrif commented Jan 16, 2018

Yup, that's the work around. For the record, I closed this issue, because that specific feature is not something we can support. That said, I do want to support views in general, as a separate concept from table!/Table (basically just not having a primary key), and when we do that they will absolutely be inferred by diesel print-schema and infer_schema!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment