Go and Databases

agolangf · · 1340 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>What is everyone using for databases in Go applications? I have very little experience with databases, and I&#39;m not really sure where to start.</p> <p>If it matters, I&#39;m rewriting a simple blog I made, and thought that it would be a good opportunity to work with databases.</p> <hr/>**评论:**<br/><br/>postman_: <pre><p>sqlx with pq.</p></pre>stone_henge: <pre><p>I didn&#39;t know about sqlx... Thank you! Some coworkers have been using gorm, which I frankly think is an undocumented mess and a terrible abstraction that ends up being more complex than plain old SQL.</p></pre>nathj07: <pre><p>You can&#39;t go too far wrong with PostgreSQL and lib/pq. I&#39;ve not tried sqlx and while I hear good things I would suggest starting without it. That way you know the basics before the helpers. You can always drop sqlx in later</p></pre>BoTuLoX: <pre><p>sqlx is really minimal and is just a more convenient way of interacting with database/sql. The abstractions do very little, and more often than not the best documentation ends up being reading the source code, since it is so simple.</p></pre>iyee: <pre><p>We&#39;re using <a href="https://godoc.org/github.com/gocraft/dbr">dbr</a> by gocraft, it&#39;s simple &amp; efficient, I even wrote a generator for it to help our team.</p></pre>netzdamon: <pre><p>This looks much better than gorm, which I&#39;m currently using. Thanks.</p></pre>schumacherfm: <pre><p>dbr is currently under refactoring with some nice new features. Look into their postgres branch.</p></pre>tylersmith-uv: <pre><p>Thanks for trying out our newer stuff. We have been running it internally for a while now and should have the newer stuff in master very soon.</p></pre>tylersmith-uv: <pre><p>Hey, thanks for recommending us! What kind of generator did you write? I&#39;m imagining SQL tables to structs?</p> <p>Check out our <a href="https://github.com/gocraft/dbr/tree/postgres" rel="nofollow">new branch</a> which support more features, including Postgres. I&#39;m really happy with the work <a href="https://github.com/taylorchu" rel="nofollow">taylorchu</a> has done to enable multiple drivers, as well as more advance SQL features like subqueries and more complex conditionals.</p></pre>iyee: <pre><p>tables -&gt; structs of course. I really hope you guys don&#39;t modify the interfaces too much to follow up. :-)</p></pre>GoTheFuckToBed: <pre><p>I use PostgresSQL because of JSONB feature, was fun. For simple things I recommend SQLite.</p></pre>CzarSkye: <pre><p><a href="https://github.com/boltdb/bolt">https://github.com/boltdb/bolt</a> is an interesting choice, especially for a small blog or something relatively simple not needing a complex SQL db. It fully implemented in go, so all you need to do is import it as a library and your set. </p></pre>mickgardner: <pre><p>The usual MySQL (MariaDB), PostgreSQL, SQLite are all used. There are ORM(ish) libraries that are used in combination with these databases. One or Two Links to get you started: <a href="https://github.com/golang/go/wiki/Projects#databases-and-storage">Golang Wiki - Databases and Storiage</a> <a href="http://go-database-sql.org/">http://go-database-sql.org/</a></p></pre>devsquid: <pre><p>I got the feeling that none of the ORMs are fully there yet. Is that still the case?</p></pre>shadowmint: <pre><p>yes.</p></pre>mickgardner: <pre><p>The nature of Golang means that ORM&#39;s it&#39;s not as easy to develop ORM&#39;s as you might think. </p> <p>But you&#39;ll find GORP / GORM and the SQLX libraries to be helpful enough that you&#39;ll get by with only a little sql.</p></pre>jasrags: <pre><p>Yup. Working with MySQL. I&#39;m using <a href="https://github.com/go-sql-driver/mysql" rel="nofollow">https://github.com/go-sql-driver/mysql</a> for the driver and <a href="https://github.com/jmoiron/sqlx" rel="nofollow">https://github.com/jmoiron/sqlx</a> for some nice helper methods.</p></pre>Cubixmeister: <pre><p><a href="https://github.com/go-gorp/gorp" rel="nofollow">https://github.com/go-gorp/gorp</a></p></pre>d_rudy: <pre><p>I&#39;m currently using <a href="https://github.com/jinzhu/gorm" rel="nofollow">gorm</a> for my app. It&#39;s pretty decent. </p> <p>However, if I&#39;m being honest, I haven&#39;t really found a good database solution/pattern that feels like idiomatic go. All the ORMs feel like they&#39;re trying too hard to be ActiveRecord, and the standard library feels a little too close to the database.</p> <p>I&#39;ve started trying to write something that feels right to me, but with only marginal success. I just feel like in general we&#39;re doing SQL in Go wrong, but I don&#39;t know what is right. Am I crazy?</p></pre>kortemy: <pre><p>MongoDB, for simplicity, and there is a phenomenal driver for it - <a href="https://labix.org/mgo">mgo</a>. For me it&#39;s easier than ever to query db and marshal results into a struct. Give it a go.</p> <p>If you want to stick with SQL though, it doesn&#39;t really matter which one you pick, since they aare all compatible with <a href="https://golang.org/pkg/database/sql/">generic SQL interface</a> in standard library. Just make sure you use <a href="https://github.com/jmoiron/sqlx">sqlx</a> as a boost to that interface, it is very powerful.</p></pre>fungussa: <pre><p>MySQL and more recently I&#39;ve also been using <a href="https://github.com/jinzhu/gorm" rel="nofollow">gorm</a> to simplify building CRUD apps.</p></pre>ptman: <pre><p>I chose beego/orm over gorm because back then it looked better. But maybe gorm is better these days. At least I&#39;m having trouble with my current orm (<a href="https://github.com/astaxie/beego/issues/1019">https://github.com/astaxie/beego/issues/1019</a>). I&#39;ve also thought about switching to sqlx.</p></pre>r2k9: <pre><p>Don&#39;t be so hard on yourself. I am sure your apps are very nice. </p> <p><a href="https://m.youtube.com/watch?v=9CdVTCDdEwI">https://m.youtube.com/watch?v=9CdVTCDdEwI</a></p></pre>fungussa: <pre><p>What do you mean by that?</p></pre>r2k9: <pre><p>It was a joke. <a href="http://dictionary.reference.com/browse/crud" rel="nofollow">http://dictionary.reference.com/browse/crud</a></p></pre>zero_iq: <pre><p>He&#39;s making a lame joke about &#39;crud&#39; meaning crap.</p> <p>i.e. You said you&#39;re building &#39;crud&#39; (crap) apps. He says they&#39;re not so bad (<em>rimshot</em>)</p></pre>fungussa: <pre><p>doh!</p></pre>maruwan: <pre><p>If you want to learn how to work with databases; start with PostgreSQL. It&#39;s the best one and it&#39;s free.</p> <p>But for some reason a lot of people are using MySQL. I blame PHP&#39;s early support ... and I think PHP and MySQL have quite a few things in common. </p></pre>Arbaal: <pre><p>Using ORM under GO is always weird. GORM seems the most feature complete, but it&#39;s documentation is beyond horrible (the documentation is the README.md file in their repository..., the code is largely undocumented).</p> <p>Simple CRUD actions are really nice in GORM, but anything with relations is awkward to use. In the end you have so many &#34;gotchas&#34; to look out for, that it&#39;s starting to perplex a regular developer.</p> <p>In the end, standard database/sql with sqlx is the best thing to use. Simple CRUD work is also incredible easy with sqlx and I think it&#39;s better to let the developers learn proper SQL than let them learn the gotchas that GORM has.</p> <p>sql/sqlx might result in the end in a little more code, but it&#39;s much easier to understand and maintain in the end.</p></pre>schoenobates: <pre><p>Postgres and pgx (<a href="https://github.com/jackc/pgx" rel="nofollow">https://github.com/jackc/pgx</a>)</p></pre>bear1728: <pre><p>I have never done a large project, but for smaller ones I tend to use sqlite (<a href="https://github.com/mattn/go-sqlite3" rel="nofollow">https://github.com/mattn/go-sqlite3</a>) with the plain database/sql interface (sqlx looks good though). I would love to try bolt sometime since it&#39;s pure go, but I haven&#39;t needed a key/value store yet.</p></pre>elithrar_: <pre><p><a href="http://www.alexedwards.net/blog/organising-database-access" rel="nofollow">http://www.alexedwards.net/blog/organising-database-access</a> is a worthwhile read.</p></pre>Geir568: <pre><p>Check out <a href="https://github.com/geir54/ggap/" rel="nofollow">https://github.com/geir54/ggap/</a> it uses gorp and postgresql</p></pre>jrussbowman: <pre><p>I&#39;m working on a golang/rethinkdb project right now. I chose rethinkdb primarily because I&#39;m doing something that&#39;s going to require real time synchronization of messages between go app servers and a database. Seeing if rethinkdb will allow me to skip having to build in a message queue. </p></pre>Streamweaver66: <pre><p>I primarily use mongodb support for go applications right now though I&#39;ve done mysql with GORM as well.</p> <p>I kind of hate the state of database libraries in Go. GORP and GORM have made a good go of it (pun intended) but it&#39;s hard to come from something as mature as SQL Alchemy to the current state of DB support in Go. </p></pre>

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

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