Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fb8ac4f7
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 搜索 >>
提交
fb8ac4f7
编写于
6月 29, 2014
作者:
S
Sean Griffin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use the type object for sending JSON to the database
上级
9ca0f8da
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
23 deletion
+11
-23
activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
.../lib/active_record/connection_adapters/postgresql/cast.rb
+0
-16
activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
.../active_record/connection_adapters/postgresql/oid/json.rb
+10
-2
activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
...b/active_record/connection_adapters/postgresql/quoting.rb
+0
-4
activerecord/test/cases/adapters/postgresql/json_test.rb
activerecord/test/cases/adapters/postgresql/json_test.rb
+1
-1
未找到文件。
activerecord/lib/active_record/connection_adapters/postgresql/cast.rb
浏览文件 @
fb8ac4f7
...
...
@@ -34,28 +34,12 @@ def string_to_hstore(string) # :nodoc:
end
end
def
json_to_string
(
object
)
# :nodoc:
if
Hash
===
object
||
Array
===
object
ActiveSupport
::
JSON
.
encode
(
object
)
else
object
end
end
def
range_to_string
(
object
)
# :nodoc:
from
=
object
.
begin
.
respond_to?
(
:infinite?
)
&&
object
.
begin
.
infinite?
?
''
:
object
.
begin
to
=
object
.
end
.
respond_to?
(
:infinite?
)
&&
object
.
end
.
infinite?
?
''
:
object
.
end
"[
#{
from
}
,
#{
to
}#{
object
.
exclude_end?
?
')'
:
']'
}
"
end
def
string_to_json
(
string
)
# :nodoc:
if
String
===
string
ActiveSupport
::
JSON
.
decode
(
string
)
else
string
end
end
private
HstorePair
=
begin
...
...
activerecord/lib/active_record/connection_adapters/postgresql/oid/json.rb
浏览文件 @
fb8ac4f7
...
...
@@ -10,11 +10,19 @@ def type
end
def
type_cast_from_database
(
value
)
ConnectionAdapters
::
PostgreSQLColumn
.
string_to_json
(
value
)
if
value
.
is_a?
(
::
String
)
::
ActiveSupport
::
JSON
.
decode
(
value
)
else
super
end
end
def
type_cast_for_database
(
value
)
ConnectionAdapters
::
PostgreSQLColumn
.
json_to_string
(
value
)
if
value
.
is_a?
(
::
Array
)
||
value
.
is_a?
(
::
Hash
)
::
ActiveSupport
::
JSON
.
encode
(
value
)
else
super
end
end
def
accessor
...
...
activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
浏览文件 @
fb8ac4f7
...
...
@@ -30,14 +30,12 @@ def quote(value, column = nil) #:nodoc:
when
Array
case
sql_type
when
'point'
then
super
(
PostgreSQLColumn
.
point_to_string
(
value
))
when
'json'
then
super
(
PostgreSQLColumn
.
json_to_string
(
value
))
else
super
(
value
,
array_column
(
column
))
end
when
Hash
case
sql_type
when
'hstore'
then
super
(
PostgreSQLColumn
.
hstore_to_string
(
value
),
column
)
when
'json'
then
super
(
PostgreSQLColumn
.
json_to_string
(
value
),
column
)
else
super
end
when
Float
...
...
@@ -92,14 +90,12 @@ def type_cast(value, column, array_member = false)
when
Array
case
column
.
sql_type
when
'point'
then
PostgreSQLColumn
.
point_to_string
(
value
)
when
'json'
then
PostgreSQLColumn
.
json_to_string
(
value
)
else
super
(
value
,
array_column
(
column
))
end
when
Hash
case
column
.
sql_type
when
'hstore'
then
PostgreSQLColumn
.
hstore_to_string
(
value
,
array_member
)
when
'json'
then
PostgreSQLColumn
.
json_to_string
(
value
)
else
super
(
value
,
column
)
end
else
...
...
activerecord/test/cases/adapters/postgresql/json_test.rb
浏览文件 @
fb8ac4f7
...
...
@@ -77,7 +77,7 @@ def test_type_cast_json
column
=
JsonDataType
.
columns_hash
[
"payload"
]
data
=
"{
\"
a_key
\"
:
\"
a_value
\"
}"
hash
=
column
.
class
.
string_to_json
data
hash
=
column
.
type_cast_from_database
(
data
)
assert_equal
({
'a_key'
=>
'a_value'
},
hash
)
assert_equal
({
'a_key'
=>
'a_value'
},
column
.
type_cast_from_database
(
data
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录