microsoft / azuredatastudio

Azure Data Studio is a data management and development tool with connectivity to popular cloud and on-premises databases. Azure Data Studio supports Windows, macOS, and Linux, with immediate capability to connect to Azure SQL and SQL Server. Browse the extension library for more database support options including MySQL, PostgreSQL, and MongoDB.
https://learn.microsoft.com/sql/azure-data-studio
MIT License
7.56k stars 898 forks source link

Better formatting for generated T-SQL from Open API spec #17234

Closed zijchen closed 2 years ago

zijchen commented 3 years ago

Current formatting when generating sqlproj from Open API spec:

CREATE TABLE [SwaggerPetstore.Models].[NewPet](
    [Id] [int] NOT NULL,
    [Name] [nvarchar](4000) NOT NULL,
    [Tag] [nvarchar](4000) NULL,
 CONSTRAINT [PK_NewPet] PRIMARY KEY CLUSTERED 
(
    [Id]
)
)
zijchen commented 3 years ago

Same table from extract:

CREATE TABLE [SwaggerPetstore.Models].[NewPet] (
    [Id]   INT             NOT NULL,
    [Name] NVARCHAR (4000) NOT NULL,
    [Tag]  NVARCHAR (4000) NULL,
    CONSTRAINT [PK_NewPet] PRIMARY KEY CLUSTERED ([Id] ASC)
);
Benjin commented 3 years ago

This is how SMO generates scripts

Options:

  1. SMO scripting options to prettify it
  2. scriptdom interpret -> generate
  3. vscode format document
Benjin commented 2 years ago

It turns out that there's no SMO option for formatting output nicely, so the option 1 is out. 2 would involve adding a call to Tools Service to pipe the capability down to ScriptDom... maybe not worth it. I think 3 is a fine balance, and has the added bonus of using the language server to determine correctness, which is the future.

@zijchen thoughts?

zijchen commented 2 years ago

Yeah I agree. Option 2 is overkill unless we find other uses for ScriptDom. 3 sounds best to me

udeeshagautam commented 2 years ago

Closing as by design (from SMO) for now.