Open safaci2000 opened 1 week ago
I guess we could add _
after each table column named TableName
, SchemaName
or Alias
.
In the meantime, workaround would be to customize generator.
I think the point I was getting at is that I think it should fail and detect a failure rather than generate code that doesn't compile. You could potentially run into the same issue with table_ or such. Maintain a reserve words that are part of your model if they're not overriden via the custom config.
I think the point I was getting at is that I think it should fail and detect a failure rather than generate code that doesn't compile.
The only way the generator can detect build failure is to initiate go build. I think that would be too much responsibility for a generator. Also, it would probably trigger every anti-virus software out there.
You could potentially run into the same issue with table_ or such.
True, but there is always an option to customize the generator.
Maintain a reserve words that are part of your model if they're not overriden via the custom config.
Since the default generator always generates columns in PascalCase
, the only possible conflict names are Table
, TableName
, SchemaName
, Alias
, AllColumns
, and MutableColumns
. If we handle these cases, the only way for users to get more conflicts is by customizing the generator.
Okay, maybe we should add a note in the wiki to call that out? So, detecting a build failure is likely overkill, what I was getting at is ensuring those values are not used.
Since we have a finite set of reserved words, can't the generator fail if it finds a column name titled one of those values you listed above?
It does add a check to check on every field but it's a better user experience than trying out jet after never hearing about it and having it blow up and moving on since it's obviously 'broken'.
Since we have a finite set of reserved words, can't the generator fail if it finds a column name titled one of those values you listed above?
It doesn't have to fail. If generator encounters any of above listed values, generator can add any character and thus break the name conflict. For instance if we add _
:
type auditActions struct {
postgres.Table
// Columns
TableName_ postgres.ColumnString
}
Ah, so dynamic renaming naming... yeah that'd be much better. 👍
Describe the bug The code generator should fail if datamodel contains reserved fields.
There is a collision with the way the code is constructed, because postgres.Table exposes TalbeName() and the table contains a field named TableName the code does not compile.
Environment (please complete the following information):
Code snippet
Expected behavior Generated code to compile successfully or fail hard on the generation and provide context on the reason for the failure