Skip to content

Commit

Permalink
Hooks builder instead of imported static functions (#82)
Browse files Browse the repository at this point in the history
* cleanup, initial hook refactor

* remove comment

* add hooks to the builder

* test new before hooks

* remove dead code

* minor changes to generated code

* remove extra spanner

* remove dead code

* update docs
  • Loading branch information
iamneal authored and namtzigla committed Oct 30, 2018
1 parent 87e6c57 commit f87ee27
Show file tree
Hide file tree
Showing 54 changed files with 403 additions and 7,299 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ protoc-gen-persist*
*~


bazel*
bazel*
.vscode
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ test: deps build

test-compile:
go build
DEBUG=false $(PROTOC) -I$(PROTOC_INCLUDE) -I. -I$$GOPATH/src \
DEBUG=false $(PROTOC) -I$(PROTOC_INCLUDE) -I. -I$$GOPATH/src \
--plugin=./protoc-gen-persist \
--persist_out=$$GOPATH/src tests/sql/little_of_everything/*.proto
DEBUG=false $(PROTOC) -I$(PROTOC_INCLUDE) -I. -I$$GOPATH/src \
Expand Down
37 changes: 10 additions & 27 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func IterUServUserProto(iter *persist_lib.Result, next func(i *User) error) erro
type UServImpl struct {
PERSIST *persist_lib.UServMethodReceiver
FORWARDED RestOfUServHandlers
HOOKS UServHooks
}
// ...
func (s *UServImpl) SelectUserById(ctx context.Context, req *User) (*User, error) {
Expand Down Expand Up @@ -166,11 +167,16 @@ type UServImplBuilder struct {
queryHandlers *persist_lib.UServQueryHandlers
i *UServImpl
db sql.DB
hooks UServHooks
}

func NewUServBuilder() *UServImplBuilder {
return &UServImplBuilder{i: &UServImpl{}}
}
func (b *UServImplBuilder) WithHooks(hs UServHooks) *UServImplBuilder {
b.hooks = hs
return b
}
func (b *UServImplBuilder) WithRestOfGrpcHandlers(r RestOfUServHandlers) *UServImplBuilder {
b.rest = r
return b
Expand Down Expand Up @@ -215,6 +221,7 @@ func (b *UServImplBuilder) Build() (*UServImpl, error) {
}
b.i.PERSIST = &persist_lib.UServMethodReceiver{Handlers: *b.queryHandlers}
b.i.FORWARDED = b.rest
b.i.HOOKS = b.hooks
return b.i, nil
}
func (b *UServImplBuilder) MustBuild() *UServImpl {
Expand Down Expand Up @@ -246,7 +253,7 @@ func (p *UserForUServ) SetFriends(param []byte) { p.Friends = param }
func (p *UserForUServ) GetCreatedOn() interface{} { return p.CreatedOn }
func (p *UserForUServ) SetCreatedOn(param interface{}) { p.CreatedOn = param }
```
- iterface for the query consisting of getters for the query parameters
- interface for the query consisting of getters for the query parameters
```go
type UServSelectUserByIdQueryParams interface {
GetId() int64
Expand Down Expand Up @@ -525,36 +532,12 @@ service Test {
option (persist.ql) = {
query: ["insert into example_table (id, start_time, name) Values (@id, @start_time, \"bananas\")"]
arguments: ["id", "start_time"]
before: {
name: "UniaryInsertBeforeHook"
package: "github.com/tcncloud/protoc-gen-persist/tests/spanner/hooks"
}
after: {
name: "UniaryInsertAfterHook"
package: "github.com/tcncloud/protoc-gen-persist/tests/spanner/hooks"
}
before: true
after: true
};
};
}
```
the actual option definitions for before/after hook:
```proto
message QLImpl {
// Callback definition function
// define the name and the package of a function with the signature
// func CallbackFunction(message pb.Message) (pb.Message, error)
message CallbackFunction {
// function name
required string name = 1;
// function go package name in the following formats
// github.com/repo;package
// github.com/package
// dir/package
// package
required string package = 2;
}
}
```


most other questions can be answered by looking at our
Expand Down
41 changes: 0 additions & 41 deletions examples/user_spanner/Makefile

This file was deleted.

71 changes: 0 additions & 71 deletions examples/user_spanner/main.go

This file was deleted.

Loading

0 comments on commit f87ee27

Please sign in to comment.