protoc-gen-go_orm
Simply generate ORM model from proto
Install
go install github.com/sraphs/protoc-gen-go_orm@latest
Usage
Define your proto file in .proto
format.
// internal/testdata/fields.proto
syntax = "proto3";
package testdata;
import "orm/opts.proto";
option go_package = "ent/testdata";
message Pet {
option (orm.opts).gen = true;
string name = 1 [(orm.field) = { tag: [ "db", "id", "pk", "autoincrement" ] }];
}
Run protoc
to generate .pb.go
and _orm.pb.go
files.
protoc \
--proto_path ./internal/testdata \
--proto_path . \
--go_out=paths=source_relative:./out \
--go_orm_out=paths=source_relative:./out \
./internal/testdata/fields.proto
This will generate .pb.go
and _orm.pb.go
files in ./out
directory.
// out/fields_orm.pb.go
package testdata
import (
_ " github.com/sraphs/protoc-gen-go_orm/orm"
)
type PetORM struct {
Name string `db:"id,pk,autoincrement"`
}
first tag is used as tag key, and other tags are used as tag value.
Contributing
We alway welcome your contributions 👏
- Fork the repository
- Create Feat_xxx branch
- Commit your code
- Create Pull Request
CHANGELOG
See Releases
License
MIT © sraph.com