Repository navigation
Replies: 2 comments 2 replies
|
Hey @aldychris Your approach seems sensible and easy to understand, but there may be a more flexible method that considers complexity and edge cases. Rather than defining the database structure and connections in yaml, we could define the data transfer objects (DTOs) and write the SQL query manually. This approach aims to handle advanced cases that may be challenging with the yaml definition, such as creating aggregated columns or implementing complex data filters. The proposed approach emphasizes on defining the API perspective and gives the user more control over the SQL query while still leveraging the code generation benefits, serialization, and more from the client library. Let's revise your example with the new approach: class: SampleView
view: sample_view
query: |
CREATE OR REPLACE VIEW "sample_view" AS
SELECT t1."description" AS "description", t2."role" AS "userRoleWhoCreated", t2."name" AS "createdBy", t3."name" AS "modifiedBy"
FROM child_data t1
JOIN parent_data t2 ON "t1"."createdBy" = t2.id
JOIN parent_data t3 ON "t1"."modifiedBy" = t3.id;
fields:
description: String
userRoleWhoCreated: String?
createdBy: String
modifiedBy: StringIn the above yaml file, we have the class and table definitions just like before. The key difference is the query field, which includes the SQL query. You define your fields as per your DTOs and the SQL query makes it clear how the data will be fetched. This does mean the user has to understand SQL and the underlying structure, but considering this is an advanced feature I think that is okay. Furthermore, the query can be included in the database migration feature, promoting ease of use and adaptability. This way, we avoid the risk of recreating SQL in a new syntax via yaml, while ensuring we can handle a variety of use cases efficiently. Some other considerations, I think it might be smartest to have the user define the id field manually for these classes (if they want one). ViewTables are read-only in PostgreSQL, the easiest solution would be to have them read-only in the code generator too. I.E. no We are not getting guaranteed type-checking since there is an arbitrary user-created query. But it should be possible to inspect the table and compare it with the object we want to create at startup (perhaps debug only) and give the user a warning if there is any type mismatch. |
|
Hi @Isakdl |
Uh oh!
There was an error while loading. Please reload this page.
Im planning to make view table from yaml file. supposedly I have this table
parent_data.yaml
child_data.yaml
Based on those 2 tables I want to have View table to show name who created and modified the description, so the view yaml will looks like this
The output of this will be
I think the basic knowledge of how create View still needed here, but is the yaml structure is easy to understand or any suggestion and input?
All reactions