GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - xiafei114/sql2api: gozero api generate

BranchesTags
Open more actions menu

Latest commit

 

History

30 Commits
30 Commits

Folders and files

NameName
Last commit message
Last commit date
.vscode
.vscode
 
 
core
core
 
 
tools/stringx
tools/stringx
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build-w.bat
build-w.bat
 
 
go.mod
go.mod
 
 
go.sum
go.sum
 
 
sql2api.go
sql2api.go
 
 

Repository files navigation

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

Generates a api file from your mysql database. 仿照sql2pb写的生成通过 mysql database生成 gozero api文件 里面加了一些自己项目的理解,本着生成出来复制总比手敲好的原则还是挺好用的。

Uses

Use from the command line:

go install github.com/xiafei114/sql2api@latest 可能不好用,pull下来自己 go install吧

api最好配本人修改的sql2pb生成rpc服务 https://github.com/xiafei114/sql2pb

$ sql2api -h

Usage of sql2api:
  -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")

$ sql2api -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/xiafei114/sql2api@latest
package main

import (
	"database/sql"
	"fmt"
	"github.com/xiafei114/sql2api/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"

	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 : https://github.com/Mikaelemmmm/sql2pb

About

gozero api generate

Topics

apidatabasegenerategozeromysql

Resources

Readme
MIT license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.