https://github.com/travisjeffery/proto-go-sql
Generate SQL Scanner and Valuer implementations for your Protobufs.
https://github.com/travisjeffery/proto-go-sql
Last synced: 6 months ago
JSON representation
Generate SQL Scanner and Valuer implementations for your Protobufs.
- Host: GitHub
- URL: https://github.com/travisjeffery/proto-go-sql
- Owner: travisjeffery
- Created: 2018-03-27T00:06:03.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T21:58:42.000Z (over 3 years ago)
- Last Synced: 2025-04-02T08:08:11.461Z (9 months ago)
- Language: Go
- Homepage: https://twitter.com/travisjeffery
- Size: 19.5 KB
- Stars: 77
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# proto-go-sql
Generate sql.Scanner and driver.Valuer implementations for your Protobufs.
## Example
We want the generated struct for this Person message to implement sql.Scanner and driver.Valuer so we can easily write and read it as JSON from Postgres.
So we compile the person.proto file:
``` proto
syntax = "proto3";
import "github.com/travisjeffery/proto-go-sql/sql.proto";
message Person {
option (sql.all) = "json";
string id = 1;
}
```
And run:
``` sh
$ protoc --sql_out=. person.proto
```
Generating this person_sql.go:
``` go
func (t *Person) Scan(val interface{}) error {
return json.Unmarshal(val.([]byte), t)
}
func (t *Person) Value() (driver.Value, error) {
return json.Marshal(t)
}
```
And we're done!
## License
MIT
---
- [travisjeffery.com](http://travisjeffery.com)
- GitHub [@travisjeffery](https://github.com/travisjeffery)
- Twitter [@travisjeffery](https://twitter.com/travisjeffery)
- Medium [@travisjeffery](https://medium.com/@travisjeffery)