foobara-postgresql-crud-driver 0.0.5 → 0.0.7

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: 9da1f2e3a8d5170f4badb5d1ec0eeb8b6f443da56ce17b4b97911767620ae099
4
- data.tar.gz: b12f27eca628e62f38c7f8d2a1af415d1ab3c72006a18d17f983b4fbb03eea91
3
+ metadata.gz: bd118df05ffe0549ade798f78feda40542637b6f38a4920827845cd0cae756cf
4
+ data.tar.gz: fc5edfc008687d35fcd73a7f63fb5856e4001bca161bd9973a9d022aee78964a
5
5
  SHA512:
6
- metadata.gz: d7d0d2d19bc3cd5d3c1625b7b4958b0f160f9c733bdac7adc3f39ec09010ddad3f7fe8ce02aa9a9d4c9c6a7bc8216a731c13d299209947cf7ebb8a327a35fdb6
7
- data.tar.gz: 8f4c6fa9014c60caef166ecdff36a22e7d87543276d36604da42ec8f7e95ff421547256e1d4e58b02f7ac789c5e5070b3f5fe0b3ec500406a1780fec49426fc7
6
+ metadata.gz: 67fe100509f84330548d90aefbceb342ae3f0f33d9ca189f09d390a9e31625e59d3fe97a7a2dcf82a9668d466fd5d3b055cae8ed920a073fc69b2d44d875429a
7
+ data.tar.gz: d1902614f890e05ef1c0fa65e36ccb53653ba6219f9229b84c015710e8f6ddee8762f301fa40075f2982925d1cb4b4d6a2ca97902fcf14daeab4e9c535773328
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.7] - 2026-09-11
2
+
3
+ - Handle JSON.fast_generate being removed
4
+
5
+ ## [0.0.6] - 2025-11-10
6
+
7
+ - Include "_varchar" as a valid stringish pg type
8
+
1
9
  ## [0.0.5] - 2025-11-10
2
10
 
3
11
  - Improve error messages for foobara type/pg column incompatibilities
@@ -17,9 +17,9 @@ module Foobara
17
17
 
18
18
  unless connection
19
19
  if in_use_connections.size >= max_connections
20
- # :nocov:
20
+ # simplecov:disable
21
21
  raise TooManyConnectionsError, "#{in_use_connections.size} connections in use, cannot allocate more."
22
- # :nocov:
22
+ # simplecov:enable
23
23
  end
24
24
 
25
25
  connection = connection_proc.call
@@ -7,9 +7,9 @@ module Foobara
7
7
  attr_accessor :pg_type, :attribute_name, :entity_class
8
8
 
9
9
  def initialize(pg_type, entity_class)
10
- # :nocov:
10
+ # simplecov:disable
11
11
  super("Unsupported column type #{pg_type} on #{entity_class.entity_name}")
12
- # :nocov:
12
+ # simplecov:enable
13
13
  end
14
14
  end
15
15
 
@@ -17,9 +17,9 @@ module Foobara
17
17
  attr_accessor :pg_type, :attribute_name, :entity_class
18
18
 
19
19
  def initialize(pg_type, attribute_name, entity_class)
20
- # :nocov:
20
+ # simplecov:disable
21
21
  super("Unsupported column type #{pg_type} for attribute #{attribute_name} on #{entity_class.entity_name}")
22
- # :nocov:
22
+ # simplecov:enable
23
23
  end
24
24
  end
25
25
 
@@ -28,7 +28,7 @@ module Foobara
28
28
 
29
29
  def initialize(pg_type:, foobara_type:, entity_class:, attribute_name: nil)
30
30
  # TODO: figure out a way to test this code path
31
- # :nocov:
31
+ # simplecov:disable
32
32
  self.pg_type = pg_type
33
33
  self.foobara_type = foobara_type
34
34
  self.entity_class = entity_class
@@ -36,7 +36,7 @@ module Foobara
36
36
 
37
37
  super("Column type mismatch between foobara #{foobara_type.type_symbol} " \
38
38
  "and postgres #{pg_type} for #{entity_class.entity_name}.#{attribute_name}")
39
- # :nocov:
39
+ # simplecov:enable
40
40
  end
41
41
  end
42
42
 
@@ -46,9 +46,9 @@ module Foobara
46
46
  @get_transaction_number += 1
47
47
  if @get_transaction_number > 65_535
48
48
  # TODO: test this code path somehow
49
- # :nocov:
49
+ # simplecov:disable
50
50
  @get_transaction_number = 1
51
- # :nocov:
51
+ # simplecov:enable
52
52
  end
53
53
  @get_transaction_number
54
54
  end
@@ -83,9 +83,9 @@ module Foobara
83
83
  'Must set ENV["DATABASE_URL"] if trying to initialize PostgresqlCrudDriver with no arguments'
84
84
  )
85
85
  else
86
- # :nocov:
86
+ # simplecov:disable
87
87
  raise ArgumentError, "Expected a String or Hash with connection creds or nil with DATABASE_URL set"
88
- # :nocov:
88
+ # simplecov:enable
89
89
  end
90
90
  end
91
91
 
@@ -232,9 +232,9 @@ module Foobara
232
232
  record_id = record_id_for(attributes)
233
233
 
234
234
  unless exists?(record_id)
235
- # :nocov:
235
+ # simplecov:disable
236
236
  raise CannotUpdateError.new(record_id, "does not exist")
237
- # :nocov:
237
+ # simplecov:enable
238
238
  end
239
239
 
240
240
  set_expressions = []
@@ -260,9 +260,9 @@ module Foobara
260
260
 
261
261
  def hard_delete(record_id)
262
262
  unless exists?(record_id)
263
- # :nocov:
263
+ # simplecov:disable
264
264
  raise CannotDeleteError.new(record_id, "does not exist")
265
- # :nocov:
265
+ # simplecov:enable
266
266
  end
267
267
 
268
268
  primary_key, record_id = normalize_attribute(entity_class.primary_key_attribute, record_id)
@@ -304,9 +304,9 @@ module Foobara
304
304
  when "jsonb", "json"
305
305
  if value.nil?
306
306
  unless info[:is_nullable]
307
- # :nocov:
307
+ # simplecov:disable
308
308
  raise "Unexpected nil value for #{attribute_name}"
309
- # :nocov:
309
+ # simplecov:enable
310
310
  end
311
311
 
312
312
  nil
@@ -317,9 +317,9 @@ module Foobara
317
317
  decoder = PG::TextDecoder::Array.new(name: info[:element_type])
318
318
  decoder.decode(value)
319
319
  else
320
- # :nocov:
320
+ # simplecov:disable
321
321
  raise UnsupportedPgColumnTypeError.new(info[:type], attribute_name, entity_class)
322
- # :nocov:
322
+ # simplecov:enable
323
323
  end
324
324
 
325
325
  [attribute_name, value]
@@ -333,9 +333,9 @@ module Foobara
333
333
  info = column_info[attribute_name.to_s]
334
334
 
335
335
  unless info
336
- # :nocov:
336
+ # simplecov:disable
337
337
  raise NoSuchColumnOrTableError, "Either #{table_name} or #{table_name}.#{attribute_name} does not exist"
338
- # :nocov:
338
+ # simplecov:enable
339
339
  end
340
340
 
341
341
  foobara_type = entity_class.model_type.element_types.element_types[attribute_name]
@@ -344,13 +344,13 @@ module Foobara
344
344
  check_type_compatibility!(foobara_type, info, attribute_name:)
345
345
  pg_cast_value(value, foobara_type, info)
346
346
  rescue UnsupportedPgColumnTypeError => e
347
- # :nocov:
347
+ # simplecov:disable
348
348
  raise UnsupportedPgColumnTypeForAttributeError.new(
349
349
  e.pg_type,
350
350
  attribute_name,
351
351
  entity_class
352
352
  )
353
- # :nocov:
353
+ # simplecov:enable
354
354
  end
355
355
 
356
356
  [PostgresqlCrudDriver.escape_identifier(attribute_name), value]
@@ -387,9 +387,9 @@ module Foobara
387
387
  if pg_info[:is_nullable]
388
388
  "NULL"
389
389
  else
390
- # :nocov:
390
+ # simplecov:disable
391
391
  raise "Unexpected nil value for #{attribute_name}"
392
- # :nocov:
392
+ # simplecov:enable
393
393
  end
394
394
  elsif foobara_type.extends?(:number)
395
395
  validate_intable!(value)
@@ -402,7 +402,7 @@ module Foobara
402
402
  pg_cast_value(value, foobara_type.target_class.primary_key_type, pg_info)
403
403
  elsif foobara_type.extends?(:model) || foobara_type.extends?(:attributes) ||
404
404
  foobara_type == BuiltinTypes[:duck]
405
- "'#{PG::Connection.escape(JSON.fast_generate(value))}'"
405
+ "'#{PG::Connection.escape(JSON.generate(value))}'"
406
406
  elsif foobara_type.extends?(:array)
407
407
  element_type = foobara_type.element_type
408
408
 
@@ -416,23 +416,23 @@ module Foobara
416
416
 
417
417
  "'#{escaped}'"
418
418
  else
419
- # :nocov:
419
+ # simplecov:disable
420
420
  raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
421
- # :nocov:
421
+ # simplecov:enable
422
422
  end
423
423
  else
424
- # :nocov:
424
+ # simplecov:disable
425
425
  raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
426
- # :nocov:
426
+ # simplecov:enable
427
427
  end
428
428
  end
429
429
 
430
430
  def validate_intable!(value)
431
431
  if value.is_a?(::String) || value.is_a?(::Symbol)
432
432
  unless value =~ /\A[+-]?\d+\z/
433
- # :nocov:
433
+ # simplecov:disable
434
434
  raise "Expected something that could be cast to an integer but got #{value}"
435
- # :nocov:
435
+ # simplecov:enable
436
436
  end
437
437
  end
438
438
  end
@@ -440,44 +440,44 @@ module Foobara
440
440
  def check_type_compatibility!(foobara_type, pg_info, pg_type: pg_info[:type], attribute_name: nil)
441
441
  if foobara_type.extends?(:integer)
442
442
  unless pg_type == "integer" || pg_type == "bigint" || pg_type == "_int4"
443
- # :nocov:
443
+ # simplecov:disable
444
444
  raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
445
- # :nocov:
445
+ # simplecov:enable
446
446
  end
447
447
  elsif foobara_type.extends?(:string) || foobara_type.extends?(:symbol)
448
- unless pg_type == "text" || pg_type == "character varying"
449
- # :nocov:
448
+ unless pg_type == "text" || pg_type == "character varying" || pg_type == "_varchar"
449
+ # simplecov:disable
450
450
  raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
451
- # :nocov:
451
+ # simplecov:enable
452
452
  end
453
453
  elsif foobara_type.extends?(:datetime)
454
454
  unless pg_type == "timestamp without time zone"
455
- # :nocov:
455
+ # simplecov:disable
456
456
  raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
457
- # :nocov:
457
+ # simplecov:enable
458
458
  end
459
459
  elsif foobara_type.extends?(:detached_entity)
460
460
  check_type_compatibility!(foobara_type.target_class.primary_key_type, pg_info, pg_type:, attribute_name:)
461
461
  elsif foobara_type.extends?(:model) || foobara_type.extends?(:attributes) ||
462
462
  foobara_type == BuiltinTypes[:duck]
463
463
  unless pg_type == "jsonb" || pg_type == "json"
464
- # :nocov:
464
+ # simplecov:disable
465
465
  raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
466
- # :nocov:
466
+ # simplecov:enable
467
467
  end
468
468
  elsif foobara_type.extends?(:array)
469
469
  if pg_type == "ARRAY"
470
470
  element_type = foobara_type.element_type
471
471
  check_type_compatibility!(element_type, pg_info, pg_type: pg_info[:element_type], attribute_name:)
472
- # :nocov:
472
+ # simplecov:disable
473
473
  elsif pg_type != json && pg_type != jsonb
474
474
  raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
475
- # :nocov:
475
+ # simplecov:enable
476
476
  end
477
477
  else
478
- # :nocov:
478
+ # simplecov:disable
479
479
  raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
480
- # :nocov:
480
+ # simplecov:enable
481
481
  end
482
482
  end
483
483
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-postgresql-crud-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  requirements: []
82
- rubygems_version: 3.6.9
82
+ rubygems_version: 4.0.16
83
83
  specification_version: 4
84
84
  summary: Provides a CRUD driver for reading/writing entities with a PostgreSQL database
85
85
  test_files: []