-
Notifications
You must be signed in to change notification settings - Fork 115
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
Extract CREATE statements from a table #37
Comments
This would be very useful. It requires some thought. When we create a table we have to tell the DBMS what types the columns have. This means we need a mapping from (type level) PGTypes to value level encodings of these. The latter don't exist yet, but I'll try to think of the most judicious way to add them. |
One option, how to do this would be to use something similar to the
the mapping from the type level to the pg types should be pretty straightforward if we don't want to have the option of specifying the range of the pg type, if we are ok with one pg type per type on haskell type level. Or do you have something that is more elegant in mind? |
I think I would prefer to have all the data you need to create the table already stored in the
to change to
for some new class Your suggestion doesn't require a breaking change, however, since it only introduces new names. |
So you mean, that the table properties would get one more field:
and the information, how to create a row in a Also, the user should be able to specify other attributes, that can't be taken from the type system like |
That's right.
Yes, and probably most importantly, keys and foreign keys. However, it seems a bit awkward to do these. |
How would that look like? I'm imagining, that the referencing of foreign key could work like |
I think it would look something like (taking liberties a bit with the types -- this is not the full specification of
For example
The problem is that we have to make sure those functions can only project, not do any operations, so they can't actually work on |
Regarding the foreign keys, what about this signature:
where the
With regards to the column specification, what about having this:
The
I did a basic implementation of this and it typechecks, so I'd like to hear from you if it's a way worth going or not. |
This is a good start. I think it won't work because a user can apply operators to the
which is invalid. I think what we actually need is to create tables like
Then I think your |
At which point can the user change the
This is the same as if the user would call the Anyway I also feel that it's good idea to have some |
I don't understand your point about |
I meant that it we consider the situation I explained a bad thing, that the user can somehow create a new table from an existing definition and then using it in This is the only point I can see where the changing of columns in |
Ah but it's not a bad thing to alter the columns of a |
So can you, please, point out, where the application of the operator before running the |
Yeah, suppose I've got
What happens when I try to run
|
So if the type held under
It will just extract the name of the column and wrap it into For the extracting the information about the columns from the table, there needs to be something similar to
where That way, the user should be indeed from |
Yes, I think your summary is correct. It is indeed a breaking change so I am a bit wary. |
Maybe we can have these two variants together, There would be needed these two instances for querying the table:
|
Wouldn't that mean users would have to define their tables twice? |
No, there would exist the old variant, that just supports querying for not breaking existing user code and the new variant would support both, querying and extracting schemas. Only users who have existing |
Sure, we can do that. Actually my biggest concern is with type inference. The type of
and suddenly users might have to start using type annotations. That's not a good situation to be in, but I don't see a way around it. |
Or, if we keep the |
At some point you have to convert |
I mean the type inference for users querying |
So do you think it's worth it even though the inference would suffer? If yes then I'd like to implement it. |
I think an implementation would be worthwhile anyway just so we can play around with it, but it's not something I will merge lightly. It needs a lot of thinking about and discussion with other users. |
OK I'll try to create some draft. |
In order to be able to only project columns from Table, it's read type must not have any available functions that can modify it like Column does.
In order to be able to only project columns from Table, it's read type must not have any available functions that can modify it like Column does.
Should be pretty easy to generate a default CREATE statement.
The text was updated successfully, but these errors were encountered: