如何单独使用activerecord?
我准备开发一个没有UI的项目。项目只是需要和数据库进行交互,有没有例子可以参考?
I prepare to develop one project, which has no UI. The project just need to interact with database, so is there any example for reference ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的应用程序是否与基于 Rails 的应用程序有联系并且需要读取 Rails 配置文件?或者,它是完全独立的并且没有 Rails 交互吗?
ActiveRecord 可以,但如果我不需要 Rails 兼容性,我使用
Sequel
。这是一个很棒的 ORM,我发现它更加灵活。如果您需要 Rails 兼容性并希望使用 ActiveRecord,请考虑使用
rails runner
。来自文档:Rails runner 适用于不需要 HTTPd 服务器或 Rails 用户界面的命令行应用程序。我将它们用于诸如每天运行的应用程序以从站点下载 ftp 文件以进行分析之类的用途。它必须写入数据库,因此它可以访问我定义的所有模型,但它永远不需要向用户呈现任何内容,因为它对用户来说是不可见的。
Does your app have ties to a Rails-based app and need to read the Rails configuration files? Or, is it entirely stand-alone and have no Rails interaction?
ActiveRecord is OK for that, but if I don't need Rails compatibility I use
Sequel
. It's a great ORM that I find to be much more flexible.If you need Rails compatibility and want to use ActiveRecord, look into using
rails runner
. From the docs:Rails runner is for command-line apps that don't need the HTTPd server or user-interface of Rails. I use them for things like an app that runs daily to ftp files from a site for analysis. It has to write to the database, so it has access to all the models I've defined, but it never needs to present anything to the user since it is invisible to them.