({
take: [
{ key: "sql", label: "SQL", type: "code", value: "select * from table" },
{
key: "language",
label: "Language",
type: "dropdown",
options: [
"sql",
"bigquery",
"db2",
"hive",
"mariadb",
"mysql",
"n1ql",
"plsql",
"postgresql",
"redshift",
"snowflake",
"sqlite",
"spark",
"tsql",
"trino",
],
},
{ key: "tabWidth", label: "Tab size", type: "dropdown", options: [2, 4] },
{ key: "useTabs", label: "Use tabs", type: "toggle", value: false },
{
key: "denseOperators",
label: "Dense Operators",
type: "toggle",
value: false,
},
{
key: "newlineBeforeSemicolon",
label: "Semicolon on new line",
type: "toggle",
value: false,
},
{
key: "logicalOperatorNewline",
label: "Logical operators position",
type: "dropdown",
options: [
{ label: "After", value: "after" },
{ label: "Before", value: "before" },
],
},
{
key: "keywordCase",
label: "Keyword case",
type: "dropdown",
options: [
{ label: "Preserve", value: "preserve" },
{ label: "Uppercase", value: "upper" },
{ label: "Lowercase", value: "lower" },
],
},
{
key: "indentStyle",
label: "Indentation style",
type: "dropdown",
options: [
{ label: "Standard", value: "standard" },
{ label: "Tabular Left", value: "tabularLeft" },
{ label: "Tabular Right", value: "tabularRight" },
],
},
{
key: "expressionWidth",
label: "Line width",
detail: "Number of characters in expressions before a new line is added",
type: "number",
value: 50,
},
{
type: "import",
value:
"https://cdnjs.cloudflare.com/ajax/libs/sql-formatter/12.0.5/sql-formatter.min.js",
},
],
make: ({ sql, ...options }) => {
try {
return {
type: "code",
label: "Result",
value: sqlFormatter.format(sql, options),
}
} catch (err) {
return { type: "code", value: err.message, label: "Error" }
}
},
})