<p>Hello, there! I'd been searching for a while around for some good decision how to manage queries to SQL-based db, but find nothing, just a couple of ORM lib, that do not provide real ORM. So my question is: How do you manage it, and is there anywhere elegant way to make it? </p>
<hr/>**评论:**<br/><br/>jupiter909: <pre><p>I'd say this is a pretty good place to start looking:
<a href="http://go-database-sql.org/" rel="nofollow">http://go-database-sql.org/</a></p></pre>qu33ksilver: <pre><p>This is very nice. Thanks!</p></pre>romain_vanesyan: <pre><p>But I don't want to work with SQL directly as sometimes queries maybe too long and too complex to handled by hands...</p></pre>eyecikjou567: <pre><p><a href="http://jinzhu.me/gorm/" rel="nofollow">http://jinzhu.me/gorm/</a></p>
<p>This one is probably the best ORM and it does what I need atm.</p></pre>0xembark: <pre><p>Why is this marked NSFW?... </p></pre>bradfitz: <pre><p>Indeed. Fixed.</p></pre>gogroob: <pre><p>I'm actually learning how to do this as well, and maybe what I have so far is terrible, but
<a href="https://raw.githubusercontent.com/micromdm/micromdm/rewrite/profile/datastore.go" rel="nofollow">this</a> is a pattern I'm trying now.</p>
<p>smaller example for building a select query. we could define additional interfaces like <code>grouper</code> to <code>GROUP BY</code>.
Someone on the Slack team showed me how to use the filters.<br/>
<a href="https://play.golang.org/p/umquNMPJu6" rel="nofollow">https://play.golang.org/p/umquNMPJu6</a></p></pre>I_HATE_SPIES: <pre><p>First I create a repo interface which specifies the actions I want to take on my persistence layer:</p>
<p>type TodoRepository interface {<br/>
ListTodos() []ID<br/>
GetTodo(ID) Todo<br/>
SaveTodo(ID, Todo)<br/>
// etc...<br/>
}</p>
<p>then I implement a simple in-memory debug-implementation and get on with my day.</p>
<p>i wait until most of the application is done before i make a database-backed implementation of my Repository, using the sqlx package.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传