Comments (9)
I guess you want something like the following:
mappings.pkl:
tables: Mapping<String, DbTable>
typealias DbTable = Mapping<String, DbMapping>
class DbMapping {
gp_table: String
gp_field: String
bc_table: String
bc_field: String
}
amends "mappings.pkl"
tables {
["salesInvoices"] {
["documentNo_to_invoiceNumber"] {
gp_table = "RM20101"
gp_field = "DOCNUMBR"
bc_table = "salesInvoices"
bc_field = "externalDocumentNumber"
}
}
}
PS: This is a better fit for "Discussions" than "Issues".
from pkl.
The type alias only improves readability and reusability.
Otherwise it's the same as tables: Mapping<String, Mapping<String, DbMapping>>
.
A Pkl Mapping
is often called "map" or "dictionary" in other programming languages.
from pkl.
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.
from pkl.
I'm not too sure what
table String {
mapping String {
gp_table: String
gp_field: String
bc_table: String
bc_field: String
}
}
means. If you know the field names ahead of time, you don't want a Mapping
, but rather a class
that defines properties. Only when you don't know the names ahead of time do you tend to use a Mapping
.
Be weary that import "mappings.pkl"
doesn't actually do anything (you don't use mappings
anywhere); at the moment, Pkl only checks that salesInvoices.documentNo_to_invoiceNumber
is indeed a Mapping
, but nothing else.
from pkl.
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: annotated types can't be applied to non-local objects
or something along those lines.
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:
class Mapping{
gp_table: String
gp_field: String
bc_table: String
bc_field: String
}
Where each gp_table, gp_field, etc, variables will have varying values attributing to them.
from pkl.
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 mapping
instantiate a many-to-one relationship? The only thing I don't really get is the distinction between using the variable name such as tables
and the keyword typealias
, but I guess this is due to the fact that there is only a single tables
object and many DbTable
s.
Also, I wasn't even aware of the "Discussions" section, so thanks again. First time I've made a forum post on GitHub.
from pkl.
There is also a Map type in Pkl with an richer API 🤓
from pkl.
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 typealias
es:
tables: Mapping<String, DbTable>
typealias DbTable = Mapping<String, DbMapping>
/// The database can't take arbitrary strings as names, so names must be restricted.
typealias DbName = String(!contains(" "))
class DbMapping {
gp_table: DbName
gp_field: DbName
bc_table: DbName
bc_field: DbName
}
from pkl.
So to clarify, the reason I originally posted this here was because of the following error:
–– Pkl Error ––
A non-local object property cannot have a type annotation.
At which point I didn't know a workaround exists.
Thanks for the help.
from pkl.
Related Issues (20)
- Bug: fatal error when chart location is invalid HOT 7
- Automatic formatting of Pkl files HOT 1
- Stack overflow when parameter name is same as object property name HOT 2
- Type constraints on `typealias`es are evaluated eagerly HOT 3
- Question: Submit to CNCF HOT 3
- `gw buildNative` runs aarch64 tasks on amd64 HOT 1
- Allow overriding Java/Kotlin package name in codegen
- Rendering lists in XML may produce unexpected results HOT 1
- Type constraints are sometimes not enforced. HOT 2
- Unable to create test for non-empty constraint on listing HOT 2
- Add SLSA provenance to your releases
- Disable "Allow merge commits" and "Allow rebase merging" in GitHub UI HOT 3
- Non-constant globbed reads return wrong results
- Reads with same glob pattern return same result even if located in different modules/directories
- better source listing for IntelliJ to include line numbers? HOT 2
- Provide an ability to depend on a local project module from a non-project module
- Feature Request: Add `hcl` format
- [Feature Request] Type parameters for Classes
- Unexpected caching with pkl-go and Evaluator.EvaluateOutputText HOT 1
- Output path placeholders don't expose `ValueRenderer.extension`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pkl.