<p>Let's say I have a table in Postgresql and I need to query it with sql and transform it to a protobuf.</p>
<p>The easiest way I can think of is to use the sql and postgres driver in go, query the database, get the row results, put them in some struct, then encode this struct with protobuf library. It looks to the beginner I am like there is too much overhead doing it this way. There probably is a better way. </p>
<p>I was wondering if there was a way to query the database, and directly get protobuf (is there some extension to do it? <a href="https://github.com/xstevens/decoderbufs" rel="nofollow">https://github.com/xstevens/decoderbufs</a> seems to do it but I'm not sure about what it does) and send then the result to the client.</p>
<p>Any idea is welcome. My skills with golang are somehow limited. My SQL skills are just good enough to query the database and get the information I want usually.</p>
<hr/>**评论:**<br/><br/>jb2p: <pre><ul>
<li>Install protoc</li>
<li>Create a .proto file. </li>
<li>Generate a golang struct using <a href="https://github.com/golang/protobuf" rel="nofollow">golang/protobuf</a></li>
<li>Fill the struct using sql.DB</li>
<li>Call proto.Marshal(struct)</li>
</ul></pre>: <pre><p>[deleted]</p></pre>rat9988: <pre><p>You didn't read my post I guess, but thanks anyway.</p></pre>
What is the most straight forward way to sql query a postgresql datbase and get result in form of protobuf?
xuanbao · · 495 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传