Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
80ad95ba
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,发现更多精彩内容 >>
提交
80ad95ba
编写于
9月 23, 2010
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
moving visitors around
上级
445a0ea3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
58 addition
and
26 deletion
+58
-26
lib/arel.rb
lib/arel.rb
+1
-6
lib/arel/select_manager.rb
lib/arel/select_manager.rb
+3
-2
lib/arel/table.rb
lib/arel/table.rb
+2
-2
lib/arel/tree_manager.rb
lib/arel/tree_manager.rb
+15
-7
lib/arel/update_manager.rb
lib/arel/update_manager.rb
+1
-5
lib/arel/visitors.rb
lib/arel/visitors.rb
+6
-0
lib/arel/visitors/mysql.rb
lib/arel/visitors/mysql.rb
+16
-0
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+14
-4
未找到文件。
lib/arel.rb
浏览文件 @
80ad95ba
...
...
@@ -12,12 +12,7 @@
require
'arel/expression'
####
require
'arel/visitors/to_sql'
require
'arel/visitors/postgresql'
require
'arel/visitors/update_sql'
require
'arel/visitors/join_sql'
require
'arel/visitors/order_clauses'
require
'arel/visitors/dot'
require
'arel/visitors'
require
'arel/tree_manager'
require
'arel/insert_manager'
...
...
lib/arel/select_manager.rb
浏览文件 @
80ad95ba
...
...
@@ -2,10 +2,11 @@ module Arel
class
SelectManager
<
Arel
::
TreeManager
include
Arel
::
Crud
def
initialize
engine
super
def
initialize
engine
,
table
=
nil
super
(
engine
)
@head
=
Nodes
::
SelectStatement
.
new
@ctx
=
@head
.
cores
.
last
from
table
end
def
taken
...
...
lib/arel/table.rb
浏览文件 @
80ad95ba
...
...
@@ -37,11 +37,11 @@ def alias
end
def
tm
SelectManager
.
new
(
@engine
).
from
(
self
)
SelectManager
.
new
(
@engine
,
self
)
end
def
from
table
SelectManager
.
new
(
@engine
).
from
table
SelectManager
.
new
(
@engine
,
table
)
end
def
joins
manager
...
...
lib/arel/tree_manager.rb
浏览文件 @
80ad95ba
...
...
@@ -4,23 +4,31 @@ class TreeManager
include
Arel
::
Relation
VISITORS
=
{
'postgresql'
=>
Arel
::
Visitors
::
PostgreSQL
'postgresql'
=>
Arel
::
Visitors
::
PostgreSQL
,
'mysql'
=>
Arel
::
Visitors
::
MySQL
,
'mysql2'
=>
Arel
::
Visitors
::
MySQL
,
}
attr_accessor
:visitor
def
initialize
engine
@engine
=
engine
@pool
=
engine
.
connection_pool
@adapter
=
@pool
.
spec
.
config
[
:adapter
]
@visitor_klass
=
VISITORS
[
@adapter
]
||
Visitors
::
ToSql
@engine
=
engine
@visitor
=
nil
end
def
to_dot
Visitors
::
Dot
.
new
.
accept
@head
end
def
visitor
return
@visitor
if
@visitor
pool
=
@engine
.
connection_pool
adapter
=
pool
.
spec
.
config
[
:adapter
]
@visitor
=
(
VISITORS
[
adapter
]
||
Visitors
::
ToSql
).
new
(
@engine
)
end
def
to_sql
viz
=
@visitor_klass
.
new
@engine
viz
.
accept
@head
visitor
.
accept
@head
end
def
initialize_copy
other
...
...
lib/arel/update_manager.rb
浏览文件 @
80ad95ba
...
...
@@ -46,11 +46,7 @@ def set values
end
def
to_sql
viz
=
@visitor_klass
.
new
@engine
unless
@engine
.
connection_pool
.
spec
.
config
[
:adapter
]
=~
/^mysql/
viz
.
extend
(
Visitors
::
UpdateSql
)
end
viz
.
accept
@head
visitor
.
accept
@head
end
end
end
lib/arel/visitors.rb
0 → 100644
浏览文件 @
80ad95ba
require
'arel/visitors/to_sql'
require
'arel/visitors/postgresql'
require
'arel/visitors/mysql'
require
'arel/visitors/join_sql'
require
'arel/visitors/order_clauses'
require
'arel/visitors/dot'
lib/arel/visitors/
update_
sql.rb
→
lib/arel/visitors/
my
sql.rb
浏览文件 @
80ad95ba
module
Arel
module
Visitors
module
Update
Sql
class
MySQL
<
Arel
::
Visitors
::
To
Sql
def
visit_Arel_Nodes_UpdateStatement
o
if
o
.
orders
.
empty?
&&
o
.
limit
.
nil?
wheres
=
o
.
wheres
else
stmt
=
Nodes
::
SelectStatement
.
new
core
=
stmt
.
cores
.
first
core
.
froms
=
o
.
relation
core
.
projections
=
[
o
.
relation
.
primary_key
]
stmt
.
limit
=
o
.
limit
stmt
.
orders
=
o
.
orders
wheres
=
[
Nodes
::
In
.
new
(
o
.
relation
.
primary_key
,
[
stmt
])]
end
[
"UPDATE
#{
visit
o
.
relation
}
"
,
(
"SET
#{
o
.
values
.
map
{
|
value
|
visit
value
}
.join ', '}"
unless
o
.
values
.
empty?
),
(
"WHERE
#{
wheres
.
map
{
|
x
|
visit
x
}
.join ' AND '}"
unless
wheres
.
empty?
)
(
"WHERE
#{
o
.
wheres
.
map
{
|
x
|
visit
x
}
.join ' AND '}"
unless
o
.
wheres
.
empty?
),
(
"ORDER BY
#{
o
.
orders
.
map
{
|
x
|
visit
x
}
.join(', ')}"
unless
o
.
orders
.
empty?
),
(
"LIMIT
#{
o
.
limit
}
"
if
o
.
limit
),
].
compact
.
join
' '
end
end
end
end
lib/arel/visitors/to_sql.rb
浏览文件 @
80ad95ba
...
...
@@ -22,15 +22,25 @@ def visit_Arel_Nodes_DeleteStatement o
end
def
visit_Arel_Nodes_UpdateStatement
o
if
o
.
orders
.
empty?
&&
o
.
limit
.
nil?
wheres
=
o
.
wheres
else
stmt
=
Nodes
::
SelectStatement
.
new
core
=
stmt
.
cores
.
first
core
.
froms
=
o
.
relation
core
.
projections
=
[
o
.
relation
.
primary_key
]
stmt
.
limit
=
o
.
limit
stmt
.
orders
=
o
.
orders
wheres
=
[
Nodes
::
In
.
new
(
o
.
relation
.
primary_key
,
[
stmt
])]
end
[
"UPDATE
#{
visit
o
.
relation
}
"
,
(
"SET
#{
o
.
values
.
map
{
|
value
|
visit
value
}
.join ', '}"
unless
o
.
values
.
empty?
),
(
"WHERE
#{
o
.
wheres
.
map
{
|
x
|
visit
x
}
.join ' AND '}"
unless
o
.
wheres
.
empty?
),
(
"ORDER BY
#{
o
.
orders
.
map
{
|
x
|
visit
x
}
.join(', ')}"
unless
o
.
orders
.
empty?
),
(
"LIMIT
#{
o
.
limit
}
"
if
o
.
limit
),
(
"WHERE
#{
wheres
.
map
{
|
x
|
visit
x
}
.join ' AND '}"
unless
wheres
.
empty?
)
].
compact
.
join
' '
end
def
visit_Arel_Nodes_InsertStatement
o
[
"INSERT INTO
#{
visit
o
.
relation
}
"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录