Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaelemmmm committed Mar 27, 2022
0 parents commit da70ec5
Show file tree
Hide file tree
Showing 13 changed files with 1,091 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so

# Folders
_obj
_test

# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out

*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*

_testmain.go

*.exe
*.test
*.prof
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/sql2pb.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#### 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 (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
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
Loading

0 comments on commit da70ec5

Please sign in to comment.