foobara-postgresql-crud-driver 0.0.6 → 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/src/connection_pool.rb +2 -2
- data/src/postgresql_crud_driver.rb +43 -43
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bd118df05ffe0549ade798f78feda40542637b6f38a4920827845cd0cae756cf
|
|
4
|
+
data.tar.gz: fc5edfc008687d35fcd73a7f63fb5856e4001bca161bd9973a9d022aee78964a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 67fe100509f84330548d90aefbceb342ae3f0f33d9ca189f09d390a9e31625e59d3fe97a7a2dcf82a9668d466fd5d3b055cae8ed920a073fc69b2d44d875429a
|
|
7
|
+
data.tar.gz: d1902614f890e05ef1c0fa65e36ccb53653ba6219f9229b84c015710e8f6ddee8762f301fa40075f2982925d1cb4b4d6a2ca97902fcf14daeab4e9c535773328
|
data/CHANGELOG.md
CHANGED
data/src/connection_pool.rb
CHANGED
|
@@ -17,9 +17,9 @@ module Foobara
|
|
|
17
17
|
|
|
18
18
|
unless connection
|
|
19
19
|
if in_use_connections.size >= max_connections
|
|
20
|
-
# :
|
|
20
|
+
# simplecov:disable
|
|
21
21
|
raise TooManyConnectionsError, "#{in_use_connections.size} connections in use, cannot allocate more."
|
|
22
|
-
# :
|
|
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
|
-
# :
|
|
10
|
+
# simplecov:disable
|
|
11
11
|
super("Unsupported column type #{pg_type} on #{entity_class.entity_name}")
|
|
12
|
-
# :
|
|
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
|
-
# :
|
|
20
|
+
# simplecov:disable
|
|
21
21
|
super("Unsupported column type #{pg_type} for attribute #{attribute_name} on #{entity_class.entity_name}")
|
|
22
|
-
# :
|
|
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
|
-
# :
|
|
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
|
-
# :
|
|
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
|
-
# :
|
|
49
|
+
# simplecov:disable
|
|
50
50
|
@get_transaction_number = 1
|
|
51
|
-
# :
|
|
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
|
-
# :
|
|
86
|
+
# simplecov:disable
|
|
87
87
|
raise ArgumentError, "Expected a String or Hash with connection creds or nil with DATABASE_URL set"
|
|
88
|
-
# :
|
|
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
|
-
# :
|
|
235
|
+
# simplecov:disable
|
|
236
236
|
raise CannotUpdateError.new(record_id, "does not exist")
|
|
237
|
-
# :
|
|
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
|
-
# :
|
|
263
|
+
# simplecov:disable
|
|
264
264
|
raise CannotDeleteError.new(record_id, "does not exist")
|
|
265
|
-
# :
|
|
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
|
-
# :
|
|
307
|
+
# simplecov:disable
|
|
308
308
|
raise "Unexpected nil value for #{attribute_name}"
|
|
309
|
-
# :
|
|
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
|
-
# :
|
|
320
|
+
# simplecov:disable
|
|
321
321
|
raise UnsupportedPgColumnTypeError.new(info[:type], attribute_name, entity_class)
|
|
322
|
-
# :
|
|
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
|
-
# :
|
|
336
|
+
# simplecov:disable
|
|
337
337
|
raise NoSuchColumnOrTableError, "Either #{table_name} or #{table_name}.#{attribute_name} does not exist"
|
|
338
|
-
# :
|
|
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
|
-
# :
|
|
347
|
+
# simplecov:disable
|
|
348
348
|
raise UnsupportedPgColumnTypeForAttributeError.new(
|
|
349
349
|
e.pg_type,
|
|
350
350
|
attribute_name,
|
|
351
351
|
entity_class
|
|
352
352
|
)
|
|
353
|
-
# :
|
|
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
|
-
# :
|
|
390
|
+
# simplecov:disable
|
|
391
391
|
raise "Unexpected nil value for #{attribute_name}"
|
|
392
|
-
# :
|
|
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.
|
|
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
|
-
# :
|
|
419
|
+
# simplecov:disable
|
|
420
420
|
raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
|
|
421
|
-
# :
|
|
421
|
+
# simplecov:enable
|
|
422
422
|
end
|
|
423
423
|
else
|
|
424
|
-
# :
|
|
424
|
+
# simplecov:disable
|
|
425
425
|
raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
|
|
426
|
-
# :
|
|
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
|
-
# :
|
|
433
|
+
# simplecov:disable
|
|
434
434
|
raise "Expected something that could be cast to an integer but got #{value}"
|
|
435
|
-
# :
|
|
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
|
-
# :
|
|
443
|
+
# simplecov:disable
|
|
444
444
|
raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
|
|
445
|
-
# :
|
|
445
|
+
# simplecov:enable
|
|
446
446
|
end
|
|
447
447
|
elsif foobara_type.extends?(:string) || foobara_type.extends?(:symbol)
|
|
448
448
|
unless pg_type == "text" || pg_type == "character varying" || pg_type == "_varchar"
|
|
449
|
-
# :
|
|
449
|
+
# simplecov:disable
|
|
450
450
|
raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
|
|
451
|
-
# :
|
|
451
|
+
# simplecov:enable
|
|
452
452
|
end
|
|
453
453
|
elsif foobara_type.extends?(:datetime)
|
|
454
454
|
unless pg_type == "timestamp without time zone"
|
|
455
|
-
# :
|
|
455
|
+
# simplecov:disable
|
|
456
456
|
raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
|
|
457
|
-
# :
|
|
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
|
-
# :
|
|
464
|
+
# simplecov:disable
|
|
465
465
|
raise ColumnTypeMismatchError.new(pg_type:, foobara_type:, attribute_name:, entity_class:)
|
|
466
|
-
# :
|
|
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
|
-
# :
|
|
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
|
-
# :
|
|
475
|
+
# simplecov:enable
|
|
476
476
|
end
|
|
477
477
|
else
|
|
478
|
-
# :
|
|
478
|
+
# simplecov:disable
|
|
479
479
|
raise UnsupportedPgColumnTypeError.new(pg_type, entity_class)
|
|
480
|
-
# :
|
|
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.
|
|
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:
|
|
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: []
|