2008-03-18
插件rquerypad, 简化查询参数 增强关联查询能力
关键字: activerecord
http://code.google.com/p/rquerypad/
目前支持rails 2.0, rails 1.2(部分2.0 方式的查询))(谢谢Quake的测试及建议)
Simplify query options with association automation and improve inner join for activerecord of rails
字段名包含关联信息,不需额外再写include或者joins
原来activerecord仅支持inner join在最后,现在没有这个限制
不想用svn,直接下载可以到 https://rubyforge.org/projects/rquerypad/
Feature
=======
1. single name string decribe associations
2. support to mix inner join and outer join with any order
3. auto remove duplicated joins from other association in different depth
4. support :conditions, :order, :group
5. auto merge to original :include, :joins
Install
=======
ruby script/plugin install http://rquerypad.googlecode.com/svn/trunk/rquerypad
Example
=======
suppose the asscociations of User <-> Thread <-> Reply is 1:N:N
Setup
=======
#to set debug model, in rails initialized script
$RQUERYPAD_DEBUG = true
#to support rails 1.2.6, in rails initialized script, such as environment.rb
#default support rails 2.0
$RQUERYPAD_RAILS = "1.2"
Test
=======
Note: current migrate script works only in rails 2.0
1.Prepare
the test depends on sqlite3 database, the following code should be add into your database.yml and place rquerypad.rb(copy from test.rb) in config/environment
rquerypad:
adapter: sqlite3
database: vendor/plugins/rquerypad/test/db.rquerypad
timeout: 5000
2.database migrate
execute the following script
rake migrate
3.start test
execute the following script
rake
目前支持rails 2.0, rails 1.2(部分2.0 方式的查询))(谢谢Quake的测试及建议)
Simplify query options with association automation and improve inner join for activerecord of rails
字段名包含关联信息,不需额外再写include或者joins
原来activerecord仅支持inner join在最后,现在没有这个限制
不想用svn,直接下载可以到 https://rubyforge.org/projects/rquerypad/
Feature
=======
1. single name string decribe associations
2. support to mix inner join and outer join with any order
3. auto remove duplicated joins from other association in different depth
4. support :conditions, :order, :group
5. auto merge to original :include, :joins
Install
=======
ruby script/plugin install http://rquerypad.googlecode.com/svn/trunk/rquerypad
Example
=======
suppose the asscociations of User <-> Thread <-> Reply is 1:N:N
@users = User.find(:all, :group => ["threads.created_at", "name"])
generate:
[:all, {:group=>"threads.created_at, users.name", :include=>[:threads]}]
@users = User.find(:all, :conditions => ["threads_.replies.title = ?",
"rquerypad"])
generate:
[:all, {:inner_joins=>["threads"], :conditions=>["replies.title = ?", "rquerypad"], :include=>[{:threads=>:replies}]}]
#note: the :inner_joints is processed by rquerypad before sending sql to database
@users = User.find(:all, :conditions => ["threads.replies.title = ? and threads.id = ?", "rquerypad", 1])
generate:
[:all, {:conditions=>["replies.title = ? and threads.id = ?", "rquerypad", 1], :include=>[{:threads=>:replies}]}]
#note: single "threads" was removed from includes
Setup
=======
#to set debug model, in rails initialized script
$RQUERYPAD_DEBUG = true
#to support rails 1.2.6, in rails initialized script, such as environment.rb
#default support rails 2.0
$RQUERYPAD_RAILS = "1.2"
Test
=======
Note: current migrate script works only in rails 2.0
1.Prepare
the test depends on sqlite3 database, the following code should be add into your database.yml and place rquerypad.rb(copy from test.rb) in config/environment
rquerypad:
adapter: sqlite3
database: vendor/plugins/rquerypad/test/db.rquerypad
timeout: 5000
2.database migrate
execute the following script
rake migrate
3.start test
execute the following script
rake
评论
lllyq
2008-03-21
哪我估计ambition要大改才行,毕竟他走上一个更抽象的层次,又想适应特殊要求的具体场合,我想这也就是半年多以来他无视inner join的基本需求的原因
Stainlesssteel
2008-03-21
或许可以给ambition贡献一下
ambition 模仿 LINQ 还是有前途的
ambition 模仿 LINQ 还是有前途的
lllyq
2008-03-21
Stainlesssteel 写道
ambition的
User.detect { |u| u.email =~ 'chris%' && u.profile.blog == 'Err' }
"SELECT users.`id` AS t0_r0 ... FROM users
LEFT OUTER JOIN profiles ON profiles.user_id = users.id
WHERE ((users.`email` LIKE 'chris%' AND profiles.blog = 'Err'))
LIMIT 1"
User.detect { |u| u.email =~ 'chris%' && u.profile.blog == 'Err' }
"SELECT users.`id` AS t0_r0 ... FROM users
LEFT OUTER JOIN profiles ON profiles.user_id = users.id
WHERE ((users.`email` LIKE 'chris%' AND profiles.blog = 'Err'))
LIMIT 1"
我原来也没打算做rquerypad,想用ambition,但仔细看了下功能比较弱,inner join都不支持,更不要说乱序混合join了,花哨不实用只是花瓶
关于ambition, 我原来还想修改ambition来实现的,但发现ambition是用自己的优势绑住自己的脚,它抽象出核心部分,具体的ldap, sql的就做adpater,但sql毕竟比较复杂,要能达到sql的正常使用必须要扩展, 但是他的没有给adapter提供扩展能力,要改就要把ambition, 以及对应的adapter都改了,工作量还不如专门写一个针对activerecord的插件,这就是rquerypad的由来。
而且ambition为了用好看的ruby way(方向不错),还用到了parsetree,搞得太复杂,其实不过是activerecord的adapter,activerecord本来就弱,搞得再花也没用
Stainlesssteel
2008-03-21
ambition的
User.detect { |u| u.email =~ 'chris%' && u.profile.blog == 'Err' }
"SELECT users.`id` AS t0_r0 ... FROM users
LEFT OUTER JOIN profiles ON profiles.user_id = users.id
WHERE ((users.`email` LIKE 'chris%' AND profiles.blog = 'Err'))
LIMIT 1"
User.detect { |u| u.email =~ 'chris%' && u.profile.blog == 'Err' }
"SELECT users.`id` AS t0_r0 ... FROM users
LEFT OUTER JOIN profiles ON profiles.user_id = users.id
WHERE ((users.`email` LIKE 'chris%' AND profiles.blog = 'Err'))
LIMIT 1"
lllyq
2008-03-21
看看你报的是什么错?我并刚刚试用了act_as_tree,修复了一个bug,但跟act_as_tree关系不大,我试过find all, tree object.each 没问题
fix bug when field is a id with single table which has belongs_to association, such as "parent.id"
现在最新版是提交了0.1.5,并增加了相关act_as_tree的测试,你可以install最新的,如果还有问题,你贴一下测试代码,测试很简单,装了sqlite3(注意还要装sqlite3.dll到ruby/bin),然后再rquerypad下rake migrate, rake
fix bug when field is a id with single table which has belongs_to association, such as "parent.id"
现在最新版是提交了0.1.5,并增加了相关act_as_tree的测试,你可以install最新的,如果还有问题,你贴一下测试代码,测试很简单,装了sqlite3(注意还要装sqlite3.dll到ruby/bin),然后再rquerypad下rake migrate, rake
Raecoo
2008-03-21
在Model使用 acts_as_tree 时发现有点问题
比如:
class Product < ActiveRecord::Base
acts_as_tree
end
products = Product.find(:all)
products.each do |p|
p.children.each ..... 这里就报错
..............
end
插件一安装就出这个问题,不知道是使用不当还是?
环境 Rails 2.0.2
比如:
class Product < ActiveRecord::Base
acts_as_tree
end
products = Product.find(:all)
products.each do |p|
p.children.each ..... 这里就报错
..............
end
插件一安装就出这个问题,不知道是使用不当还是?
环境 Rails 2.0.2
lllyq
2008-03-20
不好意思,要在environments.rb 的顶行写,保证在插件初始化之前,我还要补点注释
而且对rails 1.2兼容不是全兼容,find_all就不能兼容,只能兼容find(:all)
rquerypad 最新的是0.1.4版本,加了计算函数的支持,如 count/average
而且对rails 1.2兼容不是全兼容,find_all就不能兼容,只能兼容find(:all)
rquerypad 最新的是0.1.4版本,加了计算函数的支持,如 count/average
sun201200204
2008-03-20
我的是1.2.3版本 好像不行
undefined method `extract_options!' for [:all]:Array
(eval):9:in `find'
这里有一句@goal_status = GoalStatus.find(:all)
不知道是什么原因
在源代码中看到有个这个:
options = #{if $RQUERYPAD_RAILS == "1.2" then "extract_options_from_args!(args)" else "args.extract_options!" end}
可是有已经写上$RQUERYPAD_RAILS == "1.2"了啊
$RQUERYPAD_DEBUG = true 要写吗?写在什么地方?
undefined method `extract_options!' for [:all]:Array
(eval):9:in `find'
这里有一句@goal_status = GoalStatus.find(:all)
不知道是什么原因
在源代码中看到有个这个:
options = #{if $RQUERYPAD_RAILS == "1.2" then "extract_options_from_args!(args)" else "args.extract_options!" end}
可是有已经写上$RQUERYPAD_RAILS == "1.2"了啊
$RQUERYPAD_DEBUG = true 要写吗?写在什么地方?
lllyq
2008-03-20
有下划线的表示该连接使用inner join,后面的注释没有写的很清楚,我会补上去
shanghaichris
2008-03-20
示例当中的:@users = User.find(:all, :conditions => ["threads_.replies.title = ?",
"rquerypad"])
当中的threads_这个下划线是不是多打了,笔误?
"rquerypad"])
当中的threads_这个下划线是不是多打了,笔误?
lllyq
2008-03-20
装好plugin,如果是rails 2.0直接就可以用了
如果是rails 1.2 需要在environment里设置一个$RQUERYPAD_RAILS = "1.2" ,而且只支持2.0推荐的方式查询,例如find(:all)而不能用find_all(这个在2.0已经被删除了,谢谢Quake帮助测试)
另外好消息是,今天在https://rubyforge.org/上首页新闻推荐了rquerypad
如果是rails 1.2 需要在environment里设置一个$RQUERYPAD_RAILS = "1.2" ,而且只支持2.0推荐的方式查询,例如find(:all)而不能用find_all(这个在2.0已经被删除了,谢谢Quake帮助测试)
另外好消息是,今天在https://rubyforge.org/上首页新闻推荐了rquerypad
sun201200204
2008-03-20
强啊
不过怎么添加到自己的项目中中的model和controller中用呢
不过怎么添加到自己的项目中中的model和controller中用呢
Quake Wang
2008-03-19
这东西很棒!这样就可以像hibernate那样写关联查询语句,不需要手动指明join了。
发表评论
提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则
- 浏览: 14970 次
- 性别:

- 来自: Shanghai

- 详细资料
搜索本博客
我的相册
filemanager
共 8 张
共 8 张
最近加入圈子
最新评论
-
基于hibernate的开源通用 ...
不要都忙着想实现,性能如何很重要,对几十万条以上记录的表进行分页性能如何?有没有 ...
-- by vickey -
基于hibernate的开源通用 ...
授之以鱼不如授之以渔
-- by vlinux -
基于hibernate的开源通用 ...
而且现在都找不到下载了の
-- by fangsimple -
Rlayout,erb定义layout ...
更新了,加了支持field tag的主题模板的功能
-- by lllyq -
基于hibernate的开源通用 ...
我觉得不怎么样,根本就不像是一个开源的东东,源码没有任何注释。不是一个合格的东东
-- by bjheby






评论排行榜