kweerie 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -1
- data/lib/kweerie/base_objects.rb +37 -2
- data/lib/kweerie/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f11c69ed8356612d3a1df5dfb98b4751061db706908f7b2efe6ace375f53c73e
|
4
|
+
data.tar.gz: b33644c5b64bb941bf88bf6207ced00706e84a1c83c2b60fa9c7dddc680dd0fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f05d4db4050c840ac87c60b60e44dd27413fc3fee685cd81fd5320d6bb9d37f01ee5a1f29691989f1ec4f3de2a566d1a8fd0057696b54982bdd012170a0ea2b
|
7
|
+
data.tar.gz: 11560ae4acff559585472f020d29d0367ca431cd3f9398cfb75aa1e27b6a08057e8f6b1d5270b7f6ef043551c9f15d3b95434d586400390c512c75b410dc7661
|
data/README.md
CHANGED
@@ -147,7 +147,27 @@ user.changes # => Hash of changes with [old, new] values
|
|
147
147
|
user.original_attributes # => Original attributes from DB
|
148
148
|
```
|
149
149
|
|
150
|
-
|
150
|
+
## PostgreSQL Array Support
|
151
|
+
|
152
|
+
BaseObjects handles PostgreSQL arrays by converting them to Ruby arrays with proper type casting:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
# In your PostgreSQL schema
|
156
|
+
create_table :users do |t|
|
157
|
+
t.integer :preferred_ordering, array: true, default: []
|
158
|
+
t.string :tags, array: true
|
159
|
+
t.float :scores, array: true
|
160
|
+
end
|
161
|
+
|
162
|
+
# In your query
|
163
|
+
user = UserSearch.with(name: 'Claude').first
|
164
|
+
|
165
|
+
user.preferred_ordering # => [1, 3, 2]
|
166
|
+
user.tags # => ["ruby", "rails"]
|
167
|
+
user.scores # => [98.5, 87.2, 92.0]
|
168
|
+
```
|
169
|
+
|
170
|
+
## Performance Considerations
|
151
171
|
|
152
172
|
BaseObjects creates a unique class for each query result set, with the following optimizations:
|
153
173
|
|
data/lib/kweerie/base_objects.rb
CHANGED
@@ -39,10 +39,22 @@ module Kweerie
|
|
39
39
|
value.to_f
|
40
40
|
when /^(true|false)$/i # Boolean check
|
41
41
|
value.downcase == "true"
|
42
|
-
when /^
|
42
|
+
when /^{.*}$/ # Could be PG array or JSON
|
43
|
+
if value.start_with?("{") && value.end_with?("}") && !value.include?('"=>') && !value.include?(": ")
|
44
|
+
# PostgreSQL array (simple heuristic: no "=>" or ":" suggests it's not JSON)
|
45
|
+
parse_pg_array(value)
|
46
|
+
else
|
47
|
+
# Attempt JSON parse
|
48
|
+
begin
|
49
|
+
parsed = JSON.parse(value)
|
50
|
+
deep_stringify_keys(parsed)
|
51
|
+
rescue JSON::ParserError
|
52
|
+
value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
when /^[\[{]/ # Pure JSON (arrays starting with [ or other JSON objects)
|
43
56
|
begin
|
44
57
|
parsed = JSON.parse(value)
|
45
|
-
# Use string keys for consistency in output
|
46
58
|
deep_stringify_keys(parsed)
|
47
59
|
rescue JSON::ParserError
|
48
60
|
value
|
@@ -63,6 +75,29 @@ module Kweerie
|
|
63
75
|
instance_variable_set("@#{name}", casted_value)
|
64
76
|
end
|
65
77
|
end
|
78
|
+
define_method :parse_pg_array do |value|
|
79
|
+
# Remove the curly braces
|
80
|
+
clean_value = value.gsub(/^{|}$/, "")
|
81
|
+
return [] if clean_value.empty?
|
82
|
+
|
83
|
+
# Split on comma, but not within quoted strings
|
84
|
+
elements = clean_value.split(/,(?=(?:[^"]*"[^"]*")*[^"]*$)/)
|
85
|
+
|
86
|
+
elements.map do |element|
|
87
|
+
case element
|
88
|
+
when /^\d+$/ # Integer
|
89
|
+
element.to_i
|
90
|
+
when /^\d*\.\d+$/ # Float
|
91
|
+
element.to_f
|
92
|
+
when /^(true|false)$/i # Boolean
|
93
|
+
element.downcase == "true"
|
94
|
+
when /^"(.*)"$/ # Quoted string
|
95
|
+
::Regexp.last_match(1)
|
96
|
+
else
|
97
|
+
element
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
66
101
|
|
67
102
|
define_method :deep_symbolize_keys do |obj|
|
68
103
|
case obj
|
data/lib/kweerie/version.rb
CHANGED