且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

mysql和mysql2 gem有什么区别

更新时间:2022-10-17 23:23:22

以下是来自 mysql2 gem页面的引用:


是啊......但为什么?



有人:Dude,Mysql gem works
fiiiiiine。

我:确实如此,但它只交出
你无和字符串的字段值。
让你将它们转换为
在Ruby-land中适当的Ruby类型 - 其中
的速度慢于球。



某人:OK很好,但do_mysql可以
已经给我返回的值与Ruby
对象映射到MySQL类型。



我:是的,但它的API是相当
更复杂,可以慢两倍。


I used to work with the mysql gem, but often nowadays I hear about the mysql2 gem. Also, it is included in the Gemfile by default in Rails 3.0.x.

What is the difference and advantages of using the mysql2 gem?

Here's a quote from the mysql2 gem page:

Yeah… but why?

Someone: Dude, the Mysql gem works fiiiiiine.

Me: It sure does, but it only hands you nil and strings for field values. Leaving you to convert them into proper Ruby types in Ruby-land - which is slow as balls.

Someone: OK fine, but do_mysql can already give me back values with Ruby objects mapped to MySQL types.

Me: Yep, but its API is considerably more complex and can be ~2x slower.