GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - cascax/sql2gorm: parse SQL to gorm struct

BranchesTags
Open more actions menu

Latest commit

 

History

21 Commits
21 Commits

Folders and files

NameName
Last commit message
Last commit date
parser
parser
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
main.go
main.go
 
 

Repository files navigation

sql2gorm

sql2gorm is a command line tool to generate Go code with Gorm Tag and Json Tag from SQL.

Web tool: https://sql2gorm.mccode.info/

Download

go get -u github.com/cascax/sql2gorm/...

Usage (Command Line)

get struct from a sql file and write struct to the file

sql2gorm -f file.sql -o model.go

get struct from mysql

sql2gorm -db-dsn=root:123456@/msir -db-table=fund_info

get struct from arguments

sql2gorm -sql="CREATE TABLE person_info (
  age INT(11) unsigned NULL,
  id BIGINT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT '这是id',
  name VARCHAR(30) NOT NULL DEFAULT 'default_name' COMMENT '这是名字',
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  sex VARCHAR(2) NULL,
  num INT(11) DEFAULT 3 NULL,
  comment TEXT
  ) COMMENT='person info';"

Library usage

import "github.com/cascax/sql2gorm/parser"

sql := `CREATE TABLE t_person_info (
  id BIGINT(11) PRIMARY KEY AUTO_INCREMENT NOT NULL COMMENT 'primary id',
  name VARCHAR(30) NOT NULL DEFAULT 'default_name',
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  age INT(11) unsigned NULL,
  sex VARCHAR(2) NULL
  );`
data, err := parser.ParseSql(sql, WithTablePrefix("t_"), WithJsonTag())

About

parse SQL to gorm struct

Topics

golanggorm

Resources

Readme
MIT license
Activity

Stars

140 stars

Watchers

2 watching

Forks

51 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.