Add new options for formatting to ScriptGeneratorOptions #103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brief
When writing SQL people have certain stylistic and formatting conventions they like to follow. This PR adds four new options to the
SqlScriptGeneratorOptions
to enable people to customise the formatting of the generated SQL further to their liking. These options have been added with defaults such that the existing behaviour is preserved. New behaviour can only be enabled by changing the option to something other than the default. Some of these options have been added due to stylistic preferences but others greatly enhance readability.Added Options
NewLineFormattedIndexDefinition
Description
This option affects the formatting of index definitions. By default the option is false and they are formatted as current. With the option enabled there will be newlines inserted between UNIQUE, INCLUDE and WHERE along with an indent to clearly show it belongs to a certain index.
Motivation
With the current way indexes are generated, any index with some complexity can end up quite unreadable with it trailing far off the line.
This option combats this, while it doesn't change the way predicate logic is formatted, by separating the components of the index into their own lines we can more easily see the distinction and the line will not trail as far.
NewlineFormattedCheckConstraint
Description
This option affects the formatting of check constraints. By default the option is false and they are formatted as current. When the option is true the CHECK part of a check constraint definition will be on its own line.
Motivation
With the way predicate expressions are generated, check constraints can end up having very long lines.
By having the CHECK part of a check constraint on its own line we can combat this.
SpaceBetweenDataTypeAndParameters
Description
This option affects the formatting of datatypes, currently the script generator generates a space between the datatype and the brackets containing the parameters (if any). The default value of this option preserves this behavior but when the option is false a space will not be generated.
Motivation
This option has simply been added for stylistic preference reasons, some people prefer having a space there and others don't. This option gives them the flexibility to choose.
SpaceBetweenParametersInDataType
Description
This option affects the formatting of parameters in data types. By default the script generator generates a comma separated lists with spaces. This is preserved in the default value of this new option. However if the option is set to false we get a comma separated list without spaces.
Motivation
This option has simply been added for stylistic preference reasons, some people prefer the parameters separated with a space and others don't. This option gives them the flexibility to choose.