pg_adaptor 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pg_adaptor/version.rb +1 -1
- data/lib/pg_adaptor.rb +14 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a8ffe15c8a5d554cc272a46dcfc60a113086965
|
4
|
+
data.tar.gz: 43493eeae64eb8c2f0abd636ade6f11bfd18ef61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a67fb757367fb7080da42c74db0078a968849734d5aa7127c2967af66bc9d789cad9cb51e65bbb92f02a2945d1570ea76fe2e1caec2524ce050c354b96bf3a
|
7
|
+
data.tar.gz: 5cf92939e51b66fa0da5bb66a16170e6c538f0a6ad0ca1de5d9252b6f9acf14d5aa18ee2f57d03c8a9382f4869b46803d71b4a16037ceed8ea610d52ff824cea
|
data/lib/pg_adaptor/version.rb
CHANGED
data/lib/pg_adaptor.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sequel'
|
2
|
+
require 'json'
|
2
3
|
require "pg_adaptor/version"
|
3
4
|
|
4
5
|
class PGAdaptor
|
@@ -45,16 +46,23 @@ private
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def schema
|
50
|
+
@schema ||=
|
51
|
+
begin
|
52
|
+
schema = {}
|
53
|
+
self.class.db.schema(@name).each do |(key, info)|
|
54
|
+
schema[key] = info
|
55
|
+
end
|
56
|
+
schema
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
48
60
|
def process(model)
|
49
|
-
schema = {}
|
50
|
-
self.class.db.schema(@name).each do |(key, info)|
|
51
|
-
schema[key] = info
|
52
|
-
end
|
53
61
|
fields = {}
|
54
62
|
model.each_pair do |field,value|
|
55
63
|
next if field == :id && value.nil?
|
56
|
-
raise "Field not present in schema: #{field}" unless schema[field]
|
57
|
-
case schema[field][:db_type]
|
64
|
+
raise "Field not present in schema: #{field}" unless schema[field.to_sym]
|
65
|
+
case schema[field.to_sym][:db_type]
|
58
66
|
when "jsonb" then fields[field] = Sequel.pg_jsonb value
|
59
67
|
when /\[\]$/ then fields[field] = Sequel.pg_array value
|
60
68
|
else
|