Dynamic SQL where clause generator

blov · · 550 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p><a href="https://play.golang.org/p/QN0S_O4dqe">https://play.golang.org/p/QN0S_O4dqe</a></p> <p>I&#39;ve been working on my own little ORM for fun and finally got to the point where I needed a good filter to produce some where clauses. Now I plan on having a much simpler one than this as well as this is for &#34;advanced&#34; filter generation. I would like to read everyone&#39;s thoughts on this though.</p> <hr/>**评论:**<br/><br/>blazes816: <pre><p>I normally use <a href="https://github.com/gocraft/dbr">dbr</a> to build and execute sql queries. Your should check it out. Even if you don&#39;t want to use it it may provide some good ideas.</p></pre>st1nc1ty: <pre><p>Thank you. I took a quick look and see that their and/or is similar to how I&#39;m attempting it, at least in presentation, haven&#39;t looked into the actual code just yet.</p></pre>TheMerovius: <pre><p>why sqlFilterMap -- why not just put the correct strings in there in the first place? Also, I noticed that you are manually assembling SQL queries by passing user-provided strings in there unescaped. That might blow up when used unwisely, it would probably be better to prevent that by Design (e.g. have fieldnames always be struct field names, which can&#39;t create broken stuff).</p> <p>Lastly, Filter seems like a weird type, because it&#39;s identical to fmt.Stringer.</p></pre>st1nc1ty: <pre><p>Yeah, you&#39;re right with the map. I had something else at first but kept it. It could easily go away. Escaping would definitely be something I do in the actual code. This was just a quick example. As for the fieldnames, my orm actually doesn&#39;t use user created structs (I know that sounds weird).</p></pre>phonkee: <pre><p>I personally use <a href="https://github.com/Masterminds/squirrel" rel="nofollow">https://github.com/Masterminds/squirrel</a></p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

550 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传