github.com/bencurio/go-pg-protobuf-types

Protobuf type appender and scanner for go-pg


License
MIT
Install
go get github.com/bencurio/go-pg-protobuf-types

Documentation

Protobuf types for go-pg

Example

// Connect to the PostgreSQL
db := pg.Connect(&pg.Options{
	User: "postgres",
})

// Register protobuf appender and scanner
go_pg_protobuf_types.RegisterAppenderAndScanner()

ctx := context.Background()

if err := db.Ping(ctx); err != nil {
    panic(err)
}

// Example struct
type MySchema struct {
    tableName struct{} `pg:"your_table"`

    IsLocked *wrapperspb.BoolValue `protobuf:"bytes,1,opt,name=is_locked,json=isLocked,proto3" json:"is_locked,omitempty"`
    CreateTime *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty" pg:",type:timestamptz"`
}

// Select query
var schema []*MySchema
err := db.Model(&schema).Select()
if err != nil {
	panic(err)
}

// Result
fmt.Printf("%v", schema)

// outputs: 
// [is_locked:{value:true} create_time:{seconds:1667842124 nanos:909462000}]

Useful links and libs