xxjwxc / Gormt
Licence: mit
database to golang struct
Stars: ✭ 1,063
Projects that are alternatives of or similar to Gormt
Gnorm
A database-first code generator for any language
Stars: ✭ 415 (-60.96%)
Mutual labels: orm, database, mysql
Hunt Entity
An object-relational mapping (ORM) framework for D language (Similar to JPA / Doctrine), support PostgreSQL and MySQL.
Stars: ✭ 51 (-95.2%)
Mutual labels: orm, database, mysql
Jooq
jOOQ is the best way to write SQL in Java
Stars: ✭ 4,695 (+341.67%)
Mutual labels: orm, database, mysql
Rel
💎 Modern Database Access Layer for Golang - Testable, Extendable and Crafted Into a Clean and Elegant API
Stars: ✭ 317 (-70.18%)
Mutual labels: orm, database, mysql
Typeorm
ORM for TypeScript and JavaScript (ES7, ES6, ES5). Supports MySQL, PostgreSQL, MariaDB, SQLite, MS SQL Server, Oracle, SAP Hana, WebSQL databases. Works in NodeJS, Browser, Ionic, Cordova and Electron platforms.
Stars: ✭ 26,559 (+2398.49%)
Mutual labels: orm, database, mysql
Crecto
Database wrapper and ORM for Crystal, inspired by Ecto
Stars: ✭ 325 (-69.43%)
Mutual labels: orm, database, mysql
Maghead
The fastest pure PHP database framework with a powerful static code generator, supports horizontal scale up, designed for PHP7
Stars: ✭ 483 (-54.56%)
Mutual labels: orm, database, mysql
Wetland
A Node.js ORM, mapping-based. Works with MySQL, PostgreSQL, SQLite and more.
Stars: ✭ 261 (-75.45%)
Mutual labels: orm, database, mysql
Go Sqlbuilder
A flexible and powerful SQL string builder library plus a zero-config ORM.
Stars: ✭ 539 (-49.29%)
Mutual labels: orm, database, mysql
Architect
A set of tools which enhances ORMs written in Python with more features
Stars: ✭ 320 (-69.9%)
Mutual labels: orm, database, mysql
Goloquent
This repo no longer under maintenance, please go to https://github.com/si3nloong/sqlike
Stars: ✭ 16 (-98.49%)
Mutual labels: orm, database, mysql
Sqlboiler
Generate a Go ORM tailored to your database schema.
Stars: ✭ 4,497 (+323.05%)
Mutual labels: orm, database, mysql
Sequelizer
A GUI Desktop App for export sequelize models from database automatically.
Stars: ✭ 273 (-74.32%)
Mutual labels: orm, database, mysql
Granite
ORM Model with Adapters for mysql, pg, sqlite in the Crystal Language.
Stars: ✭ 238 (-77.61%)
Mutual labels: orm, database, mysql
Mikro Orm
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.
Stars: ✭ 3,874 (+264.44%)
Mutual labels: orm, database, mysql
Denodb
MySQL, SQLite, MariaDB, PostgreSQL and MongoDB ORM for Deno
Stars: ✭ 498 (-53.15%)
Mutual labels: orm, database, mysql
Bookshelf
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js
Stars: ✭ 6,252 (+488.15%)
Mutual labels: orm, database, mysql
中文文档
gorm(v1/v2),You can automatically generate golang sturct from mysql database. big Camel-Case Name Rule, JSON tag.
mysql database to golang struct conversion tools base ongui support
./gormt -g=true
cmd support
./gormt -g=false
install
go get -u -v github.com/xxjwxc/[email protected]
or: Dowloading
1. Configure default configuration items through the current directory config.yml file
note: for latest version of config format, please check /data/config/MyIni.go
out_dir : "./model" # out dir
url_tag : json # web url tag(json,db(https://github.com/google/go-querystring))
language : # language(English,中 文)
db_tag : gorm # DB tag(gorm,db)
simple : false #simple output
is_out_sql : false # Whether to output sql
is_out_func : true # Whether to output function
is_foreign_key : true # Whether to mark foreign key or not
is_gui : false # Whether to operate on gui
is_table_name : false # Whether to out GetTableName/column function
is_null_to_point : false # database is 'DEFAULT NULL' then set element type as point
is_web_tag: false
is_web_tag_pk_hidden: false
table_prefix: "" #table prefix
db_info :
host : "127.0.0.1"
port : 3306
username : "root"
password : "qwer"
database : "oauth_db"
type: 0 # database type (0:mysql , 1:sqlite , 2:mssql)
2. get help
./gormt --help
or
./gormt -h
-------------------------------------------------------
base on gorm tools for mysql database to golang struct
Usage:
main [flags]
Flags:
-d, --database string 数据库名
-f, --foreign 是否导出外键关联
-F, --fun 是否导出函数
-g, --gui 是否ui显示模式
-h, --help help for main
-H, --host string 数据库地址.(注意-H为大写)
-o, --outdir string 输出目录
-p, --password string 密码.
--port int 端口号 (default 3306)
-s, --singular 是否禁用表名复数
-l, --url string url标签(json,url)
-u, --user string 用户名.
3. Can be updated configuration items using command line tools
./gormt -H=127.0.0.1 -d=oauth_db -p=qwer -u=root --port=3306 -F=true
4. Support for gorm attributes
- Database tables, column field annotation support
- json tag json tag output
- gorm.Model Support export gorm.model>>>
- PRIMARY_KEY Specifies column as primary key
- UNIQUE Specifies column as unique
- NOT NULL Specifies column as NOT NULL
- INDEX Create index with or without name, same name creates composite indexes
- UNIQUE_INDEX Like INDEX, create unique index
- Support foreign key related properties Support export gorm.model>>>
- Support function export (foreign key, association, index , unique and more)Support export function >>>
def
You can enrich data types in5. Demonstration
- sql:
CREATE TABLE `user_account_tbl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`account` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`password` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`account_type` int(11) NOT NULL DEFAULT '0' COMMENT '帐号类型:0手机号,1邮件',
`app_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT 'authbucket_oauth2_client表的id',
`user_info_tbl_id` int(11) NOT NULL,
`reg_time` datetime DEFAULT NULL,
`reg_ip` varchar(15) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`bundle_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
`describ` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE KEY `account` (`account`) USING BTREE,
KEY `user_info_id` (`user_info_tbl_id`) USING BTREE,
CONSTRAINT `user_account_tbl_ibfk_1` FOREIGN KEY (`user_info_tbl_id`) REFERENCES `user_info_tbl` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='用户账号'
--->Derived results
// UserAccountTbl 用户账号
type UserAccountTbl struct {
ID int `gorm:"primary_key"`
Account string `gorm:"unique"`
Password string
AccountType int // 帐号类型:0手机号,1邮件
AppKey string // authbucket_oauth2_client表的id
UserInfoTblID int `gorm:"index"`
UserInfoTbl UserInfoTbl `gorm:"association_foreignkey:user_info_tbl_id;foreignkey:id"` // 用户信息
RegTime time.Time
RegIP string
BundleID string
Describ string
}
more>>>
6. support func export
The exported function is only the auxiliary class function of Gorm, and calls Gorm completely
// FetchByPrimaryKey primay or index 获取唯一内容
func (obj *_UserAccountTblMgr) FetchByPrimaryKey(ID int) (result UserAccountTbl, err error) {
err = obj.DB.Table(obj.GetTableName()).Where("id = ?", ID).Find(&result).Error
if err == nil && obj.isRelated {
{
var info UserInfoTbl // 用户信息
err = obj.DB.Table("user_info_tbl").Where("id = ?", result.UserInfoTblID).Find(&info).Error
if err != nil {
return
}
result.UserInfoTbl = info
}
}
return
}
more>>>
how to use call style>>>
7. build
make windows
make linux
make mac
or
go generate
8 note : in windows not support utf-8 style . ASCALL model
- Switch encoding mode
CHCP 65001
column notes default
- Add a comment to the column starting with
[@gorm default:'test']
- example
[@gorm default:'test';->;<-:create]this is my notes
Indicates that the default value is 'test',can read/creat/write - Use of foreign key notes
[@fk tableName.columnName]this is my notes
Represents the 'columnName' column associated with the 'tableName'
9. one windows gui tools
Stargazers over time
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].