Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
16e72732
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,发现更多精彩内容 >>
提交
16e72732
编写于
8月 12, 2010
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
full sql statement generation
上级
d827d6e9
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
102 addition
and
0 deletion
+102
-0
lib/arel.rb
lib/arel.rb
+1
-0
lib/arel/nodes.rb
lib/arel/nodes.rb
+1
-0
lib/arel/nodes/select.rb
lib/arel/nodes/select.rb
+13
-0
lib/arel/tree_manager.rb
lib/arel/tree_manager.rb
+31
-0
lib/arel/visitors/to_sql.rb
lib/arel/visitors/to_sql.rb
+12
-0
spec/arel/tree_manager.rb
spec/arel/tree_manager.rb
+44
-0
未找到文件。
lib/arel.rb
浏览文件 @
16e72732
require
'arel/version'
require
'arel/table'
require
'arel/attributes'
require
'arel/tree_manager'
require
'arel/nodes'
require
'arel/visitors/to_sql'
...
...
lib/arel/nodes.rb
浏览文件 @
16e72732
require
'arel/nodes/equality'
require
'arel/nodes/sql_literal'
require
'arel/nodes/select'
lib/arel/nodes/select.rb
0 → 100644
浏览文件 @
16e72732
module
Arel
module
Nodes
class
Select
attr_reader
:froms
,
:projections
,
:wheres
def
initialize
@froms
=
[]
@projections
=
[]
@wheres
=
[]
end
end
end
end
lib/arel/tree_manager.rb
0 → 100644
浏览文件 @
16e72732
module
Arel
class
TreeManager
def
initialize
engine
@engine
=
engine
@statement_list
=
[]
# default to Select
@statement_list
<<
Nodes
::
Select
.
new
end
def
from
table
@statement_list
.
last
.
froms
<<
table
self
end
def
project
projection
@statement_list
.
last
.
projections
<<
projection
self
end
def
where
expr
@statement_list
.
last
.
wheres
<<
expr
self
end
def
to_sql
viz
=
Visitors
::
ToSql
.
new
@engine
viz
.
accept
@statement_list
.
last
end
end
end
lib/arel/visitors/to_sql.rb
浏览文件 @
16e72732
...
...
@@ -12,6 +12,18 @@ def accept object
end
private
def
visit_Arel_Nodes_Select
o
[
"SELECT
#{
o
.
projections
.
map
{
|
x
|
visit
x
}
.join ', '}"
,
"FROM
#{
o
.
froms
.
map
{
|
x
|
visit
x
}
.join ', ' }"
,
(
"WHERE
#{
o
.
wheres
.
map
{
|
x
|
visit
x
}
.join ' AND ' }"
unless
o
.
wheres
.
blank?
)
].
compact
.
join
' '
end
def
visit_Arel_Table
o
quote_table_name
o
.
name
end
def
visit_Arel_Nodes_Equality
o
"
#{
visit
o
.
left
}
=
#{
visit
o
.
right
}
"
end
...
...
spec/arel/tree_manager.rb
0 → 100644
浏览文件 @
16e72732
require
'spec_helper'
module
Arel
describe
'tree manager'
do
describe
'where'
do
it
"knows where"
do
table
=
Table
.
new
:users
manager
=
Arel
::
TreeManager
.
new
Table
.
engine
manager
.
from
(
table
).
project
(
table
[
'id'
])
manager
.
where
(
table
[
'id'
].
eq
(
1
))
manager
.
to_sql
.
should
==
%{
SELECT "users"."id"
FROM "users"
WHERE "users"."id" = 1
}
.
gsub
(
"
\n
"
,
''
).
gsub
(
/(^\s*|\s*$)/
,
''
).
squeeze
(
' '
)
end
it
"chains"
do
table
=
Table
.
new
:users
manager
=
Arel
::
TreeManager
.
new
Table
.
engine
manager
.
from
(
table
)
manager
.
project
(
table
[
'id'
]).
where
(
table
[
'id'
].
eq
1
).
should
==
manager
end
end
describe
'from'
do
it
"makes sql"
do
table
=
Table
.
new
:users
manager
=
Arel
::
TreeManager
.
new
Table
.
engine
manager
.
from
table
manager
.
project
table
[
'id'
]
manager
.
to_sql
.
should
==
'SELECT "users"."id" FROM "users"'
end
it
"chains"
do
table
=
Table
.
new
:users
manager
=
Arel
::
TreeManager
.
new
Table
.
engine
manager
.
from
(
table
).
project
(
table
[
'id'
]).
should
==
manager
manager
.
to_sql
.
should
==
'SELECT "users"."id" FROM "users"'
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录