Giter Site home page Giter Site logo

sql2pb's Introduction

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

Generates a protobuf file from your mysql database.

Uses

Use from the command line:

go install github.com/Mikaelemmmm/sql2pb@latest

$ sql2pb -h

Usage of sql2pb:
  -db string
        the database type (default "mysql")
  -go_package string
        the protocol buffer gp_package. defaults to the database schema.
  -host string
        the database host (default "localhost")
  -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

import "github.com/Mikaelemmmm/sql2pb"

func main() {
    connStr := config.get("dbConnStr")
    pkg := "my_package"
    goPkg := "./my_package"
    table:= "*"
    serviceName:="usersrv"

    db, err := sql.Open(*dbType, connStr)
    if err != nil {
        log.Fatal(err)
    }

    defer db.Close()

	s, err := core.GenerateSchema(db, table,nil,serviceName, goPkg, pkg)

	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

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.