插件rquerypad, 简化查询参数 增强关联查询能力

RQueryPad是一款针对Rails框架的插件,旨在简化ActiveRecord的查询选项,并改进内部连接功能。该工具支持混合使用内连接和外连接,并能自动移除重复连接,同时还提供了条件、排序和分组等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[url]http://code.google.com/p/rquerypad/[/url]
目前支持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,直接下载可以到 [url]https://rubyforge.org/projects/rquerypad/[/url]

[b]Feature[/b]
=======
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

[b]Install[/b]
=======
ruby script/plugin install http://rquerypad.googlecode.com/svn/trunk/rquerypad

[b]Example[/b]
=======
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


[b]Setup[/b]
=======
#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"


[b]Test[/b]
=======
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值