liudanking / Gorm2sql
auto generate sql from gorm model struct
Stars: ✭ 92
Programming Languages
go
31211 projects - #10 most used programming language
Projects that are alternatives of or similar to Gorm2sql
Reiner
萊納 - A MySQL wrapper which might be better than the ORMs and written in Golang
Stars: ✭ 19 (-79.35%)
Mutual labels: sql, gorm
Gitbase
SQL interface to git repositories, written in Go. https://docs.sourced.tech/gitbase
Stars: ✭ 1,955 (+2025%)
Mutual labels: ast, sql
Goql
A golang source code scanner, this time in sql :)
Stars: ✭ 295 (+220.65%)
Mutual labels: ast, sql
Jsqlparser
JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
Stars: ✭ 3,405 (+3601.09%)
Mutual labels: ast, sql
Flora Sql Parser
Parse SQL (select) statements into abstract syntax tree (AST) and convert ASTs back to SQL.
Stars: ✭ 186 (+102.17%)
Mutual labels: ast, sql
Qone
Next-generation web query language, extend .NET LINQ for javascript.
Stars: ✭ 463 (+403.26%)
Mutual labels: ast, sql
Uaiso
A multi-language parsing infrastructure with an unified AST
Stars: ✭ 86 (-6.52%)
Mutual labels: ast
Docker Superset
Repository for Docker Image of Apache-Superset. [Docker Image: https://hub.docker.com/r/abhioncbr/docker-superset]
Stars: ✭ 86 (-6.52%)
Mutual labels: sql
Cloudquery
cloudquery transforms your cloud infrastructure into SQL or Graph database for easy monitoring, governance and security.
Stars: ✭ 1,300 (+1313.04%)
Mutual labels: sql
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1277.17%)
Mutual labels: sql
Jplusone
Tool for automatic detection and asserting "N+1 SELECT problem" occurences in JPA based Spring Boot Java applications and finding origin of JPA issued SQL statements in general
Stars: ✭ 91 (-1.09%)
Mutual labels: sql
Training Material
A collection of code examples as well as presentations for training purposes
Stars: ✭ 85 (-7.61%)
Mutual labels: sql
Jsql
jSQL is the "official" Javascript Query Language - A database written in Javascript for use in a browser or Node.
Stars: ✭ 85 (-7.61%)
Mutual labels: sql
gorm2sql: auto generate sql from gorm model struct
A Swiss Army Knife helps you generate sql from gorm model struct.
Installation
go get github.com/liudanking/gorm2sql
Usage
user_email.go
:
type UserBase struct {
UserId string `sql:"index:idx_ub"`
Ip string `sql:"unique_index:uniq_ip"`
}
type UserEmail struct {
Id int64 `gorm:"primary_key"`
UserBase
Email string
Sex bool
Age int
Score float64
UpdateTime time.Time `sql:"default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"`
CreateTime time.Time `sql:"default:CURRENT_TIMESTAMP"`
}
gorm2sql sql -f user_email.go -s UserEmail -o db.sql
Result:
CREATE TABLE `user_email`
(
`id` bigint AUTO_INCREMENT NOT NULL ,
`user_id` varchar(128) NOT NULL ,
`ip` varchar(128) NOT NULL ,
`email` varchar(128) NOT NULL ,
`sex` boolean NOT NULL ,
`age` int NOT NULL ,
`score` double NOT NULL ,
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_ub (`user_id`),
UNIQUE INDEX uniq_ip (`ip`),
PRIMARY KEY (`id`)
) engine=innodb DEFAULT charset=utf8mb4;
How it works
gorm2sql
loads go source file to golang AST, then generate sql according to tag
of gorm struct field.
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].