一个使 mysql,pgsql 数据库表自动生成 go struct 的工具

db2go

一个使 mysql、pgsql 数据库表自动生成 go struct 的工具

快速使用

将项目放入到GOPATH/src目录下,进入项目根目录下进行

$ go build

对于不同的操作系统

windows

$ db2go.exe -host=127.0.0.1 -port=5432 -user=postgres -pwd=postgres  -dbname=db_test -gorm=true -driver=pgsql

linux

$ ./db2go -host=127.0.0.1 -port=3306 -user=root -pwd=root -dbname=db_test -gorm=true -driver=mysql -package=hello

命令行提示

执行

$ ./db2go -help
Usage of db2go.exe:
  -dbname string
        必填,数据库名称,否则会报错
  -driver string
        必填,需要连接的数据库,现在只支持mysql、pgsql 例如 -driver=mysql,-driver=pgsql
  -gorm
        选填,是否添加 gorm tag,true添加,false不添加,默认不添加
  -host string
        选填,数据库ip,默认为localhost (default "localhost")
  -outdir string
        选填,go 文件输出路径,不设置的话会输出到当前程序所在路径 (default "./go_output")
  -package string
        选填,go 文件中 package 的名字,默认为 package main (default "main")
  -port int
        必填,数据库端口
  -pwd string
        必填,数据库密码
  -table string
        选填,需要导出的数据库表名称,如果不设置的话会将该数据库所有的表导出
  -user string
        必填,数据库用户名
Owner
易水韩
风萧萧兮易水寒
易水韩
Similar Resources

Golang MySql binary log replication listener

Go MySql binary log replication listener Pure Go Implementation of MySQL replication protocol. This allow you to receive event like insert, update, de

Oct 25, 2022

MySQL replication topology management and HA

MySQL replication topology management and HA

orchestrator [Documentation] orchestrator is a MySQL high availability and replication management tool, runs as a service and provides command line ac

Jan 4, 2023

Vitess is a database clustering system for horizontal scaling of MySQL.

Vitess Vitess is a database clustering system for horizontal scaling of MySQL through generalized sharding. By encapsulating shard-routing logic, Vite

Jan 3, 2023

db-recovery is a tool for recovering MySQL data.

db-recovery is a tool for recovering MySQL data. It is used in scenarios where the database has no backup or binlog. It can parse data files and redo/undo logs to recover data.

Nov 17, 2022

🐳 A most popular sql audit platform for mysql

🐳 A most popular sql audit platform for mysql

🐳 A most popular sql audit platform for mysql

Jan 6, 2023

Dumpling is a fast, easy-to-use tool written by Go for dumping data from the database(MySQL, TiDB...) to local/cloud(S3, GCP...) in multifarious formats(SQL, CSV...).

🥟 Dumpling Dumpling is a tool and a Go library for creating SQL dump from a MySQL-compatible database. It is intended to replace mysqldump and mydump

Nov 9, 2022

Vitess is a database clustering system for horizontal scaling of MySQL.

Vitess Vitess is a database clustering system for horizontal scaling of MySQL through generalized sharding. By encapsulating shard-routing logic, Vite

Jan 4, 2023

GitHub's Online Schema Migrations for MySQL

GitHub's Online Schema Migrations for MySQL

gh-ost GitHub's online schema migration for MySQL gh-ost is a triggerless online schema migration solution for MySQL. It is testable and provides paus

Jan 4, 2023
Comments
  • 用 pgsql 这么处理schema?

    用 pgsql 这么处理schema?

    比如 DB 是shopping,schema是mall, table 是 order

    db2go -host=xxx -port=5432 -user=read_only -pwd=password -dbname=shopping -table=mall.order -gorm=true -driver=pgsql -package=model

    结果: 警告:当前数据库中数据库表的数量为0,程序退出...

Related tags
mysql to mysql 轻量级多线程的库表数据同步

goMysqlSync golang mysql to mysql 轻量级多线程库表级数据同步 测试运行 设置当前binlog位置并且开始运行 go run main.go -position mysql-bin.000001 1 1619431429 查询当前binlog位置,参数n为秒数,查询结

Nov 15, 2022
auto generate sql from gorm model struct

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/li

Dec 22, 2022
A Go SQL query builder and struct mapper.

godb - a Go query builder and struct mapper godb is a simple Go query builder and struct mapper, not a full-featured ORM. godb does not manage relatio

Dec 6, 2022
database to golang struct
database to golang struct

中文文档 mysql database to golang struct conversion tools base on gorm(v1/v2),You can automatically generate golang sturct from mysql database. big Camel-

Jan 9, 2023
A go Library for scan database/sql rows to struct、slice、other types. And it support multiple databases connection management

ploto A go Library for scan database/sql rows to struct、slice、other types. And it support multiple databases connection management It's not an ORM. wo

Nov 3, 2022
Schemable - Schemable provides basic struct mapping against a database, using the squirrel package

Schemable Schemable provides basic struct mapping against a database, using the

Oct 17, 2022
ddl-maker generate ddl (SQL file) from Go struct.
ddl-maker generate ddl (SQL file) from Go struct.

[日本語] What is ddl-maker ddl-maker generate ddl (SQL file) from golang struct. It's only supported MySQL only now. The original code is kayac/ddl-maker

Jun 16, 2022
a powerful mysql toolset with Go
a powerful mysql toolset with Go

go-mysql A pure go library to handle MySQL network protocol and replication. Call for Committer/Maintainer Sorry that I have no enough time to maintai

Dec 28, 2022
Sync MySQL data into elasticsearch
Sync MySQL data into elasticsearch

go-mysql-elasticsearch is a service syncing your MySQL data into Elasticsearch automatically. It uses mysqldump to fetch the origin data at first, the

Dec 30, 2022
A high-performance MySQL proxy

kingshard 中文主页 Overview kingshard is a high-performance proxy for MySQL powered by Go. Just like other mysql proxies, you can use it to split the read

Dec 30, 2022