All Projects → cascax → sql2gorm

cascax / sql2gorm

Licence: MIT license
parse SQL to gorm struct

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to sql2gorm

mysql
GORM mysql driver
Stars: ✭ 126 (+93.85%)
Mutual labels:  gorm
backend
A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL
Stars: ✭ 27 (-58.46%)
Mutual labels:  gorm
nested-set
Nested Set is an Go implementation of the Nested set model for Gorm.
Stars: ✭ 44 (-32.31%)
Mutual labels:  gorm
gorm-neo4j
GORM for Neo4j
Stars: ✭ 16 (-75.38%)
Mutual labels:  gorm
sqlext
extend gorm and gocql
Stars: ✭ 16 (-75.38%)
Mutual labels:  gorm
go-paginate
Cursor-based go paginator
Stars: ✭ 48 (-26.15%)
Mutual labels:  gorm
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (+95.38%)
Mutual labels:  gorm
go-ddd-api
API with domain driven design approach using golang, gorm, and mysql
Stars: ✭ 136 (+109.23%)
Mutual labels:  gorm
laya-template
服务基本框架,template
Stars: ✭ 13 (-80%)
Mutual labels:  gorm
clean-gin
Implementation of clean architecture in Go, Gin with dependency injection.
Stars: ✭ 181 (+178.46%)
Mutual labels:  gorm
iris-gorm-demo
iris+gorm+mysql的restful api项目起手式
Stars: ✭ 92 (+41.54%)
Mutual labels:  gorm
gothic
🦇 Gothic is a user registration and authentication SWT/JWT microservice. It supports REST, gRPC, and gRPC Web API, reCAPTCHA & a variety of DBs with Gorm.
Stars: ✭ 65 (+0%)
Mutual labels:  gorm
kuu
Modular Go Web Framework based on GORM and Gin.
Stars: ✭ 15 (-76.92%)
Mutual labels:  gorm
go-webapp-sample
golang, echo, gorm
Stars: ✭ 194 (+198.46%)
Mutual labels:  gorm
go-echo-server-sandbox
A scaffold of golang web server using labstack/echo
Stars: ✭ 12 (-81.54%)
Mutual labels:  gorm
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (+129.23%)
Mutual labels:  gorm
go-tenancy
快速实现 SaaS 多租户平台项目
Stars: ✭ 157 (+141.54%)
Mutual labels:  gorm
sqlserver
GORM sqlserver driver
Stars: ✭ 33 (-49.23%)
Mutual labels:  gorm
grails-audit-logging-plugin
The Grails Audit Logging Plugin
Stars: ✭ 49 (-24.62%)
Mutual labels:  gorm
ego
Go微服务.A simple and component-based microservice kit for go.
Stars: ✭ 765 (+1076.92%)
Mutual labels:  gorm

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())
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].