Skip to content

travisjeffery/proto-go-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

syntax = "proto3";

import "github.com/travisjeffery/proto-go-sql/sql.proto";

message Person {
  option (sql.all) = "json";

  string id = 1;
}

And run:

$ protoc --sql_out=. person.proto

Generating this person_sql.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


About

Generate SQL Scanner and Valuer implementations for your Protobufs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published