kweerie 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13712e8746dc90c472a92aba0ee7fc7897069d669a20e64f7c57f898a7ff0012
4
- data.tar.gz: 9593d6a93cb80e8b8949764c91c49a669bb96d9828530eb876b5c2d04ad80fbd
3
+ metadata.gz: f11c69ed8356612d3a1df5dfb98b4751061db706908f7b2efe6ace375f53c73e
4
+ data.tar.gz: b33644c5b64bb941bf88bf6207ced00706e84a1c83c2b60fa9c7dddc680dd0fe
5
5
  SHA512:
6
- metadata.gz: 713a3d4d3e044f560ba9a1278d011c131b699d5805d40f95caf2e43eabf80865ae7ba4a2099d37f1d7b9e517f8c0cc16c35ca25cb18ddb1fea188455c1f019f0
7
- data.tar.gz: e5007711e45dabe31bc20a7780eb503a7f4114e21a47ad711b2327ca99a5923dce68359fa1229cb4cc488eb7c3c02cb8692b89189825931175a7eb4440adf075
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
- ### Performance Considerations
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
 
@@ -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 /^[\[{]/ # JSON/JSONB check
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kweerie
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kweerie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby