Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
df2b74b5
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 搜索 >>
未验证
提交
df2b74b5
编写于
12月 28, 2017
作者:
A
Aaron Patterson
提交者:
GitHub
12月 28, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #481 from lautis/lateral
Lateral expressions for PostgreSQL
上级
6cf061ed
d8f463a3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
1 deletion
+40
-1
lib/arel/nodes/select_core.rb
lib/arel/nodes/select_core.rb
+1
-1
lib/arel/nodes/unary.rb
lib/arel/nodes/unary.rb
+1
-0
lib/arel/select_manager.rb
lib/arel/select_manager.rb
+5
-0
lib/arel/visitors/depth_first.rb
lib/arel/visitors/depth_first.rb
+1
-0
lib/arel/visitors/postgresql.rb
lib/arel/visitors/postgresql.rb
+18
-0
test/visitors/test_postgres.rb
test/visitors/test_postgres.rb
+14
-0
未找到文件。
lib/arel/nodes/select_core.rb
浏览文件 @
df2b74b5
...
...
@@ -10,7 +10,7 @@ def initialize
@source
=
JoinSource
.
new
nil
@top
=
nil
# http
://savage.net.au
/SQL/sql-92.bnf.html#set%20quantifier
# http
s://ronsavage.github.io
/SQL/sql-92.bnf.html#set%20quantifier
@set_quantifier
=
nil
@projections
=
[]
@wheres
=
[]
...
...
lib/arel/nodes/unary.rb
浏览文件 @
df2b74b5
...
...
@@ -28,6 +28,7 @@ def eql? other
Group
GroupingElement
GroupingSet
Lateral
Limit
Lock
Not
...
...
lib/arel/select_manager.rb
浏览文件 @
df2b74b5
...
...
@@ -202,6 +202,11 @@ def except other
end
alias
:minus
:except
def
lateral
table_name
=
nil
base
=
table_name
.
nil?
?
ast
:
as
(
table_name
)
Nodes
::
Lateral
.
new
(
base
)
end
def
with
*
subqueries
if
subqueries
.
first
.
is_a?
Symbol
node_class
=
Nodes
.
const_get
(
"With
#{
subqueries
.
shift
.
to_s
.
capitalize
}
"
)
...
...
lib/arel/visitors/depth_first.rb
浏览文件 @
df2b74b5
...
...
@@ -25,6 +25,7 @@ def unary o
alias
:visit_Arel_Nodes_GroupingElement
:unary
alias
:visit_Arel_Nodes_Grouping
:unary
alias
:visit_Arel_Nodes_Having
:unary
alias
:visit_Arel_Nodes_Lateral
:unary
alias
:visit_Arel_Nodes_Limit
:unary
alias
:visit_Arel_Nodes_Not
:unary
alias
:visit_Arel_Nodes_Offset
:unary
...
...
lib/arel/visitors/postgresql.rb
浏览文件 @
df2b74b5
...
...
@@ -5,6 +5,7 @@ class PostgreSQL < Arel::Visitors::ToSql
CUBE
=
'CUBE'
ROLLUP
=
'ROLLUP'
GROUPING_SET
=
'GROUPING SET'
LATERAL
=
'LATERAL'
private
...
...
@@ -69,6 +70,23 @@ def visit_Arel_Nodes_GroupingSet o, collector
grouping_array_or_grouping_element
o
,
collector
end
def
visit_Arel_Nodes_Lateral
o
,
collector
collector
<<
LATERAL
collector
<<
SPACE
grouping_parentheses
o
,
collector
end
# Used by Lateral visitor to enclose select queries in parentheses
def
grouping_parentheses
o
,
collector
if
o
.
expr
.
is_a?
Nodes
::
SelectStatement
collector
<<
"("
visit
o
.
expr
,
collector
collector
<<
")"
else
visit
o
.
expr
,
collector
end
end
# Utilized by GroupingSet, Cube & RollUp visitors to
# handle grouping aggregation semantics
def
grouping_array_or_grouping_element
o
,
collector
...
...
test/visitors/test_postgres.rb
浏览文件 @
df2b74b5
...
...
@@ -51,6 +51,20 @@ def compile node
assert_equal
'SELECT DISTINCT'
,
compile
(
core
)
end
it
'encloses LATERAL queries in parens'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
matches
(
'foo%'
))
compile
(
subquery
.
lateral
).
must_be_like
%{
LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%')
}
end
it
'produces LATERAL queries with alias'
do
subquery
=
@table
.
project
(
:id
).
where
(
@table
[
:name
].
matches
(
'foo%'
))
compile
(
subquery
.
lateral
(
'bar'
)).
must_be_like
%{
LATERAL (SELECT id FROM "users" WHERE "users"."name" ILIKE 'foo%') bar
}
end
describe
"Nodes::Matches"
do
it
"should know how to visit"
do
node
=
@table
[
:name
].
matches
(
'foo%'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录