Rails 中的 SQL 查询构建器 [英] SQL query builder in rails
问题描述
我们正在尝试构建一个 SQL 查询构建器,允许用户使用视觉辅助进行查询.
我们已经让前端全部工作,用户能够选择表添加条件等.然而,我们的后端是一团糟,因为我们试图将这些查询作为字符串获取用户的条件,然后在我们的模型中创建适当的 SQL 字符串.
随着我们添加对越来越复杂的查询的支持,这最终会变得非常有问题并且难以维护.有没有人知道我们可以使用的 sql builder 插件,或者有更好的方法来解决这个问题.
We are trying to build a SQL query builder that would allow users to make queries using visual aid .
We have got the front end all worked up with the user being able to select tables add condition etc . However our backend is a mess as we are trying to make these queries as string taking the conditions from the user , and then making appropriate SQL strings in our models .
This would eventually become very buggy and difficult to maintain as we add support for more and more complex queries . Is anybody aware of a sql builder plugin that we can use , or a better way to approach this .
推荐答案
查看 arel.此项目的 fork 现在在 Rails 3 中用于帮助解决 ORM 不可知论.
Check out arel. A fork of this project is now used in Rails 3 to help with ORM agnosticism.
这篇关于Rails 中的 SQL 查询构建器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!