-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Column type in view is unknown #481
Comments
To be clear, here is what I think is the correct output for the view
|
Version information:
|
Hm, that's a bug for sure, but it's not clear to me where it resides :-) I will try to look into this but a temporary workaround for you is probably to create a custom hook that patches this particular view.. |
Let me know if this is fixed now! |
Thanks for looking into this! Is the fix in the latest version of
Output in
Please let me know if I'm doing something wrong or if there's any additional information I can provide that would help you investigate this problem. |
Hm ok, I was hoping it would be fixed in this version. I will try to see what else could be wrong. |
Does your table definition still look like the first message in this thread? |
Yes. |
That's so weird, I made an exact unit test for that case! Maybe something fails later in the chain.. |
In case it helps, I also get
And the generated typescript is:
Of course, this view can't easily be reproduced. But I thought it might help shed light in case there's a clue with these lateral joins. Versions:
|
Thank you. I'll investigate further when I have time :-) |
I found a very focused scenario to help isolate the problem. Basically, cross-schema Views has issues knowing the source column. @gerdemb 's example is actually going between two schemas. You can reproduce this easily. Create two views in two separate schemas. CREATE OR REPLACE VIEW public.kanel_testing AS
SELECT 1 as id; -- Change this to anything
CREATE OR REPLACE VIEW api.kanel_testing AS
SELECT * FROM public.kanel_testing; You get the following output:
/** Represents the view public.kanel_testing */
export default interface KanelTesting {
id: number;
}
/** Represents the view api.kanel_testing */
export default interface KanelTesting {
id: unknown;
} This scenario can easily come up in e.g. Supabase or other providers where it is recommended to have Views intended for API use in a separate schema from your core data schema. This limits exposure to data, and makes it clear what is exposed. So there are lots of these slim Views that simply mirror the underlying data source. If you can point me to the right area to assist (or workaround), I'd appreciate it (or of course if you immediately know where the problem is, that's probably faster haha). |
Ok, so what I found was a different problem 😅 I think the source of the problem is that |
Ah, that's a good point. I always use schemas for complete encapsulation, so I haven't had things referencing each other across that line. But it's obviously possible and I can see good use cases for it, so Kanel should support it as well. |
I believe I am experiencing this issue (postgrest instead of supabase)...
I just started using this library today, so I am not too familiar with the codebase, but it seems like this would be the area in which to incorporate a solution? kanel/packages/kanel/src/generators/resolveType.ts Lines 163 to 209 in 47ade7c
The funny thing is, it looks like the zod schemas via generateZodSchemas are the correct column types, so I figure the property metadata must be right somewhere. I am thinking of just writing a script to strip out the types and wrapping the schema with Yes this fixed it for me... I imagine this would break some other things but I don't see a testing script in package.json to check. If not though let me know you want the pull request and I can submit it. Thank you for the great tool! Saving time is the best. |
Just updated the patch-1 mentioned above to be more pull-worthy. Let me know if you would like me to create the PR as that unblocked me. Before that change I was seeing "unknown" for pretty much everything (schemas build for postgrest). Deferring the PR since I do not know what "source" might be used for later down the chain... I am assuming that deleting it might be problematic for other people, but I am not someone who should determine that. Also added #559 and associated PR #558 to address a separate but related issue with the @kristiandupont - Received your message on the PR. I am using a local branch, so no rush here. Thank you for the ack! |
Kanel is not identifying the column type for one of my views. The view:
And the output from Kanel for the view:
Notice that all the column types are
unknown
.amount
is a composite type that I have defined.It is working correctly in other views. For example with this view:
Kanel correctly generates this schema:
Notice how the
balance
column has the correct typeAmount[]
. This is my.kanel.cjs
config file:I have tried setting
resolveViews
to bothfalse
andtrue
as well as removing themakeKyselyHook()
but the results are the same. I'm not sure what is different about this viewaccount_posting_hierarchy
that Kanel connect identify the column types. Perhaps it's because of theWITH RECURSIVE
orUNION ALL
. It is my only view that is using those statements.The text was updated successfully, but these errors were encountered: