Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7b122f9a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7b122f9a
编写于
9月 08, 2010
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding maximum nodes
上级
301dfa5a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
61 addition
and
0 deletion
+61
-0
lib/arel/attributes/attribute.rb
lib/arel/attributes/attribute.rb
+4
-0
lib/arel/nodes.rb
lib/arel/nodes.rb
+1
-0
lib/arel/nodes/max.rb
lib/arel/nodes/max.rb
+22
-0
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+5
-0
spec/arel/attributes/attribute_spec.rb
spec/arel/attributes/attribute_spec.rb
+17
-0
spec/arel/nodes/sum_spec.rb
spec/arel/nodes/sum_spec.rb
+12
-0
未找到文件。
lib/arel/attributes/attribute.rb
浏览文件 @
7b122f9a
...
...
@@ -16,6 +16,10 @@ def count distinct = false
def
sum
Nodes
::
Sum
.
new
[
self
],
Nodes
::
SqlLiteral
.
new
(
'sum_id'
)
end
def
maximum
Nodes
::
Max
.
new
[
self
],
Nodes
::
SqlLiteral
.
new
(
'max_id'
)
end
end
class
String
<
Attribute
;
end
...
...
lib/arel/nodes.rb
浏览文件 @
7b122f9a
...
...
@@ -6,6 +6,7 @@
require
'arel/nodes/in'
require
'arel/nodes/count'
require
'arel/nodes/sum'
require
'arel/nodes/max'
require
'arel/nodes/sql_literal'
require
'arel/nodes/select_core'
require
'arel/nodes/select_statement'
...
...
lib/arel/nodes/max.rb
0 → 100644
浏览文件 @
7b122f9a
module
Arel
module
Nodes
class
Max
attr_accessor
:expressions
,
:alias
def
initialize
expr
,
aliaz
=
nil
@expressions
=
expr
@alias
=
aliaz
end
def
as
aliaz
self
.
alias
=
SqlLiteral
.
new
(
aliaz
)
self
end
def
to_sql
viz
=
Visitors
::
ToSql
.
new
Table
.
engine
viz
.
accept
self
end
end
end
end
lib/arel/visitors/to_sql.rb
浏览文件 @
7b122f9a
...
...
@@ -76,6 +76,11 @@ def visit_Arel_Nodes_Sum o
visit
x
}
.join(', ')})
#{
o
.
alias
?
" AS
#{
visit
o
.
alias
}
"
:
''
}
"
end
def
visit_Arel_Nodes_Max
o
"MAX(
#{
o
.
expressions
.
map
{
|
x
|
visit
x
}
.join(', ')})
#{
o
.
alias
?
" AS
#{
visit
o
.
alias
}
"
:
''
}
"
end
def
visit_Arel_Nodes_TableAlias
o
"
#{
visit
o
.
relation
}
#{
quote_table_name
o
.
name
}
"
end
...
...
spec/arel/attributes/attribute_spec.rb
浏览文件 @
7b122f9a
...
...
@@ -3,6 +3,23 @@
module
Arel
module
Attributes
describe
'attribute'
do
describe
'#maximum'
do
it
'should create a MAX node'
do
relation
=
Table
.
new
(
:users
)
relation
[
:id
].
maximum
.
should
be_kind_of
Nodes
::
Max
end
# FIXME: backwards compat. Is this really necessary?
it
'should set the alias to "max_id"'
do
relation
=
Table
.
new
(
:users
)
mgr
=
relation
.
project
relation
[
:id
].
maximum
mgr
.
to_sql
.
should
be_like
%{
SELECT MAX("users"."id") AS max_id
FROM "users"
}
end
end
describe
'#sum'
do
it
'should create a SUM node'
do
relation
=
Table
.
new
(
:users
)
...
...
spec/arel/nodes/sum_spec.rb
0 → 100644
浏览文件 @
7b122f9a
require
'spec_helper'
describe
Arel
::
Nodes
::
Sum
do
describe
"as"
do
it
'should alias the sum'
do
table
=
Arel
::
Table
.
new
:users
table
[
:id
].
sum
.
as
(
'foo'
).
to_sql
.
should
be_like
%{
SUM("users"."id") AS foo
}
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录