Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
83c47c19
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,体验更适合开发者的 AI 搜索 >>
提交
83c47c19
编写于
12月 31, 2015
作者:
K
Keenan Brock
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add database specific string concatenation
上级
dfd22638
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
47 addition
and
3 deletion
+47
-3
lib/arel/nodes/infix_operation.rb
lib/arel/nodes/infix_operation.rb
+6
-1
lib/arel/predications.rb
lib/arel/predications.rb
+4
-0
lib/arel/visitors/depth_first.rb
lib/arel/visitors/depth_first.rb
+1
-0
lib/arel/visitors/dot.rb
lib/arel/visitors/dot.rb
+1
-0
lib/arel/visitors/mysql.rb
lib/arel/visitors/mysql.rb
+8
-0
test/visitors/test_depth_first.rb
test/visitors/test_depth_first.rb
+1
-0
test/visitors/test_mysql.rb
test/visitors/test_mysql.rb
+18
-0
test/visitors/test_to_sql.rb
test/visitors/test_to_sql.rb
+8
-2
未找到文件。
lib/arel/nodes/infix_operation.rb
浏览文件 @
83c47c19
...
...
@@ -40,5 +40,10 @@ def initialize left, right
end
end
class
Concat
<
InfixOperation
def
initialize
left
,
right
super
(
'||'
,
left
,
right
)
end
end
end
end
\ No newline at end of file
end
lib/arel/predications.rb
浏览文件 @
83c47c19
...
...
@@ -202,6 +202,10 @@ def when right
Nodes
::
Case
.
new
(
self
).
when
quoted_node
(
right
)
end
def
concat
other
Nodes
::
Concat
.
new
self
,
other
end
private
def
grouping_any
method_id
,
others
,
*
extras
...
...
lib/arel/visitors/depth_first.rb
浏览文件 @
83c47c19
...
...
@@ -72,6 +72,7 @@ def binary o
alias
:visit_Arel_Nodes_As
:binary
alias
:visit_Arel_Nodes_Assignment
:binary
alias
:visit_Arel_Nodes_Between
:binary
alias
:visit_Arel_Nodes_Concat
:binary
alias
:visit_Arel_Nodes_DeleteStatement
:binary
alias
:visit_Arel_Nodes_DoesNotMatch
:binary
alias
:visit_Arel_Nodes_Equality
:binary
...
...
lib/arel/visitors/dot.rb
浏览文件 @
83c47c19
...
...
@@ -176,6 +176,7 @@ def binary o
alias
:visit_Arel_Nodes_As
:binary
alias
:visit_Arel_Nodes_Assignment
:binary
alias
:visit_Arel_Nodes_Between
:binary
alias
:visit_Arel_Nodes_Concat
:binary
alias
:visit_Arel_Nodes_DoesNotMatch
:binary
alias
:visit_Arel_Nodes_Equality
:binary
alias
:visit_Arel_Nodes_GreaterThan
:binary
...
...
lib/arel/visitors/mysql.rb
浏览文件 @
83c47c19
...
...
@@ -72,6 +72,14 @@ def visit_Arel_Nodes_UpdateStatement o, collector
maybe_visit
o
.
limit
,
collector
end
def
visit_Arel_Nodes_Concat
o
,
collector
collector
<<
" CONCAT("
visit
o
.
left
,
collector
collector
<<
", "
visit
o
.
right
,
collector
collector
<<
") "
collector
end
end
end
end
test/visitors/test_depth_first.rb
浏览文件 @
83c47c19
...
...
@@ -103,6 +103,7 @@ def test_right_outer_join
[
Arel
::
Nodes
::
Assignment
,
Arel
::
Nodes
::
Between
,
Arel
::
Nodes
::
Concat
,
Arel
::
Nodes
::
DoesNotMatch
,
Arel
::
Nodes
::
Equality
,
Arel
::
Nodes
::
GreaterThan
,
...
...
test/visitors/test_mysql.rb
浏览文件 @
83c47c19
...
...
@@ -55,6 +55,24 @@ def compile node
compile
(
node
).
must_be_like
"LOCK IN SHARE MODE"
end
end
describe
"concat"
do
it
"concats columns"
do
@table
=
Table
.
new
(
:users
)
query
=
@table
[
:name
].
concat
(
@table
[
:name
])
compile
(
query
).
must_be_like
%{
CONCAT("users"."name", "users"."name")
}
end
it
"concats a string"
do
@table
=
Table
.
new
(
:users
)
query
=
@table
[
:name
].
concat
(
Nodes
.
build_quoted
(
'abc'
))
compile
(
query
).
must_be_like
%{
CONCAT("users"."name", 'abc')
}
end
end
end
end
end
test/visitors/test_to_sql.rb
浏览文件 @
83c47c19
...
...
@@ -469,13 +469,19 @@ def quote value, column = nil
compile
(
node
).
must_equal
%(("products"."price" - 7))
end
it
"should handle Concatination"
do
table
=
Table
.
new
(
:users
)
node
=
table
[
:name
].
concat
(
table
[
:name
])
compile
(
node
).
must_equal
%("users"."name" || "users"."name")
end
it
"should handle arbitrary operators"
do
node
=
Arel
::
Nodes
::
InfixOperation
.
new
(
'
||
'
,
'
&&
'
,
Arel
::
Attributes
::
String
.
new
(
Table
.
new
(
:products
),
:name
),
Arel
::
Attributes
::
String
.
new
(
Table
.
new
(
:products
),
:name
)
)
compile
(
node
).
must_equal
%("products"."name"
||
"products"."name")
compile
(
node
).
must_equal
%("products"."name"
&&
"products"."name")
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录