-
Notifications
You must be signed in to change notification settings - Fork 275
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
Nested Type Annotations #385
Comments
Even if there was a solution as the original poster said here, but with an undefined number of internal objects of the declared type, that would be wonderful. Not looking for an elegant solution. |
I'm not too sure what
means. If you know the field names ahead of time, you don't want a Be weary that |
Mapping in this case is not as per the Pkl definition, but rather a mapping between two databases. Hence the different tables and fields. The first code block was supposed to just illustrate the general form of the object I'm trying to create. Does the second code block not define a class with specific properties? And finally, the final code doesn't even run, it throws an error saying: All I'm trying to do is enforce a specific form on to the objects of type 'table', where any one table can have one or many objects contained within it of the form:
Where each gp_table, gp_field, etc, variables will have varying values attributing to them. |
I guess you want something like the following: mappings.pkl:
PS: This is a better fit for "Discussions" than "Issues". |
Thank you so much, this is excellent + exactly what I was looking for. I understand the code off the bat, but if you are willing to give a better explanation of your thought process, I'm all ears. Does Also, I wasn't even aware of the "Discussions" section, so thanks again. First time I've made a forum post on GitHub. |
The type alias only improves readability and reusability. |
There is also a Map type in Pkl with an richer API 🤓 |
Entirely with @translatenix's suggestions (both code and Discussion; but now that it's here, that's alright... do please close this Issue when you're fully satisfied, @yesteryearer). Since you're talking about database tables and fields, I bet there are restrictions on the names of those things. It depends entirely on which database you're using what those restrictions are, but just for the example, I'm assuming names may not contain whitespace. This is to demonstrate type constraints and to further illustrate @translatenix's point about
|
So to clarify, the reason I originally posted this here was because of the following error:
At which point I didn't know a workaround exists. Thanks for the help. |
Good day,
I'm pretty new to Pkl, and despite perusing the docs, can't find a working solution for the following:
I'm trying to generate a template for an object of the following form:
In the above scenario, any
table
instances, must be able to contain any number ofmappings
.The solution I designed got as far as, a
mapping.pkl
file:And an instance as follows:
The above only works when the mapping isn't contained within the larger
salesInvoices
object, and either way, I will only be able to have a single mapping in this manner.Is there a clever work around that I'm missing? Or rather, what is the best way to go about this? I saw the following, but in this instance I think the object only required a single instance of the nested object.
The text was updated successfully, but these errors were encountered: