Custom data types
#594
|
I apply the formatter for our custom SQL-like language, and it does a good job. But in our dialect, we have a version data type with values like 3.14.5, and the latest versions of formatter throw an error: Is there any possibility of extending the formatter with additional data types? |
Answered by
nene
Apr 26, 2023
Replies: 1 comment 2 replies
|
You can define a custom dialect. See: https://github.com/sql-formatter-org/sql-formatter/blob/master/docs/dialect.md#custom-dialect-configuration-experimental There's no real way of defining a custom data-type per se, but you can make the formatter treat it as a string, by defining a regex to match it: tokenizerOptions: {
stringTypes: [
"''", // the string types of the SQL dialect you're extending
{ regex: "\d+.\d+.\d+" }, // regex to match version numbers
],
} |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm... yeah, it happens that the tokenizer tries to match NUMBER token before STRING, so it ends up matching
4.36as a NUMBER.But I think you can instead use
identTypes(to treat it as an identifier), which gets matched before number.