Git Product home page Git Product logo

sql2pb's Introduction

Give a star before you see it. Ha ha ha ~ ~

Generates a protobuf file from your mysql database.

Uses

Tips: If your operating system is windows, the default encoding of windows command line is "GBK", you need to change it to "UTF-8", otherwise the generated file will be messed up.

Use from the command line:

go install github.com/Mikaelemmmm/sql2pb@latest

$ sql2pb -h

Usage of sql2pb:
  -db string
        the database type (default "mysql")
  -field_style string
        gen protobuf field style, sql_pb | sqlPb (default "sqlPb")
  -go_package string
        the protocol buffer go_package. defaults to the database schema.
  -host string
        the database host (default "localhost")
  -ignore_columns string
        a comma spaced list of mysql columns to ignore
  -ignore_tables string
        a comma spaced list of tables to ignore
  -package string
        the protocol buffer package. defaults to the database schema.
  -password string
        the database password (default "root")
  -port int
        the database port (default 3306)
  -schema string
        the database schema
  -service_name string
        the protobuf service name , defaults to the database schema.
  -table string
        the table schema,multiple tables ',' split.  (default "*")
  -user string
        the database user (default "root")

$ sql2pb -go_package ./pb -host localhost -package pb -password root -port 3306 -schema usercenter -service_name usersrv -user root > usersrv.proto

Use as an imported library

$ go get -u github.com/Mikaelemmmm/sql2pb@latest
package main

import (
	"database/sql"
	"fmt"
	"github.com/Mikaelemmmm/sql2pb/core"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

func main() {

	dbType:= "mysql"
	connStr := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", "root", "root", "127.0.0.1", 3306, "zero-demo")
	pkg := "my_package"
	goPkg := "./my_package"
	table:= "*"
	serviceName:="usersrv"
	fieldStyle := "sqlPb"

	db, err := sql.Open(dbType, connStr)
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()
	s, err := core.GenerateSchema(db, table,nil,nil,serviceName, goPkg, pkg,fieldStyle)

	if nil != err {
		log.Fatal(err)
	}

	if nil != s {
		fmt.Println(s)
	}
}

Thanks for schemabuf

schemabuf : https://github.com/mcos/schemabuf

sql2pb's People

Contributors

mikaelemmmm avatar zergmk2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

sql2pb's Issues

部分message 没有”}“

message SearchWaxAccountGroupReq {
int64 page = 1; //page
int64 pageSize = 2; //pageSize
int64 id = 3; //id
int64 pid = 4; //娓告垙ID
string name = 5; //缁勫悕
string rules = 6; //璐﹀彿缁?}

message SearchWaxAccountGroupResp {
repeated WaxAccountGroup waxAccountGroup = 1; //waxAccountGroup
}

生成后文件没有SearchWaxAccountGroupReq “}”

生成的方法名有点小问题


  rpc AddAddres(AddAddresReq) returns (AddAddresResp);

  rpc UpdateAddres(UpdateAddresReq) returns (UpdateAddresResp);```

表名Address ,生成的方法里面少了个s

在没有mysql密码的时候,生成报错

sql2pb -go_package ./pb -host 127.0.0.1 -package pb -password -port 3306 -schema appoint -service_name ordercenter -user root -table orders > ./ordercenter.proto

报错信息是 - please input the database schema

为什么我生成的中文是乱码

//--------------------------------鑺傜偣琛?-------------------------------
message SysAuthRule {
int64 id = 1; //id
SysAuthRuleType type = 2; //menu涓鸿彍鍗?file涓烘潈闄愯妭鐐? int64 pid = 3; //鐖禝D
string name = 4; //瑙勫垯鍚嶇О
string title = 5; //瑙勫垯鍚嶇О
string icon = 6; //鍥炬爣
string url = 7; //瑙勫垯URL
string condition = 8; //鏉′欢
string remark = 9; //澶囨敞
int64 ismenu = 10; //鏄惁涓鸿彍鍗? SysAuthRuleMenutype menutype = 11; //鑿滃崟绫诲瀷
string extend = 12; //鎵╁睍灞炴€? string py = 13; //鎷奸煶棣栧瓧姣? string pinyin = 14; //鎷奸煶
int64 weigh = 15; //鏉冮噸
string status = 16; //鐘舵€?}

文件格式编码是utf16???

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.