/ddl-to-go-struct

Extension of vscode to convert DDL (sql) to structs of golang

Primary LanguageJavaScriptMIT LicenseMIT

DDL (sql) to Go Struct

This is a simple tool to convert the DDL instructions to a struct in Goland using the SQL package.

To use in my projects Copyright Arlei F. Farnetani Junior

The steps is simple.

First select the ddl create table instructions, example:

CREATE TABLE IF NOT EXISTS apps
(
    id uuid NOT NULL DEFAULT uuid_generate_v4 (),
    app_nome varchar(255) NOT NULL UNIQUE,
    app_icone varchar(255),
    app_ativa boolean NOT NULL DEFAULT true,
    created_at timestamp with time zone NOT NULL DEFAULT now(),
    updated_at timestamp with time zone NOT NULL DEFAULT now(),
    deleted_at timestamp with time zone,    
    CONSTRAINT apps_pkey PRIMARY KEY (id)
);

Then type CTRL+SHIFT+p

And run the DDLTOGS: Convert the DDL (SQL) instructions to Go Struct to convert the sql text selected to go struct

Or just select it and press CTRL+SHIFT+i

Will result in:

// apps --
	ID	uuid.UUID	`db:"id"`
	APPNome	string	`db:"app_nome"`
	APPIcone	string	`db:"app_icone"`
	APPAtiva	bool	`db:"app_ativa"`
	CreatedAT	*time.Time	`db:"created_at"`
	UpdatedAT	*time.Time	`db:"updated_at"`
	DeletedAT	*time.Time	`db:"deleted_at"`

Edition of Code

npm install -g vsce

cd /extension
vsce package

- The file will be generated: ddl-to-go-struct-0.0.3.vsix

- Right click on the file and install the vsix extension

Publish

vsce publish -p <token>

or access link direct and click in + New extension

https://marketplace.visualstudio.com/manage/publishers/farnetani

Creating a new extension

npm install -g yo generator-code

yo code

Version

V0.0.4

License

This project is a copy of the extension: DDLG2GS https://github.com/Wandecilenio/DDL2GS with customizations made by me to accept varchar and uuid fields for the my private use. I'm not responsible for any bugs/problems.

The refactoring of the project is under the MIT license. See the LICENSE file for more details. Please, in case of copying, do not forget to cite the source above that originated all (DDLG2GS).

Customized and Refactored with ❤️ by Arlei F. Farnetani Junior

Github Badge Instagram Badge Facebook Badge Gmail Badge Linkedin Badge