Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f0c4e371
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,发现更多精彩内容 >>
提交
f0c4e371
编写于
1月 04, 2011
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added Arel::Nodes::NamedFunction for representing generic SQL functions
上级
dd1a6545
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
102 addition
and
12 deletion
+102
-12
History.txt
History.txt
+1
-0
Manifest.txt
Manifest.txt
+4
-0
lib/arel/nodes.rb
lib/arel/nodes.rb
+1
-0
lib/arel/nodes/count.rb
lib/arel/nodes/count.rb
+0
-3
lib/arel/nodes/function.rb
lib/arel/nodes/function.rb
+2
-1
lib/arel/nodes/named_function.rb
lib/arel/nodes/named_function.rb
+12
-0
lib/arel/visitors/depth_first.rb
lib/arel/visitors/depth_first.rb
+8
-0
lib/arel/visitors/dot.rb
lib/arel/visitors/dot.rb
+18
-7
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+6
-0
test/nodes/test_named_function.rb
test/nodes/test_named_function.rb
+13
-0
test/nodes/test_node.rb
test/nodes/test_node.rb
+1
-0
test/visitors/test_depth_first.rb
test/visitors/test_depth_first.rb
+7
-1
test/visitors/test_dot.rb
test/visitors/test_dot.rb
+19
-0
test/visitors/test_to_sql.rb
test/visitors/test_to_sql.rb
+10
-0
未找到文件。
History.txt
浏览文件 @
f0c4e371
...
...
@@ -5,6 +5,7 @@
* AST is now Enumerable
* AND nodes are now n-ary nodes
* SQL Literals may be used as Attribute names
* Added Arel::Nodes::NamedFunction for representing generic SQL functions
* Deprecations
...
...
Manifest.txt
浏览文件 @
f0c4e371
...
...
@@ -28,6 +28,7 @@ lib/arel/nodes/inner_join.rb
lib/arel/nodes/insert_statement.rb
lib/arel/nodes/join_source.rb
lib/arel/nodes/lock.rb
lib/arel/nodes/named_function.rb
lib/arel/nodes/node.rb
lib/arel/nodes/ordering.rb
lib/arel/nodes/outer_join.rb
...
...
@@ -52,6 +53,7 @@ lib/arel/visitors.rb
lib/arel/visitors/depth_first.rb
lib/arel/visitors/dot.rb
lib/arel/visitors/join_sql.rb
lib/arel/visitors/mssql.rb
lib/arel/visitors/mysql.rb
lib/arel/visitors/oracle.rb
lib/arel/visitors/order_clauses.rb
...
...
@@ -67,6 +69,7 @@ test/nodes/test_count.rb
test/nodes/test_delete_statement.rb
test/nodes/test_equality.rb
test/nodes/test_insert_statement.rb
test/nodes/test_named_function.rb
test/nodes/test_node.rb
test/nodes/test_not.rb
test/nodes/test_or.rb
...
...
@@ -88,6 +91,7 @@ test/test_update_manager.rb
test/visitors/test_depth_first.rb
test/visitors/test_dot.rb
test/visitors/test_join_sql.rb
test/visitors/test_mssql.rb
test/visitors/test_mysql.rb
test/visitors/test_oracle.rb
test/visitors/test_postgres.rb
...
...
lib/arel/nodes.rb
浏览文件 @
f0c4e371
...
...
@@ -28,6 +28,7 @@
require
'arel/nodes/function'
require
'arel/nodes/count'
require
'arel/nodes/values'
require
'arel/nodes/named_function'
# joins
require
'arel/nodes/inner_join'
...
...
lib/arel/nodes/count.rb
浏览文件 @
f0c4e371
module
Arel
module
Nodes
class
Count
<
Arel
::
Nodes
::
Function
attr_accessor
:distinct
def
initialize
expr
,
distinct
=
false
,
aliaz
=
nil
super
(
expr
,
aliaz
)
@distinct
=
distinct
...
...
lib/arel/nodes/function.rb
浏览文件 @
f0c4e371
...
...
@@ -2,11 +2,12 @@ module Arel
module
Nodes
class
Function
<
Arel
::
Nodes
::
Node
include
Arel
::
Expression
attr_accessor
:expressions
,
:alias
attr_accessor
:expressions
,
:alias
,
:distinct
def
initialize
expr
,
aliaz
=
nil
@expressions
=
expr
@alias
=
aliaz
@distinct
=
false
end
def
as
aliaz
...
...
lib/arel/nodes/named_function.rb
0 → 100644
浏览文件 @
f0c4e371
module
Arel
module
Nodes
class
NamedFunction
<
Arel
::
Nodes
::
Function
attr_accessor
:name
def
initialize
name
,
expr
,
aliaz
=
nil
super
(
expr
,
aliaz
)
@name
=
name
end
end
end
end
lib/arel/visitors/depth_first.rb
浏览文件 @
f0c4e371
...
...
@@ -28,6 +28,7 @@ def unary o
def
function
o
visit
o
.
expressions
visit
o
.
alias
visit
o
.
distinct
end
alias
:visit_Arel_Nodes_Avg
:function
alias
:visit_Arel_Nodes_Exists
:function
...
...
@@ -35,6 +36,13 @@ def function o
alias
:visit_Arel_Nodes_Min
:function
alias
:visit_Arel_Nodes_Sum
:function
def
visit_Arel_Nodes_NamedFunction
o
visit
o
.
name
visit
o
.
expressions
visit
o
.
distinct
visit
o
.
alias
end
def
visit_Arel_Nodes_Count
o
visit
o
.
expressions
visit
o
.
alias
...
...
lib/arel/visitors/dot.rb
浏览文件 @
f0c4e371
...
...
@@ -38,13 +38,6 @@ def visit_Arel_Nodes_TableAlias o
visit_edge
o
,
"relation"
end
def
visit_Arel_Nodes_Sum
o
visit_edge
o
,
"expressions"
visit_edge
o
,
"alias"
end
alias
:visit_Arel_Nodes_Max
:visit_Arel_Nodes_Sum
alias
:visit_Arel_Nodes_Avg
:visit_Arel_Nodes_Sum
def
visit_Arel_Nodes_Count
o
visit_edge
o
,
"expressions"
visit_edge
o
,
"distinct"
...
...
@@ -82,6 +75,24 @@ def unary o
alias
:visit_Arel_Nodes_Top
:unary
alias
:visit_Arel_Nodes_UnqualifiedColumn
:unary
def
function
o
visit_edge
o
,
"expressions"
visit_edge
o
,
"distinct"
visit_edge
o
,
"alias"
end
alias
:visit_Arel_Nodes_Exists
:function
alias
:visit_Arel_Nodes_Min
:function
alias
:visit_Arel_Nodes_Max
:function
alias
:visit_Arel_Nodes_Avg
:function
alias
:visit_Arel_Nodes_Sum
:function
def
visit_Arel_Nodes_NamedFunction
o
visit_edge
o
,
"name"
visit_edge
o
,
"expressions"
visit_edge
o
,
"distinct"
visit_edge
o
,
"alias"
end
def
visit_Arel_Nodes_InsertStatement
o
visit_edge
o
,
"relation"
visit_edge
o
,
"columns"
...
...
lib/arel/visitors/to_sql.rb
浏览文件 @
f0c4e371
...
...
@@ -183,6 +183,12 @@ def visit_Arel_Nodes_Group o
visit
o
.
expr
end
def
visit_Arel_Nodes_NamedFunction
o
"
#{
o
.
name
}
(
#{
o
.
distinct
?
'DISTINCT '
:
''
}#{
o
.
expressions
.
map
{
|
x
|
visit
x
}
.join(', ')})
#{
o
.
alias
?
" AS
#{
visit
o
.
alias
}
"
:
''
}
"
end
def
visit_Arel_Nodes_Count
o
"COUNT(
#{
o
.
distinct
?
'DISTINCT '
:
''
}#{
o
.
expressions
.
map
{
|
x
|
visit
x
...
...
test/nodes/test_named_function.rb
0 → 100644
浏览文件 @
f0c4e371
require
'helper'
module
Arel
module
Nodes
class
TestNamedFunction
<
MiniTest
::
Unit
::
TestCase
def
test_construct
function
=
NamedFunction
.
new
'omg'
,
'zomg'
assert_equal
'omg'
,
function
.
name
assert_equal
'zomg'
,
function
.
expressions
end
end
end
end
test/nodes/test_node.rb
浏览文件 @
f0c4e371
...
...
@@ -11,6 +11,7 @@ def test_all_nodes_are_nodes
Nodes
.
const_get
(
k
)
}.
grep
(
Class
).
each
do
|
klass
|
next
if
Nodes
::
SqlLiteral
==
klass
next
if
klass
.
name
=~
/^Arel::Nodes::Test/
assert
klass
.
ancestors
.
include?
(
Nodes
::
Node
),
klass
.
name
end
end
...
...
test/visitors/test_depth_first.rb
浏览文件 @
f0c4e371
...
...
@@ -52,10 +52,16 @@ def test_raises_with_object
define_method
(
"test_
#{
klass
.
name
.
gsub
(
'::'
,
'_'
)
}
"
)
do
func
=
klass
.
new
(
:a
,
:b
)
@visitor
.
accept
func
assert_equal
[
:a
,
:b
,
func
],
@collector
.
calls
assert_equal
[
:a
,
:b
,
f
alse
,
f
unc
],
@collector
.
calls
end
end
def
test_named_function
func
=
Arel
::
Nodes
::
NamedFunction
.
new
(
:a
,
:b
,
:c
)
@visitor
.
accept
func
assert_equal
[
:a
,
:b
,
false
,
:c
,
func
],
@collector
.
calls
end
def
test_lock
lock
=
Nodes
::
Lock
.
new
@visitor
.
accept
lock
...
...
test/visitors/test_dot.rb
浏览文件 @
f0c4e371
...
...
@@ -7,6 +7,25 @@ def setup
@visitor
=
Visitors
::
Dot
.
new
end
# functions
[
Nodes
::
Sum
,
Nodes
::
Exists
,
Nodes
::
Max
,
Nodes
::
Min
,
Nodes
::
Avg
,
].
each
do
|
klass
|
define_method
(
"test_
#{
klass
.
name
.
gsub
(
'::'
,
'_'
)
}
"
)
do
op
=
klass
.
new
(
:a
,
:z
)
@visitor
.
accept
op
end
end
def
test_named_function
func
=
Nodes
::
NamedFunction
.
new
'omg'
,
'omg'
@visitor
.
accept
func
end
# unary ops
[
Arel
::
Nodes
::
Not
,
...
...
test/visitors/test_to_sql.rb
浏览文件 @
f0c4e371
...
...
@@ -15,6 +15,16 @@ module Visitors
sql
.
must_be_like
'"users".*'
end
it
'should visit named functions'
do
function
=
Nodes
::
NamedFunction
.
new
(
'omg'
,
[
Arel
.
star
])
assert_equal
'omg(*)'
,
@visitor
.
accept
(
function
)
end
it
'works with lists'
do
function
=
Nodes
::
NamedFunction
.
new
(
'omg'
,
[
Arel
.
star
,
Arel
.
star
])
assert_equal
'omg(*, *)'
,
@visitor
.
accept
(
function
)
end
describe
'equality'
do
it
'should handle false'
do
sql
=
@visitor
.
accept
Nodes
::
Equality
.
new
(
false
,
false
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录