aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorDickson S. Guedes <guedes@guedesoft.net>2012-09-05 14:01:21 -0300
committerDickson S. Guedes <guedes@guedesoft.net>2012-09-05 22:39:43 -0300
commit3b516b5beb79f7e8c1fdd123e7d5a03c00349cdf (patch)
treebc37c5a7d54e4fc8c6aafb83b6548fb69940b514 /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parentddaeaefc2a454be9d893ef3c546793cc47b0db84 (diff)
downloadrails-3b516b5beb79f7e8c1fdd123e7d5a03c00349cdf.tar.gz
rails-3b516b5beb79f7e8c1fdd123e7d5a03c00349cdf.tar.bz2
rails-3b516b5beb79f7e8c1fdd123e7d5a03c00349cdf.zip
ActiveRecord support to PostgreSQL 9.2 JSON type
This implements the support to encode/decode JSON data to/from database and creating columns of type JSON using a native type [1] supported by PostgreSQL from version 9.2. [1] http://www.postgresql.org/docs/9.2/static/datatype-json.html
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index 956e83bfd8..c508afb33e 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -106,6 +106,9 @@ module ActiveRecord
# Hstore
when /\A'(.*)'::hstore\z/
$1
+ # JSON
+ when /\A'(.*)'::json\z/
+ $1
# Object identifier types
when /\A-?\d+\z/
$1
@@ -201,6 +204,9 @@ module ActiveRecord
# UUID type
when 'uuid'
:uuid
+ # JSON type
+ when 'json'
+ :json
# Small and big integer types
when /^(?:small|big)int$/
:integer
@@ -267,6 +273,10 @@ module ActiveRecord
def uuid(name, options = {})
column(name, 'uuid', options)
end
+
+ def json(name, options = {})
+ column(name, 'json', options)
+ end
end
ADAPTER_NAME = 'PostgreSQL'
@@ -290,7 +300,8 @@ module ActiveRecord
inet: { name: "inet" },
cidr: { name: "cidr" },
macaddr: { name: "macaddr" },
- uuid: { name: "uuid" }
+ uuid: { name: "uuid" },
+ json: { name: "json" }
}
include Quoting