带有内存数据库的Rails [英] Rails with in memory database

查看:67
本文介绍了带有内存数据库的Rails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以设置rails以将MEMORY作为数据库引擎使用mysql吗?我从不重新启动mysql,并且经常重建数据库,所以我希望它速度更快.拥有用于运行测试的内存数据库也很好.

Can I set rails to use mysql with MEMORY as the DB engine? I never restart mysql, and rebuild the db so often I'd rather have it be fast. Having the memory db for running tests would be nice too.

我应该指定这仅用于开发/测试,而不是生产.

I should have specified this is for dev/testing only, not production.

推荐答案

我不明白为什么你不能这样做;您选择的存储引擎是MySQL实现细节.您需要做的就是在迁移的 create_table 声明中设置:options => "ENGINE=MEMORY".

I don't see why you couldn't; your choice of storage engine is a MySQL implementation detail. All you should need to do is set :options => "ENGINE=MEMORY" in your create_table declaration in your migrations.

当然,我也看不出你为什么会-尤其是在生产中.关于MEMORY引擎的MySQL文档充满了警告 a>,例如固定长度的字段分配,与失去一切的风险相比,您意识到的速度增益必须微不足道.如果您的应用程序不需要任何持久化,为什么不完全跳过ActiveRecord并将模型放在Memcached之上呢?

Of course, I also don't see why you would -- especially in production. The MySQL documentation for the MEMORY engine is full of caveats, like fixed length field allocation, and the speed gain you'd realize has got to be trivial compared to the risk of losing everything. If your application is such that nothing needs to be persisted, ever, why not just skip ActiveRecord completely and layer your models on top of Memcached?

这篇关于带有内存数据库的Rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆