Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ca48977f
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 搜索 >>
未验证
提交
ca48977f
编写于
5月 11, 2020
作者:
A
Aaron Patterson
提交者:
GitHub
5月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #39246 from alassek/arel-set-operators
Add Arel support for PostgreSQL contains and overlaps operators
上级
dd2acd5e
3a8eee91
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
71 addition
and
0 deletion
+71
-0
activerecord/lib/arel/nodes/infix_operation.rb
activerecord/lib/arel/nodes/infix_operation.rb
+12
-0
activerecord/lib/arel/predications.rb
activerecord/lib/arel/predications.rb
+8
-0
activerecord/lib/arel/visitors/postgresql.rb
activerecord/lib/arel/visitors/postgresql.rb
+3
-0
activerecord/test/cases/arel/attributes/attribute_test.rb
activerecord/test/cases/arel/attributes/attribute_test.rb
+32
-0
activerecord/test/cases/arel/visitors/postgres_test.rb
activerecord/test/cases/arel/visitors/postgres_test.rb
+16
-0
未找到文件。
activerecord/lib/arel/nodes/infix_operation.rb
浏览文件 @
ca48977f
...
...
@@ -47,6 +47,18 @@ def initialize(left, right)
end
end
class
Contains
<
InfixOperation
def
initialize
(
left
,
right
)
super
(
"@>"
,
left
,
right
)
end
end
class
Overlaps
<
InfixOperation
def
initialize
(
left
,
right
)
super
(
"&&"
,
left
,
right
)
end
end
class
BitwiseAnd
<
InfixOperation
def
initialize
(
left
,
right
)
super
(
:&
,
left
,
right
)
...
...
activerecord/lib/arel/predications.rb
浏览文件 @
ca48977f
...
...
@@ -206,6 +206,14 @@ def concat(other)
Nodes
::
Concat
.
new
self
,
other
end
def
contains
(
other
)
Arel
::
Nodes
::
Contains
.
new
(
self
,
other
)
end
def
overlaps
(
other
)
Arel
::
Nodes
::
Overlaps
.
new
(
self
,
other
)
end
private
def
grouping_any
(
method_id
,
others
,
*
extras
)
nodes
=
others
.
map
{
|
expr
|
send
(
method_id
,
expr
,
*
extras
)
}
...
...
activerecord/lib/arel/visitors/postgresql.rb
浏览文件 @
ca48977f
...
...
@@ -92,6 +92,9 @@ def visit_Arel_Nodes_NullsLast(o, collector)
collector
<<
" NULLS LAST"
end
alias
:visit_Arel_Nodes_Contains
:visit_Arel_Nodes_InfixOperation
alias
:visit_Arel_Nodes_Overlaps
:visit_Arel_Nodes_InfixOperation
# Used by Lateral visitor to enclose select queries in parentheses
def
grouping_parentheses
(
o
,
collector
)
if
o
.
expr
.
is_a?
Nodes
::
SelectStatement
...
...
activerecord/test/cases/arel/attributes/attribute_test.rb
浏览文件 @
ca48977f
...
...
@@ -1043,6 +1043,38 @@ class AttributeTest < Arel::Spec
end
end
describe
"#contains"
do
it
"should create a Contains node"
do
relation
=
Table
.
new
(
:products
)
query
=
Nodes
.
build_quoted
(
"{foo,bar}"
)
_
(
relation
[
:tags
].
contains
(
query
)).
must_be_kind_of
Nodes
::
Contains
end
it
"should generate @> in sql"
do
relation
=
Table
.
new
(
:products
)
mgr
=
relation
.
project
relation
[
:id
]
query
=
Nodes
.
build_quoted
(
"{foo,bar}"
)
mgr
.
where
relation
[
:tags
].
contains
(
query
)
_
(
mgr
.
to_sql
).
must_be_like
%{ SELECT "products"."id" FROM "products" WHERE "products"."tags" @> '{foo,bar}' }
end
end
describe
"#overlaps"
do
it
"should create an Overlaps node"
do
relation
=
Table
.
new
(
:products
)
query
=
Nodes
.
build_quoted
(
"{foo,bar}"
)
_
(
relation
[
:tags
].
overlaps
(
query
)).
must_be_kind_of
Nodes
::
Overlaps
end
it
"should generate && in sql"
do
relation
=
Table
.
new
(
:products
)
mgr
=
relation
.
project
relation
[
:id
]
query
=
Nodes
.
build_quoted
(
"{foo,bar}"
)
mgr
.
where
relation
[
:tags
].
overlaps
(
query
)
_
(
mgr
.
to_sql
).
must_be_like
%{ SELECT "products"."id" FROM "products" WHERE "products"."tags" && '{foo,bar}' }
end
end
describe
"equality"
do
describe
"#to_sql"
do
it
"should produce sql"
do
...
...
activerecord/test/cases/arel/visitors/postgres_test.rb
浏览文件 @
ca48977f
...
...
@@ -331,6 +331,22 @@ def compile(node)
}
end
end
describe
"Nodes::InfixOperation"
do
it
"should handle Contains"
do
inner
=
Nodes
.
build_quoted
(
'{"foo":"bar"}'
)
outer
=
Table
.
new
(
:products
)[
:metadata
]
sql
=
compile
Nodes
::
Contains
.
new
(
outer
,
inner
)
_
(
sql
).
must_be_like
%{ "products"."metadata" @> '{"foo":"bar"}' }
end
it
"should handle Overlaps"
do
column
=
Table
.
new
(
:products
)[
:tags
]
search
=
Nodes
.
build_quoted
(
"{foo,bar,baz}"
)
sql
=
compile
Nodes
::
Overlaps
.
new
(
column
,
search
)
_
(
sql
).
must_be_like
%{ "products"."tags" && '{foo,bar,baz}' }
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录